Skip to Content
NotebooksPDFBlank forms

Blank forms

Download notebook (.ipynb)

Browse the public IRS/USCIS blank-form catalog with the Indox SDK: list, get one, blank download URL, its fields, then fill two fields and save the PDF.

Config

Add your settings to the repo .env (local) or Colab Secrets — this cell reads them with get(...): INDOX_API_KEY (your ak_… key) and INDOX_BASE_URL (https://indox.org; the SDK adds /api/v1/… itself). A missing key stops here with its name.

import json, logging, re, sys, tempfile from pathlib import Path REPO = Path.cwd().parents[1] sys.path[:0] = [str(REPO), str(REPO / "languages" / "python")] try: from google.colab import userdata get = userdata.get except ImportError: from tools.env import require_env as get from indox_client import Indox logging.basicConfig(format="→ %(message)s", force=True) logging.getLogger("urllib3.connectionpool").setLevel(logging.DEBUG) def _mask(record): record.msg = re.sub(r"/(public|sign)/[^/ ]+", r"/\1/***", record.getMessage()) record.args = () return True logging.getLogger("urllib3.connectionpool").addFilter(_mask) def show(data, limit=2500): print(json.dumps(data, indent=2, default=str)[:limit]) client = Indox(api_key=get("INDOX_API_KEY"), base_url=get("INDOX_BASE_URL")) start_credits = client.billing.credits_balance()["credit_amount"] SAMPLES = REPO / "colab" out = Path(tempfile.mkdtemp()) SLUG = "w9"
forms = client.pdf.forms.list(source="irs", q="w-9", limit=3) show(forms) assert SLUG in [f["slug"] for f in forms["items"]]
form = client.pdf.forms.get(SLUG) show(form) assert form["fields"] > 0
blank = client.pdf.forms.blank(SLUG) show({**blank, "url": blank["url"].split("?")[0] + "?<signed query hidden>"}) assert blank["url"].startswith("http")
import time for _ in range(30): fields = client.pdf.forms.fields(SLUG) if fields.get("status") != "pending": break time.sleep(2) show(fields) text = [f["name"] for f in fields["fields"] if f["type"] == "text"] assert len(text) >= 2
filled = client.pdf.forms.fill( SLUG, {text[0]: "Ada Lovelace", text[1]: "Analytical Engines LLC"}, out / "w9-filled.pdf" ) show({"saved": str(filled), "bytes": filled.stat().st_size}) assert filled.read_bytes()[:5] == b"%PDF-"

Usage

now = client.billing.credits_balance()["credit_amount"] print(f"credits used by this notebook: {start_credits - now} (balance {now})") show(client.billing.usage_by_feature())