# Python SDK

### Overview

If you want to use Python to connect with a blockchain node, it's possible to use vanilla Python but several convenience libraries exist within the ecosystem that make this much easier. With these libraries, developers can write intuitive, one-line methods to initialize JSON-RPC requests (under the hood) that interact with blockchain.

**Python SDKs** provide powerful and easy-to-use interfaces for interacting with EVM (Ethereum Virtual Machine) compatible blockchains like Ethereum, Polygon, BSC, Avalanche, and others.

### Main Libraries:

#### 1. [**Web3.py**](http://Web3.py) (Recommended)

* Official Python library for Ethereum
* Comprehensive API with extensive documentation
* Built-in support for smart contracts and transactions
* Active community and regular updates

#### 2. **Brownie**

* Development framework built on [Web3.py](http://Web3.py)
* Integrated testing and deployment tools
* Smart contract compilation and management
* Great for DeFi and complex dApp development

#### 3. **Ape Framework**

* Modern Python framework for Ethereum development
* Plugin-based architecture
* Advanced testing capabilities
* Type hints and modern Python features

### Quick Example

Here's a simple example using [**Web3.py**](http://Web3.py) to check an account balance:

```
from web3 import Web3

# Connect to network (X1EcoChain Nubica Testnet)
w3 = Web3(Web3.HTTPProvider('https://nubica-rpc.x1eco.com'))

# Check connection
if w3.is_connected():
    print("Connected to X1EcoChain network")

    # Check X1 balance
    address = '<some address>'
    balance_wei = w3.eth.get_balance(address)

    # Convert from wei to X1
    balance_eth = w3.from_wei(balance_wei, 'ether')
    print(f"Balance: {balance_eth} X1")
else:
    print("Failed to connect")
```

***

### Next Steps:

* Set up wallet connections and private key management
* Interact with smart contracts
* Handle transactions and events
* Implement error handling and gas optimization
* Use async/await for better performance


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://x1ecochain.gitbook.io/x1-ecochain-tech-whitepaper/development-environment/python-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
