Skip to main content

Python SDK for XAI Blockchain - AI compute pooling and governance

Project description

XAI Blockchain SDK for Python

A lightweight Python SDK for interacting with the XAI blockchain platform. Supports wallet operations, transactions, governance proposals, AI compute task matching, and more.

Installation

pip install xai-blockchain-sdk

For development:

pip install xai-blockchain-sdk[dev]

Quick Start

from xai_blockchain_sdk import XAIClient

# Connect to testnet
client = XAIClient(base_url="https://testnet-rpc.xaiblockchain.com")

# Get blockchain stats
stats = client.blockchain.get_stats()
print(f"Chain height: {stats.chain_height}")
print(f"Network: {stats.network}")

# Check wallet balance
balance = client.wallet.get_balance("xai1yourawlletaddress...")
print(f"Balance: {balance.balance_xai} XAI")

Features

Blockchain Operations

# Get blockchain statistics
stats = client.blockchain.get_stats()

# Get a specific block
block = client.blockchain.get_block(100)
print(f"Block {block.index}: {block.hash}")

# List recent blocks
result = client.blockchain.list_blocks(limit=10)
for block in result["blocks"]:
    print(f"Block {block.index}: {len(block.transactions)} transactions")

# Check node health
health = client.blockchain.get_health()

Wallet Operations

# Get wallet balance
balance = client.wallet.get_balance("xai1...")
print(f"Available: {balance.available_balance}")
print(f"Locked: {balance.locked_balance}")

# Get transaction history
history = client.wallet.get_history("xai1...", limit=20)

Transactions

# Get transaction details
tx = client.transaction.get("txhash...")
print(f"Status: {tx.status}")
print(f"Confirmations: {tx.confirmations}")

# Get pending transactions (mempool)
pending = client.transaction.get_pending(limit=10)

Governance

# List all proposals
proposals = client.governance.list_proposals()

# Filter by status
active = client.governance.list_proposals(status="active")

# Get specific proposal
proposal = client.governance.get_proposal("proposal-id")

# Get governance statistics
gov_stats = client.governance.get_stats()
print(f"Active proposals: {gov_stats['proposals']['active']}")

# Check voting power
power = client.governance.get_voting_power("xai1...")

AI Compute

# Get available AI models
models = client.ai.list_models()
for name, info in models.items():
    print(f"{name}: quality={info['quality_score']}, speed={info['speed_score']}")

# Get supported task types
task_types = client.ai.list_task_types()

# Match a task to the best model
match = client.ai.match_task(
    task_type="security_audit",
    complexity="complex",
    priority="high"
)
print(f"Recommended model: {match['recommended_model']}")

# Get AI compute statistics
ai_stats = client.ai.get_stats()
print(f"Available models: {ai_stats['available_models']}")

Mining

# Get mining status
status = client.mining.get_status()
print(f"Mining: {status.mining}")
print(f"Hashrate: {status.hashrate}")

Trading/Exchange

# Get exchange rates
rates = client.trading.get_rates()

# List available pairs
pairs = client.trading.list_pairs()

# Get order book
orderbook = client.trading.get_order_book("XAI/USDT")

Configuration

Custom Base URL

# Testnet (default)
client = XAIClient(base_url="https://testnet-rpc.xaiblockchain.com")

# Mainnet (when available)
client = XAIClient(base_url="https://rpc.xaiblockchain.com")

# Local development
client = XAIClient(base_url="http://localhost:12570")

API Key Authentication

client = XAIClient(
    base_url="https://testnet-rpc.xaiblockchain.com",
    api_key="your-api-key"
)

Request Timeout

client = XAIClient(
    base_url="https://testnet-rpc.xaiblockchain.com",
    timeout=30  # seconds
)

Retry Configuration

client = XAIClient(
    base_url="https://testnet-rpc.xaiblockchain.com",
    max_retries=3,
    retry_delay=1.0  # seconds
)

Error Handling

from xai_blockchain_sdk import (
    XAIClient,
    XAIError,
    NetworkError,
    ValidationError,
    AuthenticationError,
    RateLimitError,
)

client = XAIClient(base_url="https://testnet-rpc.xaiblockchain.com")

try:
    balance = client.wallet.get_balance("invalid-address")
except ValidationError as e:
    print(f"Invalid input: {e}")
except NetworkError as e:
    print(f"Network issue: {e}")
except AuthenticationError as e:
    print(f"Auth failed: {e}")
except RateLimitError as e:
    print(f"Rate limited: {e}")
except XAIError as e:
    print(f"XAI error: {e}")

Data Models

The SDK provides typed data models for all responses:

  • Wallet - Wallet information
  • Balance - Wallet balance details
  • Transaction - Transaction data
  • Block - Block information
  • BlockchainStats - Network statistics
  • Proposal - Governance proposal
  • MiningStatus - Mining information
  • TradeOrder - Exchange order
from xai_blockchain_sdk import Block, Transaction, TransactionStatus

# Models are dataclasses with type hints
block: Block = client.blockchain.get_block(100)
print(block.index)  # int
print(block.hash)   # str
print(block.transactions)  # list

Requirements

  • Python 3.9+
  • requests >= 2.28.0

Links

License

Apache License 2.0 - see LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xai_blockchain_sdk-1.0.0.tar.gz (26.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xai_blockchain_sdk-1.0.0-py3-none-any.whl (31.0 kB view details)

Uploaded Python 3

File details

Details for the file xai_blockchain_sdk-1.0.0.tar.gz.

File metadata

  • Download URL: xai_blockchain_sdk-1.0.0.tar.gz
  • Upload date:
  • Size: 26.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for xai_blockchain_sdk-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b500b9d1d4700a88473a2873dcebb456fa72bb513c285594c3a503ff7bc15fc4
MD5 33fbab888e370ee5f7aa1fe03224ce14
BLAKE2b-256 6e8d02eeffbd7e2554cd69cae7fbfbde9ee2ed1b45eddc1ba80a7907cb1165fe

See more details on using hashes here.

Provenance

The following attestation bundles were made for xai_blockchain_sdk-1.0.0.tar.gz:

Publisher: publish-sdk.yml on xai-blockchain/xai

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file xai_blockchain_sdk-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for xai_blockchain_sdk-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 25aa032cbeb6e0fc0bdd63ec19e48be005515b227e53a5586ea4375cf99ccecc
MD5 7819e5b308f2b7d2f295eb8f894a2d17
BLAKE2b-256 c435174465ca24e3b8f877222a70cf98d814b78fdb48ae94c0751e56e773d6ab

See more details on using hashes here.

Provenance

The following attestation bundles were made for xai_blockchain_sdk-1.0.0-py3-none-any.whl:

Publisher: publish-sdk.yml on xai-blockchain/xai

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page