SDKs
Python
Padrões idiomáticos de Python para a Thunderbit Open API
Os SDKs oficiais estão a caminho. Até lá, a API da Thunderbit é uma superfície REST HTTP/JSON simples — httpx (ou requests) é tudo o que você precisa.
Instalar
pip install httpxConfigurar
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 de uma página
resp = client.post("/distill", json={"url": "https://thunderbit.com/playground"})
resp.raise_for_status()
print(resp.json()["data"]["markdown"])Extract de dados estruturados
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
Para pipelines de alta vazão, troque para 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]Para mais de ~10 URLs, prefira /batch/distill em vez de fan-out de chamadas individuais — veja Ciclo de Vida de Batch Job.
Um SDK Python oficial está em desenvolvimento — volte em breve.