|
1 | | -# pdfrest |
| 1 | +# pdfRest Python SDK |
2 | 2 |
|
3 | | -Python client library for the PDFRest service. The project is managed with |
4 | | -[uv](https://docs.astral.sh/uv/) and targets Python 3.9 and newer. |
| 3 | +[](https://github.com/pdfrest/pdfrest-python/actions/workflows/test-and-publish.yml) |
| 4 | +[](https://pypi.org/project/pdfrest/) |
| 5 | +[](https://pypi.org/project/pdfrest/) |
| 6 | +[](https://python.pdfrest.com/llms.txt) |
5 | 7 |
|
6 | | -## Running examples |
| 8 | +Build production-grade PDF automation with the official Python SDK for |
| 9 | +[pdfRest](https://pdfrest.com/): a powerful PDF API platform for conversion, |
| 10 | +OCR, extraction, redaction, security, forms, and AI-ready document workflows. |
7 | 11 |
|
8 | | -```bash |
9 | | -uvx nox -s examples |
10 | | -uv run nox -s run-example -- examples/delete/delete_example.py |
11 | | -``` |
| 12 | +- Homepage: [pdfrest.com](https://pdfrest.com/) |
| 13 | +- API docs: [pdfrest.com/apidocs](https://pdfrest.com/apidocs/) |
| 14 | +- Python SDK docs: [python.pdfrest.com](https://python.pdfrest.com/) |
| 15 | +- API Lab: [pdfrest.com/apilab](https://pdfrest.com/apilab/) |
12 | 16 |
|
13 | | -## Getting started |
| 17 | +## Why pdfRest |
14 | 18 |
|
15 | | -```bash |
16 | | -uv sync |
17 | | -uv run python -c "import pdfrest; print(pdfrest.__version__)" |
18 | | -``` |
| 19 | +- Enterprise PDF quality powered by Adobe PDF Library technology. |
| 20 | +- Fast onboarding with API Lab, code samples, and straightforward REST patterns. |
| 21 | +- Chainable API workflows that let you pass outputs between calls. |
| 22 | +- Deployment flexibility: Cloud, self-hosted on AWS, or self-hosted container. |
| 23 | +- Security and compliance resources published in the trust center and product |
| 24 | + documentation. |
| 25 | + |
| 26 | +## Why this SDK |
| 27 | + |
| 28 | +- Official typed Python interface to pdfRest (`PdfRestClient` and |
| 29 | + `AsyncPdfRestClient`). |
| 30 | +- Pydantic-backed request/response models for safer integrations. |
| 31 | +- High-level helpers for the endpoints teams use most in production. |
| 32 | +- Consistent error handling, request customization, and file management helpers. |
| 33 | + |
| 34 | +## What you can build |
19 | 35 |
|
20 | | -## Development |
| 36 | +Use this PDF API for workflows like: |
21 | 37 |
|
22 | | -To install the tooling used by CI locally, include the `--group dev` flag: |
| 38 | +- Convert and transform: PDF to Word/Excel/PowerPoint/images/Markdown, and |
| 39 | + convert files to PDF/PDF-A/PDF-X. |
| 40 | +- Extract and analyze: OCR, text extraction, image extraction, PDF metadata. |
| 41 | +- Secure and govern: redaction, encryption, permissions, signing, watermarking. |
| 42 | +- Compose and optimize: merge/split, compress, flatten, rasterize, color |
| 43 | + conversion. |
| 44 | +- Form operations: import/export form data, flatten forms, XFA to Acroforms. |
| 45 | + |
| 46 | +## Built for AI and LLM pipelines |
| 47 | + |
| 48 | +pdfRest is especially useful for document AI systems: |
| 49 | + |
| 50 | +- Convert PDFs to structured Markdown for downstream retrieval and training data |
| 51 | + prep. |
| 52 | +- Extract clean text and metadata for indexing and chunking pipelines. |
| 53 | +- Summarize and translate document content with API-native operations. |
| 54 | +- Keep multi-step pipelines efficient by chaining outputs between operations. |
| 55 | + |
| 56 | +## Installation |
| 57 | + |
| 58 | +`pdfrest` supports Python `3.10+`. |
| 59 | + |
| 60 | +Recommended (`uv`): |
23 | 61 |
|
24 | 62 | ```bash |
25 | | -uv sync --group dev |
| 63 | +uv add pdfrest |
26 | 64 | ``` |
27 | 65 |
|
28 | | -It is recommended to enable the pre-commit hooks after installation: |
| 66 | +Fallback (`pip`): |
29 | 67 |
|
30 | 68 | ```bash |
31 | | -uv run pre-commit install |
| 69 | +pip install pdfrest |
32 | 70 | ``` |
33 | 71 |
|
34 | | -Run the test suite with: |
| 72 | +## Quick start |
| 73 | + |
| 74 | +Set your API key in `PDFREST_API_KEY`: |
35 | 75 |
|
36 | 76 | ```bash |
37 | | -uv run pytest |
| 77 | +export PDFREST_API_KEY="your-api-key" |
38 | 78 | ``` |
39 | 79 |
|
40 | | -Check per-function coverage for the client classes: |
| 80 | +Run your script: |
41 | 81 |
|
42 | 82 | ```bash |
43 | | -uvx nox -s class-coverage |
| 83 | +uv run python your_script.py |
44 | 84 | ``` |
45 | 85 |
|
46 | | -To reuse an existing `coverage/py<version>/coverage.json` without rerunning |
47 | | -tests, add `-- --no-tests` (and optional `--coverage-json path`). |
| 86 | +Example (upload + extract text): |
48 | 87 |
|
49 | | -## Documentation |
| 88 | +```python |
| 89 | +from pathlib import Path |
50 | 90 |
|
51 | | -Run the docs site locally: |
| 91 | +from pdfrest import PdfRestClient |
52 | 92 |
|
53 | | -```bash |
54 | | -uv run mkdocs serve |
| 93 | +with PdfRestClient() as client: |
| 94 | + uploaded = client.files.create_from_paths([Path("input.pdf")])[0] |
| 95 | + result = client.extract_pdf_text(uploaded, full_text="document") |
| 96 | + |
| 97 | +preview = "" |
| 98 | +if result.full_text is not None and result.full_text.document_text is not None: |
| 99 | + preview = result.full_text.document_text[:500] |
| 100 | +print(preview) |
55 | 101 | ``` |
56 | 102 |
|
57 | | -Build the static documentation site: |
| 103 | +Async example: |
58 | 104 |
|
59 | | -```bash |
60 | | -uv run mkdocs build --strict |
| 105 | +```python |
| 106 | +import asyncio |
| 107 | +from pathlib import Path |
| 108 | + |
| 109 | +from pdfrest import AsyncPdfRestClient |
| 110 | + |
| 111 | + |
| 112 | +async def main() -> None: |
| 113 | + async with AsyncPdfRestClient() as client: |
| 114 | + uploaded = (await client.files.create_from_paths([Path("input.pdf")]))[0] |
| 115 | + result = await client.extract_pdf_text(uploaded, full_text="document") |
| 116 | + preview = "" |
| 117 | + if result.full_text is not None and result.full_text.document_text is not None: |
| 118 | + preview = result.full_text.document_text[:500] |
| 119 | + print(preview) |
| 120 | + |
| 121 | + |
| 122 | +asyncio.run(main()) |
61 | 123 | ``` |
| 124 | + |
| 125 | +## Deployment options |
| 126 | + |
| 127 | +- Cloud (default): use `PdfRestClient()` with `PDFREST_API_KEY`. |
| 128 | +- Self-hosted: set `base_url="https://your-api-host"` and keep the same Python |
| 129 | + SDK surface. |
| 130 | + |
| 131 | +## Learn more |
| 132 | + |
| 133 | +- API toolkit overview: [pdfrest.com](https://pdfrest.com/) |
| 134 | +- Resources and insights: |
| 135 | + [pdfrest.com/resources](https://pdfrest.com/resources/) |
| 136 | +- Example scripts: `examples/README.md` |
| 137 | +- Python SDK docs: [python.pdfrest.com](https://python.pdfrest.com/) |
| 138 | + |
| 139 | +## For contributors |
| 140 | + |
| 141 | +Contributor workflows live in `CONTRIBUTING.md`. |
0 commit comments