v2.0.0
pytonapi 2.0 Release Notes
Major release with full architectural refactoring, new modular client infrastructure, streaming and webhook support.
Migration from the previous version is non-trivial. The previous version remains available:
pip install "pytonapi<2.0"
Examples
Practical examples for all modules are located in the examples/ folder.
Breaking Changes
Module structure — full reorganization
pytonapi/methods/andpytonapi/schema/have been removed- REST resources moved to
pytonapi/rest/resources/, models topytonapi/rest/models/ - Entry point changed:
Tonapi→TonapiRestClient
Client lifecycle — explicit session management
create_session()/close_session()instead of implicit lazy initialization- Context manager supported:
async with TonapiRestClient(...) as tonapi: - External session can be passed via
session=parameter
Models — auto-generated from OpenAPI
- All Pydantic models regenerated from the official TON API spec
- Method
.to_raw(),.to_amount()removed from models — use utility functions instead - Address fields use plain
str, not custom types
Utility functions
raw_to_userfriendly(),userfriendly_to_raw()— address conversionto_nano(),to_amount()— amount conversion withDecimalprecision
Changes
TonapiRestClient — async REST client
- Built on
aiohttpwith configurable timeout, headers, and cookies - Rate limiting via
rps_limit/rps_period(sliding-window algorithm) - 18 resource groups: accounts, blockchain, jettons, nft, dns, staking, and more
RetryPolicy — retry policies
- Configurable per HTTP status code (429, 5xx)
- Exponential backoff with
base_delay,max_delay,backoff_factor - Built-in defaults:
DEFAULT_RETRY_POLICY
Streaming — SSE and WebSocket transports
TonapiStreamingclient with.sseand.wsproperties- Subscribe to transactions, blocks, traces, and mempool
- Automatic reconnection with configurable
ReconnectPolicy - Graceful shutdown via
asyncio.Event
Webhooks — push notifications
TonapiWebhookClient— HTTP CRUD for webhook managementTonapiWebhookDispatcher— event routing with decorator-based handler registration- Four event types:
account_tx,mempool_msg,opcode_msg,new_contracts - Per-path token verification, dependency injection, sync/async handlers
- Ready-made examples for FastAPI and aiohttp
Codegen — code generation from OpenAPI spec
python -m codegengenerates models, resources, mixin, and test scaffolds- Jinja2 templates, configurable method name overrides
- Fixtures file for manual test data — not overwritten by codegen
Before using in production
- Carefully review your code against the new API
- Test your logic on testnet before switching to mainnet
Found a bug — open an Issue or Pull Request. Let's make the library better together.