The Python SDK supports indexing pending data to implement optimistic updates in your application.
Adding support for pending blocks to your application is easy, simply configure
IndexerRunner as follows:
handle_pending is a function with the following signature:
async def handle_pending(info: Info, block_events: NewEvents):pass
The chain-aware storage provided by the Python SDK will handle data invalidation for you:
- On every new
pendingdata, it invalidates all data from the previously handled pending block.
- On new
datablocks, it invalidates any pending data.
- Don't add dynamic filters in the pending block handler. This is currently not supported.
- Use an
interval_secondsthat makes sense for your application.
- Add an attribute to documents to track wether the document was inserted in an accepted block or in a pending block. Use this information to clearly display data in your application.