SDKs

Python

Pattern Python idiomatici per la Open API di Thunderbit

Gli SDK ufficiali sono in arrivo. Nel frattempo, l'API di Thunderbit è una semplice superficie REST HTTP/JSON — httpx (o requests) è tutto ciò che ti serve.

Installazione

pip install httpx

Configurazione

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)

Distill di una pagina

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

Extract di dati strutturati

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

Per pipeline ad alto throughput, passa a 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]

Per più di ~10 URL, preferisci /batch/distill invece di moltiplicare singole chiamate — vedi Ciclo di vita dei batch job.

Un SDK Python ufficiale è in sviluppo — torna presto a controllare.