How to subscribe events #306
-
Hi, I'm looking for a way to subscribe a runtime events using py-substrate-interface but couldn't any document or example regarding it. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
This is not possible at the moment, as the current library is only intended be used in a synchronous context. Eventually we would also like to have a async version, for async Python apps. |
Beta Was this translation helpful? Give feedback.
-
The only subscription is currently supports is to wait for the result when sending an extrinsic (the |
Beta Was this translation helpful? Give feedback.
-
Thank you for your reply! I understood that. |
Beta Was this translation helpful? Give feedback.
-
Good news, since latest release https://github.com/polkascan/py-substrate-interface/releases/tag/v0.12.1 storage subscriptions are possible, so for example to subscribe to events: def subscription_handler(obj, update_nr, subscription_id):
# Do something with the update
print('Events:', obj.value)
# The execution will block until an arbitrary value is returned, which will be the result of the `query`
if update_nr > 5:
return {'updates': update_nr, 'message': 'processed events'}
result = substrate.query("System", "Events", [], subscription_handler=subscription_handler) |
Beta Was this translation helpful? Give feedback.
Good news, since latest release https://github.com/polkascan/py-substrate-interface/releases/tag/v0.12.1 storage subscriptions are possible, so for example to subscribe to events: