async-substrate-interface
Asyncio library for interacting with Substrate. It aims to be mostly API-compatible with `py-substrate-interface`. The current version is 1.6.4, with frequent releases, often several per month. It utilizes `bt-decode` for faster SCALE decoding.
Warnings
- breaking Version 1.6.4 introduced changes to fix the 'legacy (old) runtimeApi'. Users relying on older runtime API interaction patterns might need to update their code to align with these changes.
- deprecated Support for Python 3.9 was officially removed in version 1.6.2. Attempts to use the library with Python 3.9 or older will likely result in installation or runtime errors.
- gotcha While designed to be 'mostly API-compatible with py-substrate-interface', the library is explicitly stated as 'about 90% API compatible' and 'its own library'. This implies that subtle differences in API or behavior may exist.
- gotcha The library employs various caching mechanisms (in-memory and disk-based via `DiskCachedAsyncSubstrateInterface`). Cache sizes are configurable via environment variables (`SUBSTRATE_CACHE_METHOD_SIZE`, `SUBSTRATE_RUNTIME_CACHE_SIZE`), and disk caching is keyed by the network URI.
- gotcha The documentation suggests that while `AsyncSubstrateInterface` can be used directly, it is generally recommended to use it as part of `AsyncSubtensor` when operating within the Bittensor ecosystem.
Install
-
pip install async-substrate-interface
Imports
- AsyncSubstrateInterface
from async_substrate_interface import AsyncSubstrateInterface
Quickstart
import asyncio
from async_substrate_interface import AsyncSubstrateInterface
async def main():
substrate = AsyncSubstrateInterface(
url="wss://rpc.polkadot.io"
)
async with substrate:
result = await substrate.query(
module='System',
storage_function='Account',
params=['5CZs3T15Ky4jch1sUpSFwkUbYEnsCfe1WCY51fH3SPV6NFnf'] # Example address
)
print(result)
if __name__ == '__main__':
asyncio.run(main())