Python

Use Create a Fillable PDF from Python.

Official PyPI package coming soon. Until it's published, call the REST API directly with the requests library (pip install requests). Everything below works today.

Convert a PDF

import os
import requests

with open("applicant.pdf", "rb") as f:
    res = requests.post(
        "https://api.createafillablepdf.com/v1/convert",
        headers={"Authorization": f"Bearer {os.environ['CAFP_KEY']}"},
        files={"file": ("applicant.pdf", f, "application/pdf")},
        data={"detect": "fields"},
    )

if not res.ok:
    err = res.json()["error"]
    raise RuntimeError(f"{err['type']}: {err['message']}")

result = res.json()
print(result["fields"], result["document_url"])

Fill a converted document

import os
import requests

res = requests.post(
    "https://api.createafillablepdf.com/v1/fill",
    headers={"Authorization": f"Bearer {os.environ['CAFP_KEY']}"},
    json={
        "conversion_id": "c_123",
        "values": {"applicant_legal_name": "Dana Okonkwo", "is_us_citizen": True},
    },
)
with open("filled.pdf", "wb") as f:
    f.write(res.content)  # the filled PDF

When the official package ships, this becomes from createafillablepdf import FillablePDF with client.convert(...) and client.fill(...). The REST calls above will keep working either way.