> For the complete documentation index, see [llms.txt](https://docs.tajirchain.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tajirchain.com/developers/smart-contract-interaction/web3.py-guide.md).

# web3.py Guide

#### **Install**

```
pip install web3
```

#### **Connect to Tajir**

```python
from web3 import Web3

w3 = Web3(Web3.HTTPProvider("https://rpc.testnet.tajirchain.com"))
```

#### **Read Data: Get Balance**

```python
balance = w3.eth.get_balance("0xYourAddress")
print(w3.from_wei(balance, 'ether'))
```

#### **Write Data: Send Transaction**

```python
# Sign the transaction using your secure wallet or signing service.
# Never hardcode or expose private keys in your application.

signed_tx = secure_sign_transaction(tx)
tx_hash = w3.eth.send_raw_transaction(signed_tx)
print(tx_hash.hex())
```

**Security Note: Never store or hardcode private keys in your application. Always use a secure wallet, signer, or key management solution.**

#### **Call a Contract Function**

```python
contract = w3.eth.contract(address=CONTRACT_ADDRESS, abi=ABI)
print(contract.functions.myMethod().call())
```
