Skip to main content

Official Python SDK for the DocPeel document AI API.

Project description

docpeel — Python SDK

PyPI version Python versions

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). A data: URI prefix is allowed and stripped. Requires file_name.
  • file — the SDK reads it, base64-encodes it, then sends it. Accepts:
    • A path (str or os.PathLike)
    • Raw bytes — requires file_name
    • A binary file-like object — e.g. open(path, "rb") / io.BytesIO

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...")

client.extractions.list(*, limit=None, cursor=None)

Cursor-paginated list of recent extractions for the workspace.

page = client.extractions.list(limit=50)
for ext in page.extractions:
    print(ext.id, ext.status)
if page.next_cursor:
    page = client.extractions.list(cursor=page.next_cursor)

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

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

docpeel-0.1.0.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

docpeel-0.1.0-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file docpeel-0.1.0.tar.gz.

File metadata

  • Download URL: docpeel-0.1.0.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for docpeel-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d0afd09a2910e0314d1f7d5564b456bf8d37a10f13cf9d51ad8b458599070756
MD5 a1c12834a761cd5431bc0e019da224d8
BLAKE2b-256 1754680957859c1b67ab1397bce5660ce0a4a6ccc8ed4ae5c2811640a9731769

See more details on using hashes here.

File details

Details for the file docpeel-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: docpeel-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for docpeel-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d24ebe1eed6afcbbca283eb36bc97dc320c361a46c669d1230e1ac70774b37ad
MD5 8b22a57a1ef1f957b57e607da15cc4cf
BLAKE2b-256 e03a65ac95a4c42af774ebc5b34d473b90b5114ec7c0de98aa49107f9ad80337

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page