|
| 1 | +# Getting started |
| 2 | + |
| 3 | +This guide walks through a Cloud-first setup for `pdfrest` (the Python package |
| 4 | +published on PyPI) so you can make your first API call quickly. |
| 5 | + |
| 6 | +## Before you begin |
| 7 | + |
| 8 | +- A Python runtime (3.10+ recommended for this SDK). |
| 9 | +- A local PDF file to test with. |
| 10 | +- A pdfRest Cloud account and API key. |
| 11 | + |
| 12 | +For the official Cloud onboarding flow, see: |
| 13 | + |
| 14 | +- [pdfRest API Toolkit Cloud: Getting Started](https://docs.pdfrest.com/pdfrest-api-toolkit-cloud/getting-started/) |
| 15 | +- [Python API reference](api-reference.md) |
| 16 | +- [API Lab](https://pdfrest.com/apilab/) |
| 17 | + |
| 18 | +## 1. Create a project and install `pdfrest` |
| 19 | + |
| 20 | +### Recommended: uv |
| 21 | + |
| 22 | +=== "uv (Recommended)" |
| 23 | + ```bash |
| 24 | + mkdir pdfrest-quickstart |
| 25 | + cd pdfrest-quickstart |
| 26 | + uv init |
| 27 | + uv add pdfrest |
| 28 | + ``` |
| 29 | + |
| 30 | +=== "pip + venv" |
| 31 | + ```bash |
| 32 | + mkdir pdfrest-quickstart |
| 33 | + cd pdfrest-quickstart |
| 34 | + python -m venv .venv |
| 35 | + source .venv/bin/activate |
| 36 | + pip install pdfrest |
| 37 | + ``` |
| 38 | + |
| 39 | +=== "Poetry" |
| 40 | + ```bash |
| 41 | + mkdir pdfrest-quickstart |
| 42 | + cd pdfrest-quickstart |
| 43 | + poetry init --no-interaction |
| 44 | + poetry add pdfrest |
| 45 | + ``` |
| 46 | + |
| 47 | +## 2. Get your pdfRest Cloud API key |
| 48 | + |
| 49 | +1. Create or sign in to your account at [pdfRest.com](https://pdfrest.com/). |
| 50 | +2. Follow the Cloud onboarding steps in |
| 51 | + [Getting Started](https://docs.pdfrest.com/pdfrest-api-toolkit-cloud/getting-started/). |
| 52 | +3. Copy your API key and export it as `PDFREST_API_KEY` in your shell. |
| 53 | + |
| 54 | +=== "macOS / Linux (bash/zsh)" |
| 55 | + ```bash |
| 56 | + export PDFREST_API_KEY="your-api-key-here" |
| 57 | + ``` |
| 58 | + |
| 59 | +=== "Windows PowerShell" |
| 60 | + ```powershell |
| 61 | + $env:PDFREST_API_KEY="your-api-key-here" |
| 62 | + ``` |
| 63 | + |
| 64 | +!!! tip |
| 65 | + The [API Lab](https://pdfrest.com/apilab/) is useful for testing endpoints |
| 66 | + interactively and generating starter code samples before integrating them |
| 67 | + into your project. |
| 68 | + |
| 69 | +## 3. Add a short example program |
| 70 | + |
| 71 | +Create `quickstart.py`: |
| 72 | + |
| 73 | +```python |
| 74 | +from pathlib import Path |
| 75 | + |
| 76 | +from pdfrest import PdfRestClient |
| 77 | + |
| 78 | +input_pdf = Path("input.pdf") |
| 79 | + |
| 80 | +if not input_pdf.exists(): |
| 81 | + raise FileNotFoundError( |
| 82 | + "Place a test PDF at ./input.pdf before running this script." |
| 83 | + ) |
| 84 | + |
| 85 | +with PdfRestClient() as client: |
| 86 | + uploaded = client.files.create_from_paths([input_pdf])[0] |
| 87 | + document = client.extract_pdf_text(uploaded, full_text="document") |
| 88 | + |
| 89 | +full_text = "" |
| 90 | +if document.full_text is not None and document.full_text.document_text is not None: |
| 91 | + full_text = document.full_text.document_text |
| 92 | + |
| 93 | +print(f"Input file id: {uploaded.id}") |
| 94 | +print("Extracted text preview:") |
| 95 | +print(full_text[:500] if full_text else "(no text returned)") |
| 96 | +``` |
| 97 | + |
| 98 | +What this script does: |
| 99 | + |
| 100 | +- Uploads `input.pdf` to pdfRest Cloud. |
| 101 | +- Calls `extract_pdf_text`. |
| 102 | +- Prints a short text preview from the response. |
| 103 | + |
| 104 | +## 4. Run the example |
| 105 | + |
| 106 | +=== "uv" |
| 107 | + ```bash |
| 108 | + uv run python quickstart.py |
| 109 | + ``` |
| 110 | + |
| 111 | +=== "pip + venv" |
| 112 | + ```bash |
| 113 | + python quickstart.py |
| 114 | + ``` |
| 115 | + |
| 116 | +=== "Poetry" |
| 117 | + ```bash |
| 118 | + poetry run python quickstart.py |
| 119 | + ``` |
| 120 | + |
| 121 | +## 5. Next steps |
| 122 | + |
| 123 | +- Browse endpoint options in the |
| 124 | + [Python API reference](api-reference.md). |
| 125 | +- Explore additional endpoint behavior and payload examples in |
| 126 | + [API Lab](https://pdfrest.com/apilab/). |
0 commit comments