Skip to Content
NotebooksPDFSaved pipelines

Saved pipelines

Download notebook (.ipynb)

Save a PDF operation set once, list and read it, run it on a PDF, then delete it.

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()) pdf = SAMPLES / "pdf" / "samples" / "bitcoin.pdf"
pipeline = client.pdf.create_pipeline({"name": "SDK demo: rotate", "operations": {"rotate_angle": 90}}) show(pipeline) assert pipeline["operations"] == {"rotate_angle": 90}
pipelines = client.pdf.list_pipelines() show(pipelines) assert pipeline["id"] in [p["id"] for p in pipelines["pipelines"]]
got = client.pdf.get_pipeline(pipeline["id"]) show(got) assert got["name"] == pipeline["name"]
from indox_client import BadRequestError try: run = client.pdf.run_pipeline(pipeline["id"]) except BadRequestError as exc: print(f"SDK gap: run_pipeline cannot upload the PDF ({exc.status_code} {exc.message});" " running the same operations through pdf.convert") run = client.pdf.convert(pdf, target_format="pdf", data={"options": got["operations"]}) show(run) assert run["status"] == "pending"
done = client.pdf.wait(run["id"]) show(done) rotated = client.pdf.download(run["id"], out / "bitcoin-rotated.pdf") assert b"/Rotate" in rotated.read_bytes()

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())
deleted = client.pdf.delete_pipeline(pipeline["id"]) show(deleted) client.conversion.delete(run["id"]) assert deleted["deleted"]