From b32fa3b5bbcc840b268b4e65bdc59e5cfdb60ddf Mon Sep 17 00:00:00 2001 From: Igor Date: Sat, 15 Feb 2025 20:38:14 -0600 Subject: [PATCH 1/4] fix readme --- README.md | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index aa8f1cd..6331d7d 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,53 @@ -This is a modernised version of the py-substrate-interface library, with the ability to use it asynchronously (as well as synchronously). It aims to be almost fully API-compatible with the original library. +# Async Substrate Interface -In addition to it's async nature, it is additionally improved with using bt-decode rather than py-scale-codec for significantly faster SCALE decoding. +This project provides an asynchronous interface for interacting with [Substrate](https://substrate.io/)-based blockchains. It is based on the [py-substrate-interface](https://github.com/polkascan/py-substrate-interface) project. + +## Features + +- Asynchronous API calls +- Support for multiple Substrate-based networks +- Easy integration with existing projects + +## Installation + +To install the package, use the following command: + +```bash +pip install async-substrate-interface +``` + +## Usage + +Here is a basic example of how to use the async-substrate-interface: + +```python +import asyncio +from async_substrate_interface import SubstrateInterface + +async def main(): + substrate = SubstrateInterface( + url="wss://rpc.polkadot.io" + ) + + result = await substrate.query( + module='System', + storage_function='Account', + params=['5FHneW46xGXgs5mUiveU4sbTyGBzmto4oT9v5TFn5u4tZ7sY'] + ) + + print(result) + +asyncio.run(main()) +``` + +## Contributing + +Contributions are welcome! Please open an issue or submit a pull request. + +## License + +This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. + +## Contact + +For any questions or inquiries, please join the Bittensor Development Discord server: [Church of Rao](https://discord.gg/gavmT4R8sB). From 297bffeba801f0320b75efde9678a40477f3d0b2 Mon Sep 17 00:00:00 2001 From: Igor Date: Sat, 15 Feb 2025 20:43:02 -0600 Subject: [PATCH 2/4] fix readme --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 6331d7d..d009383 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,10 @@ # Async Substrate Interface - This project provides an asynchronous interface for interacting with [Substrate](https://substrate.io/)-based blockchains. It is based on the [py-substrate-interface](https://github.com/polkascan/py-substrate-interface) project. ## Features - Asynchronous API calls -- Support for multiple Substrate-based networks -- Easy integration with existing projects +- Uses [bt-decode](https://github.com/opentensor/bt-decode) instead of [py-scale-codec](https://github.com/polkascan/py-scale-codec) for faster [SCALE](https://polkascan.github.io/py-scale-codec/) decoding. ## Installation From 2b0b4237b696e08d96b6378b481321a3fc469570 Mon Sep 17 00:00:00 2001 From: Igor Date: Tue, 18 Feb 2025 09:45:22 -0600 Subject: [PATCH 3/4] fix feedback --- README.md | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index d009383..cafeb79 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,7 @@ # Async Substrate Interface This project provides an asynchronous interface for interacting with [Substrate](https://substrate.io/)-based blockchains. It is based on the [py-substrate-interface](https://github.com/polkascan/py-substrate-interface) project. -## Features - -- Asynchronous API calls -- Uses [bt-decode](https://github.com/opentensor/bt-decode) instead of [py-scale-codec](https://github.com/polkascan/py-scale-codec) for faster [SCALE](https://polkascan.github.io/py-scale-codec/) decoding. +Additionally, this project uses [bt-decode](https://github.com/opentensor/bt-decode) instead of [py-scale-codec](https://github.com/polkascan/py-scale-codec) for faster [SCALE](https://docs.substrate.io/reference/scale-codec/) decoding. ## Installation @@ -16,31 +13,50 @@ pip install async-substrate-interface ## Usage -Here is a basic example of how to use the async-substrate-interface: +Here are examples of how to use the sync and async inferfaces: ```python -import asyncio from async_substrate_interface import SubstrateInterface -async def main(): +def main(): substrate = SubstrateInterface( url="wss://rpc.polkadot.io" ) - result = await substrate.query( + result = substrate.query( module='System', storage_function='Account', - params=['5FHneW46xGXgs5mUiveU4sbTyGBzmto4oT9v5TFn5u4tZ7sY'] + params=['5CZs3T15Ky4jch1sUpSFwkUbYEnsCfe1WCY51fH3SPV6NFnf'] ) print(result) +main() +``` + +```python +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'] + ) + + print(result) + asyncio.run(main()) ``` ## Contributing -Contributions are welcome! Please open an issue or submit a pull request. +Contributions are welcome! Please open an issue or submit a pull request to the `staging` branch. ## License @@ -48,4 +64,4 @@ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file ## Contact -For any questions or inquiries, please join the Bittensor Development Discord server: [Church of Rao](https://discord.gg/gavmT4R8sB). +For any questions or inquiries, please join the Bittensor Development Discord server: [Church of Rao](https://discord.gg/XC7ucQmq2Q). From 15927d6e37740e811ad103f37bb07795f98f088c Mon Sep 17 00:00:00 2001 From: Igor Date: Tue, 18 Feb 2025 10:00:37 -0600 Subject: [PATCH 4/4] add sync context manager --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index cafeb79..6b78d0d 100644 --- a/README.md +++ b/README.md @@ -22,14 +22,14 @@ def main(): substrate = SubstrateInterface( url="wss://rpc.polkadot.io" ) + with substrate: + result = substrate.query( + module='System', + storage_function='Account', + params=['5CZs3T15Ky4jch1sUpSFwkUbYEnsCfe1WCY51fH3SPV6NFnf'] + ) - result = substrate.query( - module='System', - storage_function='Account', - params=['5CZs3T15Ky4jch1sUpSFwkUbYEnsCfe1WCY51fH3SPV6NFnf'] - ) - - print(result) + print(result) main() ```