- Docs
- Developer Kit
- Python SDK
Python SDK
Official Python client with sync and async interfaces covering every Dual API endpoint.
The Python SDK (v1.0.0) is an official Python client with sync and async interfaces covering every Dual API endpoint. Built on httpx with automatic retry, Pydantic models, and a typed error hierarchy.
Requirements: Python >= 3.9 · httpx · pydantic v2
Installation
pip install dual-sdk
Quick Start
import osfrom dual_sdk import DualClientclient = DualClient(token=os.environ["DUAL_API_KEY"],auth_mode="api_key",)# Returns a typed Wallet modelwallet = client.wallets.me()print(wallet.id, wallet.email)# Returns PaginatedResponse[Template]page = client.templates.list(limit=20)for tmpl in page.items:print(tmpl.name)# Returns a typed Object modelobj = client.objects.create(template_id="tmpl_abc123",properties={"name": "My First Token"})print(obj.id)
Async Support
Use AsyncDualClient for non-blocking I/O. Every method mirrors the sync API with await.
import asynciofrom dual_sdk import AsyncDualClientasync def main():async with AsyncDualClient(token=os.environ["DUAL_API_KEY"], auth_mode="api_key") as client:wallet = await client.wallets.me()templates = await client.templates.list(limit=20)# Concurrent requestsimport asyncioresults = await asyncio.gather(client.objects.list(limit=10),client.templates.list(limit=10),client.organizations.list(limit=10),)asyncio.run(main())
Configuration
The SDK supports custom timeouts, retry policies with exponential backoff, and base URL configuration.
from dual_sdk import DualClient# API key auth (default)client = DualClient(token=os.environ["DUAL_API_KEY"],auth_mode="api_key",base_url="https://api-testnet.dual.network", # defaulttimeout=10.0, # secondsmax_retries=3, # retry on 429/5xxbackoff=1.0, # exponential backoff base)# JWT bearer token authjwt_client = DualClient(token=os.environ["DUAL_JWT"],auth_mode="bearer",)
Error Handling
All API errors are raised as DualError subclasses with status, code, message, and full response body.
from dual_sdk import DualClient, DualError, DualAuthError, DualRateLimitErrorclient = DualClient(token=os.environ["DUAL_API_KEY"], auth_mode="api_key")try:wallet = client.wallets.me()except DualAuthError as e:print(f"Auth failed [{e.status}]: {e.code}")except DualRateLimitError as e:print(f"Rate limited. Retry after {e.retry_after}s")except DualError as e:print(f"API error [{e.status}]: {e.message}")print("Details:", e.body)
Modules
The SDK provides 14 modules accessible via client.module_name. Each module has identical sync and async interfaces.
View the full source on GitHub · 2,083 lines · 14 modules · sync + async