Wellfriend Python SDK
The official Python client for the Wellfriend document API: PDF and image tools, pipelines, uploads, downloads and webhooks. Typed throughout, with a sync and an async client.
Install
pip install wellfriend-document-sdk
Python 3.10 or later. The only dependency is httpx. To verify Ed25519-signed
webhooks, add the optional extra: pip install "wellfriend-document-sdk[ed25519]".
Quickstart
from wellfriend import Wellfriend
wf = Wellfriend() # reads WELLFRIEND_API_KEY
wf.tools.compress_pdf("in.pdf").save("out.pdf")
The async client has the same surface:
from wellfriend import AsyncWellfriend
async with AsyncWellfriend() as wf:
result = await wf.tools.compress_pdf("in.pdf")
await result.save("out.pdf")
Get an API key
Create a key at https://wellfriend.dev/dashboard/developer-api/keys and export it as WELLFRIEND_API_KEY, or
pass Wellfriend(api_key=...). WELLFRIEND_BASE_URL overrides the API root (https://wellfriend.dev/api/v2).
A missing key fails at the first request with an AuthenticationError that says where to create one.
Tools
Every tool of the catalog is a method of wf.tools, with typed, snake_case parameters:
result = wf.tools.compress_pdf("report.pdf", profile="aggressive_max", fast_web_view=True)
result.save("small.pdf") # streams to disk; a directory keeps the output's own name
result.bytes() # or read it into memory
for chunk in result.stream(): ... # or stream it
result.outputs[0].filename, result.outputs[0].size_bytes, result.operation.id, result.usage
- The input is a path,
bytes, a binary stream,File(stream, "scan.png"), a stored document id ("doc_..."), aDocument, or a previous result (which chains without downloading):wf.tools.ocr_pdf(wf.tools.compress_pdf("in.pdf")). - Tools that read several files take a list:
wf.tools.merge_pdf(["a.pdf", "b.pdf"]). - Asset files are parameters too:
wf.tools.add_watermark("in.pdf", type="image", watermark_image="logo.png"). - The media type comes from the file name's extension (or the content, for nameless bytes).
wf.tools.run("compress-pdf", "in.pdf", {"profile": "medium"})runs any tool by id.
Each call uploads the input, starts the operation, waits for it (polling with backoff, up to the client's
wait_timeout, 15 minutes by default) and raises OperationFailedError if it fails. To start and wait later:
operation = wf.tools.compress_pdf("in.pdf", wait=False) # Python idiom: a keyword, not an options field
...
result = operation.wait() # or wf.document_operations.wait(operation.id)
wf.quote("ocr-pdf", pages=40) returns what a run costs before you send it.
Pipelines
Several tools on one file, chained on the server (at most 10 steps):
pipeline = wf.pipeline(["compress-pdf", ("rotate-pdf", {"angle": 90})])
pipeline.run("scan.pdf").save("out.pdf")
The input is uploaded once. Every step starts at once and reads the previous step's output (source), so
nothing is downloaded or uploaded in between; the SDK waits for the last step only. If a step fails, the
following steps fail too (their request units are refunded) and run() raises OperationFailedError
naming the failed step. Steps are tool ids, (tool, params) pairs, {"tool": ..., "params": ...} or
Step(tool, params). With options={"idempotency_key": "k"} each step uses k:step-<n>.
Files
doc = wf.documents.create("big-scan.pdf", title="Scan") # returns a typed Document
wf.documents.download(doc).save("copy.pdf") # current version, streamed
wf.document_versions.download(doc.id, version_id).save("downloads/")
Files up to 50 MiB go up in one streamed request. Larger files use the resumable upload: the SDK computes the SHA-256 while reading, sends parts of the size the API chooses (8 MiB today), retries each part on its own and never holds the whole file in memory. A file the workspace already stores completes at once. Downloads stream to a temporary file, are checked against the checksum the API sends, and are moved into place.
Errors
WellfriendError
├─ APIError status, code, message, reference_id, details, headers
│ ├─ BadRequestError (400)
│ │ └─ ValidationError (422, or a 400 whose code ends in _INVALID/_REQUIRED/_UNSUPPORTED)
│ ├─ AuthenticationError (401) PermissionDeniedError (403)
│ ├─ NotFoundError (404) ConflictError (409)
│ ├─ RateLimitError (429, retry_after)
│ └─ ServerError (5xx)
├─ ConnectionError (also a builtin ConnectionError)
├─ TimeoutError (also a builtin TimeoutError)
├─ OperationFailedError code, operation
├─ WaitTimeoutError operation_id
└─ WebhookVerificationError
from wellfriend import ValidationError, OperationFailedError
try:
wf.tools.rotate_pdf("in.pdf", angle="45")
except ValidationError as error:
print(error.code, error) # OPERATION_INPUT_INVALID ... (reference ref_...)
str(error) is the API's message followed by (reference <id>); quote the reference when you contact Support.
Retries and timeouts
wf = Wellfriend(timeout=60, max_retries=2, wait_timeout=900)
wf.documents.list(options={"timeout": 5, "max_retries": 0})
wf.tools.compress_pdf("in.pdf", options={"idempotency_key": "invoice-1234-compress"})
- Network errors and 408, 429, 500, 502, 503, 504 and 520-524 answers are retried with exponential backoff and full
jitter (0.5 s base, 8 s cap), honouring
Retry-After. Reads are retried, and so are writes that carry an idempotency key. - Writes the API de-duplicates get a generated idempotency key, reused for each retry of that call. Pass your
own with
options={"idempotency_key": ...}; a tool call derives the keys of its uploads from it. timeoutcovers connecting, the response headers and each idle read. It never cuts off a long upload or download that is still moving.- Every method takes the same
optionsdict:idempotency_key,timeout,max_retries,headers. Wellfriend(http_client=httpx.Client(...))uses your own client (proxies, certificates).
Webhooks
from wellfriend import verify_webhook
event = verify_webhook(request.body, request.headers, "whsec_...") # or wf.webhooks.verify(...)
if event.type == "com.wellfriend.document-operation.completed.v2":
print(event.data.output_document_id)
It checks the Standard Webhooks signature (v1, HMAC-SHA256 with the whsec_ secret, or v1a, Ed25519 with
the endpoint's public key) over the raw body, refuses timestamps more than 5 minutes away, and returns a typed
event. Pass a list of secrets during a rotation. wf.webhooks.verify defaults to WELLFRIEND_WEBHOOK_SECRET.
All resources
Every API operation is a method named after its operation id: <group>.<action> becomes
wf.<group>.<action>() in snake_case.
for doc in wf.documents.list(q="invoice"): # pages automatically
print(doc.id, doc.title)
link = wf.secure_links.create(document_id=doc.id, authentication_mode="PUBLIC_UNLISTED")
endpoint = wf.webhooks.endpoints.create(url="https://example.com/hooks", event_filters=["*"])
run = wf.workflow_runs.get("wfrun_...")
Arguments are snake_case and map to the API's camelCase names. Responses are typed models where the API
describes them (Document, Operation, Upload, Quote, ...) and ApiObject otherwise, which reads members
by snake_case attribute (obj.next_cursor) or by key (obj["nextCursor"]); to_dict() returns the raw JSON.
List methods return a page you can iterate across pages (async for with the async client). Use
extra_body={...} to send a field the SDK does not know yet. The server-side signature check of a delivery is
wf.webhooks.verify_remote(...). A TOOL embed session (one tool workspace in your page) is
wf.embed_sessions.create_tool(tool_id, parent_origin, preset=..., locked_parameters=...).
Metadata
Release files for wellfriend-document-sdk 1.0.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 | Provenance | Actions |
|---|---|---|---|---|
| wellfriend_document_sdk-1.0.0.tar.gz | 129.1 kB | Without provenance | Details for wellfriend_document_sdk-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| wellfriend_document_sdk-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for wellfriend_document_sdk-1.0.0-py3-none-any.whl |
Total release size: 253.3 kB
Release files / wellfriend_document_sdk-1.0.0.tar.gz
| Download URL | wellfriend_document_sdk-1.0.0.tar.gz |
|---|---|
| Size | 129.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4f2b22458f950eedfeea177bf47303db2bc850c41fb34c5f06dc0b05f3a55ca1
|
|
BLAKE2b-256 checksum How to use checksums |
52e0694c091d0015c3ef210cafb4ed0ae37d58ba7bc579ed770a1522d78718f5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Release files / wellfriend_document_sdk-1.0.0-py3-none-any.whl
| Download URL | wellfriend_document_sdk-1.0.0-py3-none-any.whl |
|---|---|
| Size | 124.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cd3e41cb532ebf45da032b2a154a20c280983b38f0d8d1722f81f36503b5ad6f
|
|
BLAKE2b-256 checksum How to use checksums |
6074f8d699f57d247e98e42449c162e6d5ee45b5ee4796ab1335b748fb2fa3cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Security for wellfriend-document-sdk 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.