{"id":2358,"library":"web3","title":"web3.py","description":"web3.py is a Python library designed for interacting with the Ethereum blockchain. It enables developers to build decentralized applications (dApps), manage Ethereum accounts, send transactions, interact with smart contracts, and query blockchain data. Currently at version 7.15.0, the library follows Semantic Versioning, with major versions introducing significant breaking changes and frequent minor updates for new features and bug fixes.","status":"active","version":"7.15.0","language":"en","source_language":"en","source_url":"https://github.com/ethereum/web3.py","tags":["ethereum","blockchain","web3","smart-contracts","dapp","web3-py"],"install":[{"cmd":"pip install web3","lang":"bash","label":"Core library"},{"cmd":"pip install \"web3[tester]\"","lang":"bash","label":"With EthereumTesterProvider"}],"dependencies":[{"reason":"Required for the EthereumTesterProvider, useful for local testing without a live node.","package":"eth-tester","optional":true}],"imports":[{"symbol":"Web3","correct":"from web3 import Web3"},{"symbol":"AsyncWeb3","correct":"from web3 import AsyncWeb3"},{"symbol":"HTTPProvider","correct":"from web3 import HTTPProvider"},{"symbol":"IPCProvider","correct":"from web3 import IPCProvider"},{"note":"WebsocketProviderV2 was renamed to WebSocketProvider in v7. The old WebsocketProvider (v5) was renamed to LegacyWebSocketProvider and deprecated in v7.","wrong":"from web3 import WebsocketProviderV2 (v6)","symbol":"WebSocketProvider","correct":"from web3 import WebSocketProvider"}],"quickstart":{"code":"import os\nfrom web3 import Web3, HTTPProvider\n\n# Replace with your actual RPC URL, e.g., from Infura, Alchemy, or a local node.\n# It's best practice to use environment variables for sensitive info.\nINFURA_URL = os.environ.get('WEB3_PROVIDER_URL', 'http://127.0.0.1:8545')\n\n# Initialize Web3 with an HTTPProvider\ntry:\n    w3 = Web3(HTTPProvider(INFURA_URL))\n    if w3.is_connected():\n        print(f\"Successfully connected to Ethereum node at {INFURA_URL}\")\n        # Get the latest block number\n        latest_block = w3.eth.block_number\n        print(f\"Latest block number: {latest_block}\")\n    else:\n        print(f\"Failed to connect to Ethereum node at {INFURA_URL}\")\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")","lang":"python","description":"This quickstart demonstrates how to connect to an Ethereum node using `HTTPProvider` and retrieve the latest block number. For asynchronous operations, use `AsyncWeb3` and an asynchronous provider like `AsyncHTTPProvider` or `WebSocketProvider`."},"warnings":[{"fix":"Ensure all byte-like inputs match the ABI's specified length exactly, or explicitly disable strict bytes checking via `w3.strict_bytes_type_checking = False` if necessary.","message":"Strict bytes checking is enabled by default in v6. This means ABI arguments expecting a specific bytes length (e.g., bytes4) will only accept 0x-prefixed hex strings or bytes types of that exact length. Ambiguous values will be invalidated.","severity":"breaking","affected_versions":">=6.0.0"},{"fix":"Update method and property calls to use `snake_case`. For example, `w3.eth.getBlock('latest')` becomes `w3.eth.get_block('latest')`.","message":"Most API methods and properties were converted from `camelCase` to `snake_case` in v6 to align with Pythonic conventions. Exceptions include contract methods/events (which follow ABI) and JSON-RPC parameters/returns (which follow RPC spec).","severity":"breaking","affected_versions":">=6.0.0"},{"fix":"Instantiate `Web3` for synchronous code and `AsyncWeb3` for asynchronous code. Ensure providers are compatible with the chosen `Web3` instance.","message":"In v6, the `Web3` class was split into `Web3` (for synchronous operations) and `AsyncWeb3` (for asynchronous operations). Providers must match the instance type (e.g., `AsyncWeb3` requires `AsyncHTTPProvider` or `WebSocketProvider`).","severity":"breaking","affected_versions":">=6.0.0"},{"fix":"Rewrite custom middleware to conform to the new class-based structure, separating request and response processing. Consult the official migration guide for examples.","message":"The middleware model changed to a class-based system in v7, replacing the older functional middleware. Middleware logic is now separated into `request_processor` and `response_processor` functions.","severity":"breaking","affected_versions":">=7.0.0"},{"fix":"Remove all reliance on the `web3.ethpm` module. If EthPM-like functionality is still needed, explore alternative solutions or re-implement necessary parts.","message":"The `EthPM` module, deprecated in v6 due to lack of use and functionality issues, was completely removed in v7.","severity":"breaking","affected_versions":">=7.0.0"},{"fix":"Upgrade your Python environment to version 3.8 or later.","message":"Python 3.7 support was dropped in v7. The library now requires Python 3.8 or newer.","severity":"gotcha","affected_versions":">=7.0.0"},{"fix":"Remove any calls to `w3.geth.miner` methods. These functionalities are no longer relevant in modern Ethereum.","message":"The `geth.miner` namespace and its methods were deprecated in v6 and completely removed in v7, reflecting Geth's transition away from mining (Proof-of-Work) to Proof-of-Stake.","severity":"deprecated","affected_versions":">=6.0.0 (deprecated), >=7.0.0 (removed)"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}