> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sei.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Python Quickstart (web3.py)

> Connect to Sei from Python using web3.py — read chain data, then sign and broadcast transactions against the Sei EVM JSON-RPC.

Sei is fully EVM-compatible, so any standard Ethereum client works with it, including Python's [web3.py](https://web3py.readthedocs.io). In this guide, you connect to Sei from a Python script and read chain data without credentials. Then you sign and broadcast a transaction.

## Install

Use an isolated virtual environment:

```bash theme={"dark"}
python3 -m venv venv
source venv/bin/activate          # Windows: venv\Scripts\activate
pip install web3
```

## Reading chain data

This is the first milestone. It does not need a private key.

```python theme={"dark"}
from web3 import Web3

w3 = Web3(Web3.HTTPProvider("https://evm-rpc.sei-apis.com"))

# Any valid Sei EVM address — swap in your own
address = "0x0000000000000000000000000000000000000000"

print("Connected:", w3.is_connected())
print("Chain ID:", w3.eth.chain_id)                                  # 1329 on mainnet
print("Latest block:", w3.eth.block_number)
print("Balance (SEI):", w3.from_wei(w3.eth.get_balance(address), "ether"))
print("Nonce:", w3.eth.get_transaction_count(address))
```

**You are done when you see:**

```text theme={"dark"}
Connected: True
Chain ID: 1329
Latest block: 148203117
Balance (SEI): 12.5
Nonce: 7
```

The exact values are illustrative. Your block number will differ, and so will the balance and nonce of the queried address. The EVM chain ID is always `1329` on Sei Mainnet and `1328` on Sei Testnet.

## Try it live

`web3.py` sends plain JSON-RPC requests internally. These snippets send the same reads to Sei Mainnet, so you do not need Python to run them.

w3.eth.chain\_id

Sei Mainnet

Sei Mainnet EVM chain ID. It decodes to 1329.

Request

<pre />

w3.eth.block\_number

Sei Mainnet

Latest committed block on Sei Mainnet.

Request

<pre />

w3.eth.get\_balance(address)

Sei Mainnet

Wei balance of the example address. You can replace the example address with your own. w3.from\_wei(…, 'ether') converts the balance to SEI.

Request

<pre />

## Sending a transaction

This next step requires a funded account. Get testnet SEI from the [faucet](https://docs.sei.io/learn/faucet.md). Then build the transaction, **sign it locally**, and broadcast it with `eth_sendRawTransaction`. Public RPC endpoints do not manage accounts, so you sign the transaction yourself instead of relying on node-managed accounts.

```python theme={"dark"}
import os
from web3 import Web3

# Sei Testnet
w3 = Web3(Web3.HTTPProvider("https://evm-rpc-testnet.sei-apis.com"))

account = w3.eth.account.from_key(os.environ["SEI_PRIVATE_KEY"])

tx = {
    "to": "0xRecipient",
    "value": w3.to_wei(0.001, "ether"),
    "nonce": w3.eth.get_transaction_count(account.address),
    "chainId": w3.eth.chain_id,
    "type": 2,  # EIP-1559
    "maxPriorityFeePerGas": w3.to_wei(1, "gwei"),
    "maxFeePerGas": w3.eth.gas_price * 2 + w3.to_wei(1, "gwei"),
}
tx["gas"] = w3.eth.estimate_gas(tx)  # always estimate rather than hard-coding

signed = w3.eth.account.sign_transaction(tx, account.key)
tx_hash = w3.eth.send_raw_transaction(signed.raw_transaction)

receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
print("Mined in block:", receipt.blockNumber)  # final immediately — Sei has instant finality
```

> [!WARNING]
>
> Never hard-code or commit a private key. Load it from an environment variable or a secrets manager. Use a dedicated throwaway key that holds only the funds you need.

> [!NOTE]
>
> In web3.py v7+, the attribute name is `signed.raw_transaction`. In web3.py v6, it is `signed.rawTransaction`.

## Reading a contract

```python theme={"dark"}
abi = [{
    "constant": True,
    "inputs": [{"name": "owner", "type": "address"}],
    "name": "balanceOf",
    "outputs": [{"name": "", "type": "uint256"}],
    "stateMutability": "view",
    "type": "function",
}]

token = w3.eth.contract(address="0xTokenAddress", abi=abi)
print(token.functions.balanceOf(address).call())
```

## Next steps

* [viem Quickstart](https://docs.sei.io/evm/evm-parity/examples/viem-quickstart.md): the TypeScript and Node.js equivalent
* [ethers v6 Quickstart](https://docs.sei.io/evm/evm-parity/examples/ethers-quickstart.md): TypeScript with ethers
* [Network information](https://docs.sei.io/evm/networks.md): RPC endpoints, chain IDs, and explorers
* [Faucet](https://docs.sei.io/learn/faucet.md): get testnet SEI


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.