{"id":18683522,"url":"https://github.com/narasimha1997/aio-eth","last_synced_at":"2025-09-11T01:10:01.071Z","repository":{"id":104766289,"uuid":"484810327","full_name":"Narasimha1997/aio-eth","owner":"Narasimha1997","description":"A simple python library that can be used to run large Web3 queries on Ethereum blockchain concurrently as per Ethereum JSON-RPC specification.","archived":false,"fork":false,"pushed_at":"2022-04-24T04:38:42.000Z","size":28,"stargazers_count":28,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-12T04:40:24.615Z","etag":null,"topics":["asyncio","blockchain","ethereum","python3","web3"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Narasimha1997.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-04-23T17:16:03.000Z","updated_at":"2024-06-09T11:54:41.000Z","dependencies_parsed_at":"2023-05-29T17:15:08.154Z","dependency_job_id":null,"html_url":"https://github.com/Narasimha1997/aio-eth","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/Narasimha1997/aio-eth","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Narasimha1997%2Faio-eth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Narasimha1997%2Faio-eth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Narasimha1997%2Faio-eth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Narasimha1997%2Faio-eth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Narasimha1997","download_url":"https://codeload.github.com/Narasimha1997/aio-eth/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Narasimha1997%2Faio-eth/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274557583,"owners_count":25307516,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-10T02:00:12.551Z","response_time":83,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asyncio","blockchain","ethereum","python3","web3"],"created_at":"2024-11-07T10:14:50.485Z","updated_at":"2025-09-11T01:10:01.054Z","avatar_url":"https://github.com/Narasimha1997.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"## aio-eth - Asynchronous JSON-RPC client for Ethereum\nA simple python library that can be used to run large Web3 queries on [Ethereum blockchain](https://ethereum.org/en/) concurrently as per [Ethereum JSON-RPC specification](https://ethereum.org/en/developers/docs/apis/json-rpc/).\n\nThe library provides a bare minimal framework for expressing raw JSON-RPC queries as described in the Ethereum Specification and execute them together either concurrently (off-chain on the client side) or together as a batch (JSON-RPC batch specification on-chain). This method greatly reduces the time required to run large queries sequentially and thus can be used for use-cases where we need to index large number of transactions happening on ethereum blockchain in a local database for faster Web2 queries.\n\n### Features\n1. Provides interface for concurrent execution of large number of JSON-RPC queries\n2. Provides interface for batched execution of large number of JSON-RPC queries\n3. Provides complete flexibility to call any JSON-RPC method by allowing users to specify raw queries directly.\n\n### Requirements:\n1. Python 3.6+\n\n### How to install:\n\n1. From source:\n```\ngit clone git@github.com:Narasimha1997/aio-eth.git\ncd aio-eth\npip3 install -e .\n```\n\n2. From [PyPi](https://pypi.org/):\n```\npip3 install aio-eth\n``` \n\n### Examples:\n\n1. Run tasks concurrently: This method will create a socket for each task on the client-side and executes the JSON-RPC calls concurrently. Under the hood, this method uses [aiohttp](https://docs.aiohttp.org/en/stable/) module. By this way you are using the client machine's resources and bandwidth to run queries by creating N concurrent sockets.\n\n```python\nimport asyncio\nimport aio_eth\nimport time\n\nURL = \"https://rinkeby.infura.io/v3/b6fe23ef7add48d18d33c9bf41d5ad0c\"\n\nasync def query_blocks():\n\n    # create the API handle\n    async with aio_eth.EthAioAPI(URL, max_tasks=100) as api:\n\n        # express queries - example: get all transactions from 70 blocks\n        # starting from 10553978\n        for i in range(10553978, 10553978 + 70):\n\n            # submit tasks to the task list, if `current tasks \u003e max_tasks`\n            # this method throws an exception.\n            api.push_task({\n                \"method\": \"eth_getBlockByNumber\",\n                \"params\": [\n                    hex(i), True\n                ]\n            })\n        \n\n        st = time.time()\n        # execute the tasks together concurrently, outputs are returned in the same\n        # order in which their corresponding queries where submitted.\n        result = await api.exec_tasks_async()\n        et = time.time()\n        print('time taken: ', et - st, ' seconds')\n\nif __name__ == \"__main__\":\n    loop = asyncio.get_event_loop()\n    loop.run_until_complete(query_blocks())\n```\n\nOutput:\n```\ntime taken:  1.5487761497497559  seconds\n```\n\n2. Run tasks as batch: This method will submit the batch of queries to the connected Ethereum RPC server and expects the output of all the queries at once, unlike concurrent method, here you will be using only one socket as all the queries are submitted as batch. While Batch API is very useful, few providers do not support batch queries, so make sure your provider supports batch queries before using this.\n\n```python\nimport asyncio\nimport aio_eth\nimport time\n\nURL = \"https://rinkeby.infura.io/v3/b6fe23ef7add48d18d33c9bf41d5ad0c\"\n\nasync def query_blocks():\n\n    # create the API handle\n    async with aio_eth.EthAioAPI(URL, max_tasks=100) as api:\n\n        # express queries - example: get all transactions from 70 blocks\n        # starting from 10553978\n        for i in range(10553978, 10553978 + 70):\n\n            # submit tasks to the task list, if `current tasks \u003e max_tasks`\n            # this method throws an exception.\n            api.push_task({\n                \"method\": \"eth_getBlockByNumber\",\n                \"params\": [\n                    hex(i), True\n                ]\n            })\n        \n\n        st = time.time()\n        # execute the tasks together as batch, outputs are returned in the same\n        # order in which their corresponding queries where submitted.\n        result = await api.exec_tasks_batch()\n        et = time.time()\n        print('time taken: ', et - st, ' seconds')\n\nif __name__ == \"__main__\":\n    loop = asyncio.get_event_loop()\n    loop.run_until_complete(query_blocks())\n```\nOutput:\n```\ntime taken:  3.698002576828003  seconds\n```\nIt can be noted that using concurrent connects gives result in less time when compared to batch API, but Batch API can be helpful for large queries involving hundreds of tasks as opening many concurrent sockets while eat up the system's resources.\n\n### Handling errors:\n1. When using `exec_tasks_async` - each task can succeed or fail independently as they are executed concurrently, each item in the result contains a key called `success`, which is either `True` or `False`, if `success` is `False`, then a field called `exception` can be read to get the `Exception` object of the corresponding error.\n2. When using `exec_tasks_batch`, all of the tasks can either succeed or fail as it is executed on the server side. For this reason, the method throws an exception on failure and must be handled externally.\n\n### Maximum tasks size:\nWe can limit the number of tasks that can be allowed to be submitted at once by calling `set_max_tasks` method. By default it is set to 100. When we try to more tasks above this limit using `push_task` an exception is thrown. Example:\n\n```python\nasync with aio_eth.EthAioAPI(URL, max_tasks=100) as api:\n    ......\n    # set max task size\n    api.set_max_tasks(500)\n    .......\n```\n\n### TODO:\n1. Support Web Sockets channel\n\n### Contributing\nPlease feel free to raise issues and submit PRs.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnarasimha1997%2Faio-eth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnarasimha1997%2Faio-eth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnarasimha1997%2Faio-eth/lists"}