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
Metadata
Release files for docpeel 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| docpeel-0.2.0.tar.gz | 7.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| docpeel-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.5 kB
Release files / docpeel-0.2.0.tar.gz
| Download URL | docpeel-0.2.0.tar.gz |
|---|---|
| Size | 7.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4b37d680f6b09aa97fd7a687fe3fdc9e0945bc1d25bce7a23b863e2062a9aafb
|
|
BLAKE2b-256 checksum How to use checksums |
9af46927a191665f1f0d59942ff4125ced6cb6d4a7d399b762f17afe106757c1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.13
|
Release files / docpeel-0.2.0-py3-none-any.whl
| Download URL | docpeel-0.2.0-py3-none-any.whl |
|---|---|
| Size | 9.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
18625dbcaabd8c3d364967f0e24865ef4c51be9b3c9764fd5aac01251ebd87e6
|
|
BLAKE2b-256 checksum How to use checksums |
4d216b01448a0e0cb0f7bc64f1dc20362764e10543076d51b62b6fed0a2a9310
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.13
|