The purpose of this page is to give you a sense of everything Web3.py can do and to serve as a quick reference guide. You’ll find a summary of each feature with links to learn more. You may also be interested in the Examples page, which demonstrates some of these features in greater detail.


After installing Web3.py (via pip install web3), you’ll need to specify the provider and any middleware you want to use beyond the defaults.


Providers are how Web3.py connects to the blockchain. The library comes with the following built-in providers:

  • Web3.IPCProvider for connecting to ipc socket based JSON-RPC servers.

  • Web3.HTTPProvider for connecting to http and https based JSON-RPC servers.

  • Web3.WebsocketProvider for connecting to ws and wss websocket based JSON-RPC servers.

>>> from web3 import Web3

# IPCProvider:
>>> w3 = Web3(Web3.IPCProvider('./path/to/geth.ipc'))

# HTTPProvider:
>>> w3 = Web3(Web3.HTTPProvider(''))

# WebsocketProvider:
>>> w3 = Web3(Web3.WebsocketProvider('ws://'))

>>> w3.isConnected()

For more information, (e.g., connecting to remote nodes, provider auto-detection, using a test provider) see the Providers documentation.


Your Web3.py instance may be further configured via middleware.

Web3.py middleware is described using an onion metaphor, where each layer of middleware may affect both the incoming request and outgoing response from your provider. The documentation includes a visualization of this idea.

Several middleware are included by default. You may add to (add, inject, replace) or disable (remove, clear) any of these middleware.

Your Keys

Private keys are required to approve any transaction made on your behalf. The manner in which your key is secured will determine how you create and send transactions in Web3.py.

A local node, like Geth, may manage your keys for you. You can reference those keys using the web3.eth.accounts property.

A hosted node, like Infura, will have no knowledge of your keys. In this case, you’ll need to have your private key available locally for signing transactions.

Full documentation on the distinction between keys can be found here.

Base API

The Web3 class includes a number of convenient utility functions:

Encoding and Decoding Helpers

Address Helpers

Currency Conversions

Cryptographic Hashing

web3.eth API

The most commonly used APIs for interacting with Ethereum can be found under the web3.eth namespace. As a reminder, the Examples page will demonstrate how to use several of these methods.

Fetching Data

Viewing account balances (get_balance), transactions (get_transaction), and block data (get_block) are some of the most common starting points in Web3.py.


Making Transactions

The most common use cases will be satisfied with send_transaction or the combination of sign_transaction and send_raw_transaction.


If interacting with a smart contract, a dedicated API exists. See the next section, Contracts.



The two most common use cases involving smart contracts are deploying and executing functions on a deployed contract.

Deployment requires that the contract already be compiled, with its bytecode and ABI available. This compilation step can done within Remix or one of the many contract development frameworks, such as Brownie.

Once the contract object is instantiated, calling transact on the constructor method will deploy an instance of the contract:

>>> ExampleContract = w3.eth.contract(abi=abi, bytecode=bytecode)
>>> tx_hash = ExampleContract.constructor().transact()
>>> tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
>>> tx_receipt.contractAddress

Once loaded into a Contract object, the functions of a deployed contract are available on the functions namespace:

>>> deployed_contract = w3.eth.contract(address=tx_receipt.contractAddress, abi=abi)
>>> deployed_contract.functions.myFunction(42).transact()

If you want to read data from a contract (or see the result of transaction locally, without executing it on the network), you can use the ContractFunction.call method, or the more concise ContractCaller syntax:

# Using ContractFunction.call
>>> deployed_contract.functions.getMyValue().call()

# Using ContractCaller
>>> deployed_contract.caller().getMyValue()

For more, see the full Contracts documentation.


Logs and Filters

If you want to react to new blocks being mined or specific events being emitted by a contract, you can leverage Web3.py filters.

# Use case: filter for new blocks
>>> new_filter = web3.eth.filter('latest')

# Use case: filter for contract event "MyEvent"
>>> new_filter = deployed_contract.events.MyEvent.createFilter(fromBlock='latest')

# retrieve filter results:
>>> new_filter.get_all_entries()
>>> new_filter.get_new_entries()

More complex patterns for creating filters and polling for logs can be found in the Filtering documentation.



Some basic network properties are available on the web3.net object:


ethPM allows you to package up your contracts for reuse or use contracts from another trusted registry. See the full details here.


Ethereum Name Service (ENS) provides the infrastructure for human-readable addresses. As an example, instead of 0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359, you can send funds to ethereumfoundation.eth. Web3.py has support for ENS, documented here.