Key Features
- Modern Python: Python 3.8+ with full type hints
- Sync and Async: Both
Client(sync) andAsyncClient(async) clients - httpx Powered: Industry-standard HTTP client with automatic retries
- Dataclass Models: Clean, typed data structures
- uv-Ready: Includes
pyproject.tomlfor modern Python packaging - SSE Streaming: First-class Server-Sent Events support
Quick Start
Step 1: Define Your Contract
Step 2: Generate the SDK
Step 3: Install and Use
Generated Code Structure
pyproject.toml
init.py
Client Configuration
Creating a Client
Configuration Options
Modifying Client Options
Create a new client with modified options:Closing the Client
Always close the client when done:Async Client
The SDK includes a fully async client for use withasyncio:
Async Context Manager
Type System
Type Mapping Reference
Dataclass Types
Contract struct types generate Python dataclasses:Optional and Nullable Fields
Example:
Enum Fields
Enum fields use literal type hints in the docstring:List and Dict Types
Resources and Methods
Resource Pattern
Each contract resource becomes a property on the client:Method Signatures
Methods use Python naming conventions (snake_case):Calling Methods
Methods accept keyword arguments matching the input type fields:Streaming (SSE)
For methods with streaming support, the SDK provides iterator-based consumption:Sync Streaming
Async Streaming
Collecting All Events
Error Handling
Error Types
The SDK defines three error types:Handling Errors
Automatic Retries
The client automatically retries failed requests (except for 4xx errors):- Network errors
- 5xx server errors
- Timeout errors
Advanced Usage
Custom Headers
Authentication Modes
The SDK supports different authentication modes based on your service configuration:Timeout Configuration
Using with Existing httpx Client
The generated SDK uses httpx internally. For advanced use cases, you can access the underlying client:Complete Example
Server
Client Usage
Async Example
Installation and Distribution
Installing Locally
Publishing to PyPI
Installing from Git
See Also
- Overview - Introduction to SDK generation
- Go - Generate Go clients
- TypeScript - Generate TypeScript clients
- Types - Contract type system
- REST Transport - Serve your API over REST