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 가 개발 중입니다 —— 곧 다시 확인해 주세요.