{"id":18738062,"url":"https://github.com/blocknative/python-sdk","last_synced_at":"2025-04-12T19:32:42.126Z","repository":{"id":38774968,"uuid":"386097973","full_name":"blocknative/python-sdk","owner":"blocknative","description":null,"archived":false,"fork":false,"pushed_at":"2022-07-05T18:46:53.000Z","size":2966,"stargazers_count":43,"open_issues_count":3,"forks_count":17,"subscribers_count":16,"default_branch":"main","last_synced_at":"2024-04-25T22:22:01.009Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/blocknative.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-07-14T23:03:14.000Z","updated_at":"2024-04-11T12:02:58.000Z","dependencies_parsed_at":"2022-07-09T10:46:11.012Z","dependency_job_id":null,"html_url":"https://github.com/blocknative/python-sdk","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blocknative%2Fpython-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blocknative%2Fpython-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blocknative%2Fpython-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blocknative%2Fpython-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/blocknative","download_url":"https://codeload.github.com/blocknative/python-sdk/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248621366,"owners_count":21134822,"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","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":[],"created_at":"2024-11-07T15:28:02.185Z","updated_at":"2025-04-12T19:32:41.832Z","avatar_url":"https://github.com/blocknative.png","language":"Python","readme":"\u003ca href=\"https://pypi.org/project/blocknative-sdk/\"\u003e\n    \u003cimg src=\"https://img.shields.io/pypi/v/blocknative-sdk\" /\u003e\n\u003c/a\u003e\n\n# Blocknative Python SDK\n\n## Install\n\nVirtualEnv QuickStart\n\n```bash\n$ virtualenv bn\n$ . ./bn/bin/activate\n(bn) $ pip3 install --upgrade pip\n(bn) $ pip3 install blocknative-sdk\n(bn) $ curl 'https://raw.githubusercontent.com/blocknative/python-sdk/main/examples/subscribe.py' \u003e subscribe.py\n(bn) $ python3 subscribe.py myapikey.key\n```\n\nManual Install\n\n```bash\npython3 setup.py install\n```\n\n## API Key\n\nTo get started using the Blocknative Python SDK you must first obtain an API Key. You can do so by heading over to [Blocknative.com](https://explorer.blocknative.com/account)!\n\n## Usage\n\n### Basic usage\n\n```python\nfrom blocknative.stream import Stream\nimport json\n\n# Initialize the stream\nstream = Stream('\u003cAPI_KEY\u003e')\n\n# Define your transaction handler which has the context of a specific subscription.\nasync def txn_handler(txn, unsubscribe):\n    # Output the transaction data to the console\n    print(json.dumps(txn, indent=4))\n\n# Define the address you want to watch\nuniswap_v2_address = '0x7a250d5630b4cf539739df2c5dacb4c659f2488d'\n\n# Register the subscription\nstream.subscribe_address(uniswap_v2_address, txn_handler)\n\n# Start the websocket connection and start receiving events!\nstream.connect()\n```\n\n### Unsubscribing\n\n```python\nfrom blocknative.stream import Stream\nimport json\n\n# Initialize the stream\nstream = Stream('\u003cAPI_KEY\u003e')\n\n# Define your transaction handler\nasync def txn_handler(txn, unsubscribe):\n    if txn['status'] == \"confirmed\":\n        # Output the transaction data to the console\n        print(json.dumps(txn, indent=4))\n\n        # Unsubscribe from this subscription\n        unsubscribe()\n\n# Define the address you want to watch\nuniswap_v2_address = '0x7a250d5630b4cf539739df2c5dacb4c659f2488d'\n\n# Register the subscription\nstream.subscribe_address(uniswap_v2_address, txn_handler)\n\n# Start the websocket connection and start receiving events!\nstream.connect()\n```\n\n### Using Filters\n\n```python\nfrom blocknative.stream import Stream\nimport json\n\nstream = Stream('\u003cAPI_KEY\u003e')\n\nasync def txn_handler(txn, unsubscribe):\n    # This will only get called with transactions that have status of 'confirmed'\n    # This is due to the global filter above\n    print(json.dumps(txn, indent=4))\n\nuniswap_v2_address = '0x7a250d5630b4cf539739df2c5dacb4c659f2488d'\n\nfilters = [{\n    'status': 'confirmed'\n}]\n\n# Global filter will apply to all of these subscriptions\nstream.subscribe_address(curve_fi_address, txn_handler, filter=filters)\n\n# Start the websocket connection and start receiving events!\nstream.connect()\n```\n\n### Using Global Filters\n\nSimilar as above but this time we use global filters which will apply to all subscriptions.\n\n```python\nfrom blocknative.stream import Stream\nimport json\n\nglobal_filters = [{\n    'status': 'confirmed'\n}]\n\nstream = Stream('\u003cAPI_KEY\u003e', global_filters=global_filters)\n\nasync def txn_handler(txn, unsubscribe):\n    # This will only get called with transactions that have status of 'confirmed'\n    # This is due to the global filter above\n    print(json.dumps(txn, indent=4))\n\nuniswap_v2_address = '0x7a250d5630b4cf539739df2c5dacb4c659f2488d'\ncurve_fi_address = '0xdf5e0e81dff6faf3a7e52ba697820c5e32d806a8'\nsushi_swap_address = '0xd9e1ce17f2641f24ae83637ab66a2cca9c378b9f'\n\n# Global filter will apply to all of these subscriptions\nstream.subscribe_address(curve_fi_address, txn_handler)\nstream.subscribe_address(uniswap_v2_address, txn_handler)\nstream.subscribe_address(sushi_swap_address, txn_handler)\n\n# Start the websocket connection and start receiving events!\nstream.connect()\n```\n\n### Connecting to Binance Smart Chain\n\n```python\nfrom blocknative.stream import Stream\nimport json\n\nBSC_NETWORK_ID = 56\n\n# Initialize the stream - specify network_id `56` to connect to bsc main\nstream = Stream('\u003cAPI_KEY\u003e', network_id=BSC_NETWORK_ID)\n\n# Define your transaction handler which has the context of a specific subscription.\nasync def txn_handler(txn, unsubscribe):\n    # Output the transaction data to the console\n    print(json.dumps(txn, indent=4))\n\n# Define the address you want to watch\npancakeswap_v2_address = '0x10ed43c718714eb63d5aa57b78b54704e256024e'\n\n# Register the subscription\nstream.subscribe_address(pancakeswap_v2_address, txn_handler)\n\n# Start the websocket connection and start receiving events!\nstream.connect()\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblocknative%2Fpython-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblocknative%2Fpython-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblocknative%2Fpython-sdk/lists"}