async with TonapiStreaming("YOUR_API_KEY", Network.MAINNET) as streaming: async for event in streaming.sse.subscribe_transactions(): print(event.tx_hash)
streaming = TonapiStreaming("YOUR_API_KEY", Network.MAINNET)await streaming.create_session()try: async for event in streaming.sse.subscribe_transactions(): print(event.tx_hash)finally: await streaming.close_session()
Transports (streaming.sse and streaming.ws) are lazy-initialized on first access and share the session with the parent client. Accessing a transport before create_session() raises TONAPISessionNotCreatedError.
Use the Opcode enum or raw hex strings to filter transactions by operation code:
from pytonapi.types import Opcodeasync for event in streaming.sse.subscribe_transactions( accounts=["EQ..."], operations=[Opcode.JETTON_TRANSFER, Opcode.JETTON_NOTIFY],): print(f"Jetton activity: {event.tx_hash}")
Available Opcodes
Enum
Hex
TEXT_COMMENT
0x00000000
ENCRYPTED_TEXT_COMMENT
0x2167da4b
EXCESS
0xd53276db
BOUNCE
0xffffffff
TOP_UP
0xd372158c
JETTON_TRANSFER
0x0f8a7ea5
JETTON_INTERNAL_TRANSFER
0x178d4519
JETTON_NOTIFY
0x7362d09c
JETTON_BURN
0x595f07bc
JETTON_MINT
0x642b7d07
JETTON_CHANGE_ADMIN
0x6501f354
JETTON_CHANGE_METADATA
0xcb862902
JETTON_CLAIM_ADMIN
0xfb88e119
JETTON_BURN_NOTIFICATION
0x7bdd97de
JETTON_CALL_TO
0x235caf52
JETTON_SET_STATUS
0xeed236d3
JETTON_UPGRADE
0x2508d66a
NFT_TRANSFER
0x5fcc3d14
NFT_OWNERSHIP_ASSIGNED
0x05138d91
GET_ROYALTY_PARAMS
0x693d3950
GET_STATIC_DATA
0x2fcb26a2
REPORT_ROYALTY_PARAMS
0xa8cb00ad
REPORT_STATIC_DATA
0x8b771735
OUTBID_NOTIFICATION
0x557cea20
PROVE_OWNERSHIP
0x04ded148
OWNERSHIP_PROOF
0x0524c7ae
SBT_DESTROY
0x1f04537a
SBT_REVOKE
0x6f89f5e3
SBT_REQUEST_OWNER
0xd0c3bfea
SBT_OWNER_INFO
0x0dd607e3
CHANGE_DNS_RECORD
0x4eb1f0f9
DELETE_DNS_RECORD
0x4eb1f0f9
DNS_BALANCE_RELEASE
0x4ed14b65
TELEITEM_BID_INFO
0x38127de1
TELEITEM_CANCEL_AUCTION
0x371638ae
TELEITEM_DEPLOY
0x299a3e15
TELEITEM_OK
0xa37a0983
TELEITEM_RETURN_BID
0xa43227e1
TELEITEM_START_AUCTION
0x487a8e81
TELEMINT_DEPLOY
0x4637289a
TELEMINT_DEPLOY_V2
0x4637289b
MULTISIG_NEW_ORDER
0xf718510f
MULTISIG_APPROVE
0xa762230f
MULTISIG_EXECUTE_INTERNAL
0xa32c59bf
You can also pass raw hex strings directly: operations=["0x0f8a7ea5"].
Transient errors (5xx, 429, heartbeat timeout) are retried automatically with exponential backoff. Client errors (400, 401, 403, 404) raise immediately.
from pytonapi.types import ReconnectPolicyasync with TonapiStreaming( "YOUR_API_KEY", Network.MAINNET, reconnect_policy=ReconnectPolicy( max_reconnects=10, # -1 for unlimited delay=0.5, # initial delay (seconds) max_delay=10.0, # upper bound after backoff backoff_factor=2.0, # multiplier per attempt ),) as streaming: ...
Default progression: 0.5 s → 1.0 s → 2.0 s → 4.0 s → 8.0 s → 10.0 s (capped). After all attempts are exhausted, TONAPIConnectionLostError is raised. SSE heartbeats arrive every 5 seconds — if no data arrives within 30 seconds, a reconnect is triggered.
Always close the session properly. After an ungraceful disconnect the server may hold the old session open, counting against your connection limit.