Skip to content

v2.0.0

Choose a tag to compare

@nessshon nessshon released this 09 Mar 23:58

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/ and pytonapi/schema/ have been removed
  • REST resources moved to pytonapi/rest/resources/, models to pytonapi/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 conversion
  • to_nano(), to_amount() — amount conversion with Decimal precision

Changes

TonapiRestClient — async REST client

  • Built on aiohttp with 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

  • TonapiStreaming client with .sse and .ws properties
  • 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 management
  • TonapiWebhookDispatcher — 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 codegen generates 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.