AIBlock Python SDK
Python SDK for interacting with the AIBlock blockchain. This SDK provides a simple interface for wallet operations and blockchain queries.
Installation
pip install aiblock
Quick Start
Basic Blockchain Queries
from aiblock.blockchain import BlockchainClient
# Initialize blockchain client
client = BlockchainClient(
storage_host='https://storage.aiblock.dev',
mempool_host='https://mempool.aiblock.dev'
)
# Query blockchain
latest_block = client.get_latest_block()
if latest_block.is_ok:
print(f"Latest block: {latest_block.get_ok()['content']['block_num']}")
# Get specific block by number
block = client.get_block_by_num(1)
if block.is_ok:
print(f"Block 1: {block.get_ok()['content']}")
# Get blockchain entry by hash
entry = client.get_blockchain_entry('some_hash')
# Get transaction by hash
transaction = client.get_transaction_by_hash('tx_hash')
# Get multiple transactions
transactions = client.fetch_transactions(['hash1', 'hash2'])
# Get supply information (requires mempool host)
total_supply = client.get_total_supply()
issued_supply = client.get_issued_supply()
Wallet Operations
from aiblock.wallet import Wallet
# Create wallet
wallet = Wallet()
# Generate seed phrase
seed_phrase = wallet.generate_seed_phrase()
print(f"Seed phrase: {seed_phrase}")
# Initialize wallet from seed
config = {
'passphrase': 'your-secure-passphrase',
'mempoolHost': 'https://mempool.aiblock.dev',
'storageHost': 'https://storage.aiblock.dev',
'valenceHost': 'https://valence.aiblock.dev'
}
result = wallet.from_seed(seed_phrase, config)
if result.is_ok:
print(f"Wallet address: {wallet.get_address()}")
else:
print(result.error, result.error_message)
Features
Blockchain Client
- get_latest_block() - Get the latest block information
- get_block_by_num(block_num) - Get a specific block by number
- get_blockchain_entry(hash) - Get blockchain entry by hash
- get_transaction_by_hash(tx_hash) - Get transaction details
- fetch_transactions(tx_hashes) - Get multiple transactions
- get_total_supply() - Get total token supply
- get_issued_supply() - Get issued token supply
Wallet Operations
- Generate and manage seed phrases
- Create and manage keypairs
- Create and sign transactions
- Create item assets
- Check balances
- 2WayPayment protocol support
Configuration
The SDK uses environment variables for configuration. Create a .env file:
AIBLOCK_PASSPHRASE="your-secure-passphrase"
AIBLOCK_STORAGE_HOST="https://storage.aiblock.dev"
AIBLOCK_MEMPOOL_HOST="https://mempool.aiblock.dev"
AIBLOCK_VALENCE_HOST="https://valence.aiblock.dev"
Error Handling
All methods return IResult objects with proper error handling:
result = client.get_latest_block()
if result.is_ok:
data = result.get_ok()
print(f"Success: {data}")
else:
print(result.error, result.error_message)
Development
- Clone the repository
- Install uv (https://docs.astral.sh/uv/)
- Run tests:
uv pip install -q pytest requests-mock && uv run pytest -q
All 68 tests pass, ensuring reliability and compatibility.
Documentation
- API Reference - Complete API documentation
- Examples - Usage examples and patterns
- Troubleshooting - Common issues and solutions
Contributing
We welcome contributions! Please feel free to submit a Pull Request.
License
MIT License
Metadata
Release files for aiblock 0.2.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| aiblock-0.2.9.tar.gz | 70.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aiblock-0.2.9-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 103.5 kB
Release files / aiblock-0.2.9.tar.gz
| Download URL | aiblock-0.2.9.tar.gz |
|---|---|
| Size | 70.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
55314bdc83583014934dc0520cab9ea4aea4a6e4fb1e8b6337e1600479fd83bc
|
|
BLAKE2b-256 checksum How to use checksums |
7b5888ab806650fb1aae09aa316f882a05a22b9ca1d3d406055a81582fb6552b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / aiblock-0.2.9-py3-none-any.whl
| Download URL | aiblock-0.2.9-py3-none-any.whl |
|---|---|
| Size | 33.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
18a4c08835b59435e56d4efff006ed4f4478cfb7374e12e72c2d6cc1137fd90e
|
|
BLAKE2b-256 checksum How to use checksums |
cbf89bada0eb8526290622810ec1bd109af0e53e866162f5d496a633c30d2bb2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|