> For the complete documentation index, see [llms.txt](https://docs.watchdata.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.watchdata.io/web3/web3-sdk/web3.py.md).

# Web3.py

## Web3.py overview

### Adding web3.py <a href="#id-2f9b" id="id-2f9b"></a>

**Note:** We need Python version >=3.5.3 and install web3.py using pip3 install web3.

Python and other library versions cause common installation problems. So if you face any problems, try [setting up a virtual environment and troubleshooting](https://web3py.readthedocs.io/en/stable/troubleshooting.html) the installation of web3.py.

### Using web3.py <a href="#d3fc" id="d3fc"></a>

We will use web3.py to get the last Ethereum block number. To do this we will use the code below.

```python
from web3 import Web3
watchdata_url = 'YOUR_ETHEREUM_NODE_URL'
w3 = Web3(Web3.HTTPProvider(watchdata_url))
last_block_number = w3.eth.block_number
print(f'last block number in eth = {last_block_number}')
```

So go ahead and replace \`**YOUR\_ETHEREUM\_NODE\_URL**\` with the http provider from the instructions above.

![](https://miro.medium.com/max/1400/0*IdOl9gFkBi5WhnTP)

In this code snippet, we import the web3.py library, declare a watchdata\_url variable to which we assign the URL of our watchdata node in Ethereum. And then we create an instance of the web3 class with our watchdata\_url.

![](https://miro.medium.com/max/1400/0*tI0_D0v840-I7DCB)

In this code snippet, we retrieve the last Ethereum block number using the w3.eth.blockNumber API and display it.

That’s it, you are connected via the Ethereum network using Python. You can also learn more about the [web3.py](https://web3py.readthedocs.io/en/stable/index.html) APIs for building complicated applications on Ethereum.
