SDKs

Python

Idiomatische Python-patronen voor de Thunderbit Open API

Officiële SDK's zijn onderweg. Tot die tijd is de Thunderbit API een gewone HTTP/JSON REST-interface — httpx (of requests) is alles wat je nodig hebt.

Installeren

pip install httpx

Configureren

import httpx, os

API = "https://openapi.thunderbit.com/openapi/v1"
H = {"Authorization": f"Bearer {os.environ['THUNDERBIT_API_KEY']}"}
client = httpx.Client(base_url=API, headers=H, timeout=60.0)

Een pagina Distillen

resp = client.post("/distill", json={"url": "https://thunderbit.com/playground"})
resp.raise_for_status()
print(resp.json()["data"]["markdown"])

Gestructureerde data Extracten

resp = client.post("/extract", json={
    "url": "https://example.com/product/iphone-15-pro",
    "schema": {
        "type": "object",
        "properties": {
            "name":  {"type": "string"},
            "price": {"type": "number"},
        },
        "required": ["name", "price"],
    },
})
print(resp.json()["data"])

Async

Voor pipelines met hoge doorvoer wissel je naar httpx.AsyncClient:

import asyncio, httpx

async def distill_many(urls: list[str]):
    async with httpx.AsyncClient(headers=H, timeout=60.0) as client:
        tasks = [client.post(f"{API}/distill", json={"url": u}) for u in urls]
        resps = await asyncio.gather(*tasks)
        return [r.json()["data"]["markdown"] for r in resps]

Voor meer dan ~10 URL's gebruik je liever /batch/distill dan losse calls uit te waaieren — zie Batch Job Lifecycle.

Een officiële Python SDK is in ontwikkeling — kom binnenkort terug.