Setup & Usage
Quick start
Copy the generated package into your project tree. Python SDK needs aiohttp
installed; TypeScript SDK has zero dependencies.
from articles_sdk import sdk
sdk.setup(
host="https://api.example.com/",
headers=lambda: {"Authorization": "Bearer " + token},
)
async with sdk:
article = await sdk.articles.get(1)
print(article.title)
article = await sdk.articles.get(1)
async with sdk: creates and closes an aiohttp.ClientSession. The host
defaults to http://localhost:8000/. Configure before making requests:
Global singleton vs instance
Both Python and TypeScript generated SDKs export a pre-instantiated sdk
object. This is convenient for simple apps where all requests use the same host
and auth.
However, a single global config is unsafe when your code makes requests on behalf of different users — a background task in an OAuth application, for instance. In that case, create separate instances:
SDK lifecycle
SDK()— create instance (no network)sdk.setup(host=..., headers=...)— optional, any time before requestsasync with sdk:— opens session, closes on exit- Inside context: make requests
Reuse the same SDK instance across requests. Sessions are cheap.
new SDK()or use exportedsdk— create instance (no network)sdk.setup({host, headers})— configure host and auth- Start making requests immediately
No explicit session. Each request calls fetch() with configured headers.
Resource access
Unknown resource types raise error:
Debug logging
Enable logging to see every HTTP request and response:
The Python SDK uses standard logging.getLogger(__name__) throughout. Set
level to DEBUG to see method, URL, params, status, and response body for
every request.