Official Python SDK for the DocPeel document AI API.
Project description
docpeel — Python SDK
Official Python SDK for the DocPeel document AI API. Extract structured JSON from invoices, receipts, contracts, IDs, bank statements, and any other document — in a few lines of Python.
Install
pip install docpeel
Requires Python 3.8+.
Quickstart
import base64
from docpeel import DocPeel
client = DocPeel(api_key="dpk_live_...") # or set DOCPEEL_API_KEY env var
# DocPeel takes documents as base64 in a JSON body.
with open("invoice.pdf", "rb") as f:
file_b64 = base64.b64encode(f.read()).decode("ascii")
extraction = client.extractions.create(
file_b64=file_b64,
file_name="invoice.pdf",
template_id="tpl_invoice", # optional
)
for f in extraction.fields:
print(f.field, "=", f.value, f"({f.confidence}% confidence)")
# → Invoice Number = INV-2024-081 (98% confidence)
# → Total = $1,240.00 (97% confidence)
Prefer to let the SDK encode for you? Pass a path, bytes, or a binary
file-like as file and the SDK base64-encodes it before sending:
ext = client.extractions.create("invoice.pdf") # path — SDK reads + encodes
Authentication
Pass your API key directly or set the DOCPEEL_API_KEY environment variable:
import os
os.environ["DOCPEEL_API_KEY"] = "dpk_live_..."
client = DocPeel()
Generate keys in your DocPeel dashboard.
API reference
client.ping()
Verify the API key. Returns a dict with key + workspace metadata.
me = client.ping()
# {'api_key': {'id': ..., 'name': ..., 'scopes': [...]}, 'request_id': ...}
client.extractions.create(file=None, *, file_b64=None, file_name=None, content_type=None, template_id=None)
Submit a document. Pass either:
file_b64— a pre-encoded base64 string (recommended; the SDK passes it through untouched). Adata:URI prefix is allowed and stripped. Requiresfile_name.file— the SDK reads it, base64-encodes it, then sends it. Accepts:- A path (
stroros.PathLike) - Raw bytes — requires
file_name - A binary file-like object — e.g.
open(path, "rb")/io.BytesIO
- A path (
Either way the wire format is application/json with the body{' '}
{ "file": <base64>, "file_name": ..., "content_type": ..., "template_id": ... } —
no multipart upload is ever sent.
Returns an Extraction dataclass.
import base64
with open("receipt.jpg", "rb") as f:
b64 = base64.b64encode(f.read()).decode("ascii")
ext = client.extractions.create(file_b64=b64, file_name="receipt.jpg")
client.extractions.retrieve(extraction_id)
ext = client.extractions.retrieve("ext_01HZX...")
Errors
All HTTP errors raise DocPeelError with .status, .code, .message, and
.request_id:
from docpeel import DocPeel, DocPeelError
try:
client.extractions.create("invoice.pdf")
except DocPeelError as err:
if err.code == "rate_limited":
time.sleep(1)
else:
raise
Configuration
client = DocPeel(
api_key="dpk_live_...",
base_url="https://api.docpeel.com", # override for staging
timeout=60, # seconds, default 120
)
To customise retries or adapters, pass your own requests.Session:
import requests
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry
session = requests.Session()
session.mount("https://", HTTPAdapter(max_retries=Retry(total=3, backoff_factor=0.5)))
client = DocPeel(api_key="dpk_live_...", session=session)
Documentation
- Full docs: https://docpeel.com/docs
- Python SDK guide: https://docpeel.com/docs/sdk/python
- REST API reference: https://docpeel.com/docs/api/endpoints
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file docpeel-0.2.0.tar.gz.
File metadata
- Download URL: docpeel-0.2.0.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b37d680f6b09aa97fd7a687fe3fdc9e0945bc1d25bce7a23b863e2062a9aafb
|
|
| MD5 |
dc8663917c17fdc9e2f15d73f8fe361b
|
|
| BLAKE2b-256 |
9af46927a191665f1f0d59942ff4125ced6cb6d4a7d399b762f17afe106757c1
|
File details
Details for the file docpeel-0.2.0-py3-none-any.whl.
File metadata
- Download URL: docpeel-0.2.0-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
18625dbcaabd8c3d364967f0e24865ef4c51be9b3c9764fd5aac01251ebd87e6
|
|
| MD5 |
7f30e7dc3459a246416280387ae64f46
|
|
| BLAKE2b-256 |
4d216b01448a0e0cb0f7bc64f1dc20362764e10543076d51b62b6fed0a2a9310
|