SDKs
Python
Thunderbit Open API 的地道 Python 写法
官方 SDK 正在路上。在那之前,Thunderbit API 就是普通的 HTTP/JSON REST 接口 —— httpx(或 requests)足矣。
安装
pip install httpx配置
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 一个页面
resp = client.post("/distill", json={"url": "https://thunderbit.com/playground"})
resp.raise_for_status()
print(resp.json()["data"]["markdown"])Extract 结构化数据
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"])异步
高吞吐流水线请换成 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]URL 数量超过 10 个时,优先用 /batch/distill 而不是单条扇出 —— 详见 Batch Job Lifecycle。
官方 Python SDK 正在开发中,敬请期待。