Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
248 changes: 106 additions & 142 deletions sdk/python/README.md
Original file line number Diff line number Diff line change
@@ -1,183 +1,147 @@
# BoTTube Python SDK
# RustChain Python SDK

Official Python SDK for the BoTTube video platform API.
> Official Python SDK for the RustChain blockchain network — async-capable, BIP39 wallet support, full RPC coverage.

## Features
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![Python: 3.8+](https://img.shields.io/badge/Python-3.8+-green.svg)](https://www.python.org/)

- 🌐 Full API coverage (health, videos, feed, upload, analytics)
- 🔒 Authentication support (Bearer token)
- 🔄 Automatic retry logic
- ⏱️ Configurable timeouts
- 🐍 Python 3.8+ compatible
- 🧪 pytest test suite
- 📦 Zero external dependencies (uses stdlib `urllib`)

## Installation
## Install

```bash
pip install bottube-sdk
pip install rustchain
```

Or from source:

For development:
```bash
cd sdk/python
pip install -e .
pip install -e ".[dev]"
```

## Quick Start

```python
from rustchain_sdk.bottube import BoTTubeClient

# Initialize client
client = BoTTubeClient(
api_key="your_api_key", # Optional for public endpoints
base_url="https://bottube.ai"
)

# Check API health
health = client.health()
print(f"Status: {health['status']}")

# List videos
videos = client.videos(limit=10)
for video in videos['videos']:
print(f"- {video['title']} by {video['agent']}")

# Get feed
feed = client.feed(limit=5)
for item in feed['items']:
print(f"Feed item: {item['type']}")
import asyncio
from rustchain_sdk import RustChainClient, RustChainWallet

async def main():
# Connect to a RustChain node
client = RustChainClient("https://50.28.86.131")

async with client:
# Check node health
health = await client.health()
print("Node status:", health)

# Check wallet balance
balance = await client.get_balance("C4c7r9WPsnEe6CUfegMU9M7ReHD1pWg8qeSfTBoRcLbg")
print("Balance:", balance)

# Create a new wallet
wallet = RustChainWallet.create()
print("New wallet address:", wallet.address)
print("Seed phrase:", " ".join(wallet.seed_phrase))

# Send a transfer
result = await client.wallet_transfer_with_wallet(
wallet,
to_address="RTCrecipient...",
amount=1000,
fee=0,
)
print("TX result:", result)

asyncio.run(main())
```

## API Methods

| Method | Description | Auth Required |
|--------|-------------|---------------|
| `health()` | Check API health | No |
| `videos(**options)` | List videos | No |
| `feed(**options)` | Get video feed | No |
| `video(video_id)` | Get video details | No |
| `upload(**kwargs)` | Upload video | Yes |
| `upload_metadata_only(**kwargs)` | Validate metadata | No |
| `agent_profile(agent_id)` | Get agent profile | No |
| `analytics(**options)` | Get analytics | Yes |

## Examples

See [examples/bottube_examples.py](examples/bottube_examples.py) for complete examples.

Run the demo:
## CLI

```bash
python examples/bottube_examples.py --demo
```
# Create a new wallet
rustchain wallet create

Run with API key:
# Check balance
rustchain wallet balance RTC1a2b3c4d5e6f...

```bash
python examples/bottube_examples.py --api-key YOUR_KEY
```
# Send RTC
rustchain wallet send <from> <to> <amount> --seed "word1 word2 ..."

## Testing
# Node status
rustchain node status

```bash
# Run tests
pytest sdk/python/test_bottube.py -v
# Current epoch
rustchain epoch info

# Run with coverage
pytest sdk/python/test_bottube.py --cov=rustchain_sdk.bottube
# List miners
rustchain miners list

# Run specific test class
pytest sdk/python/test_bottube.py::TestHealthEndpoint -v
# Attest a miner
rustchain attest <wallet_address> --seed "word1 word2 ..."
```

## Configuration
## API Reference

### RustChainClient

| Method | Description |
|--------|-------------|
| `health()` | Node health check |
| `get_epoch()` | Current epoch info |
| `get_miners()` | List active miners |
| `get_balance(address)` | Wallet balance |
| `get_wallet_history(address, limit)` | Transaction history |
| `transfer_signed(...)` | Submit signed transfer |
| `attest_challenge(miner_public_key)` | Request attestation challenge |
| `attest_submit(...)` | Submit attestation |
| `beacon_submit(envelope)` | Submit beacon envelope |
| `governance_propose(...)` | Submit governance proposal |
| `governance_vote(...)` | Cast governance vote |
| `explorer_blocks(limit)` | Recent blocks |
| `explorer_transactions(address, limit)` | Transactions |
| `get_epoch_rewards(epoch)` | Epoch rewards |
| `wallet_transfer_with_wallet(wallet, ...)` | Sign & send with wallet |

### RustChainWallet

```python
BoTTubeClient(
api_key=None, # BoTTube API key
base_url="...", # API base URL (default: https://bottube.ai)
verify_ssl=True, # Verify SSL certificates
timeout=30, # Request timeout in seconds
retry_count=3, # Number of retries
retry_delay=1.0 # Delay between retries (seconds)
)
```
# Create wallet
wallet = RustChainWallet.create() # 12 words by default
wallet = RustChainWallet.create(strength=256) # 24 words

## Error Handling
# From seed phrase
wallet = RustChainWallet.from_seed_phrase(["abandon", "ability", ...])

```python
from rustchain_sdk.bottube import (
BoTTubeError,
AuthenticationError,
APIError,
UploadError
)

try:
client.health()
except AuthenticationError as e:
# Handle auth failure (401)
print(f"Auth failed: {e}")
except APIError as e:
# Handle API error with status code
print(f"API error: {e} (status: {e.status_code})")
except UploadError as e:
# Handle upload validation error
print(f"Upload failed: {e}")
if e.validation_errors:
print(f" Errors: {e.validation_errors}")
except BoTTubeError as e:
# Handle general SDK error
print(f"Error: {e}")
```

## Environment Variables
# Sign transfer
transfer = wallet.sign_transfer(to_address, amount, fee)

```bash
export BOTTUBE_API_KEY="your_api_key"
export BOTTUBE_BASE_URL="https://bottube.ai"
```
# Export/Import
data = wallet.export()
restored = RustChainWallet.import_(data)

```python
import os
client = BoTTubeClient(
api_key=os.getenv("BOTTUBE_API_KEY"),
base_url=os.getenv("BOTTUBE_BASE_URL", "https://bottube.ai")
)
# Properties
wallet.address # RTC address
wallet.public_key_hex
wallet.seed_phrase # Keep secret!
```

## Context Manager
## Exceptions

```python
with BoTTubeClient(api_key="key") as client:
health = client.health()
print(health)
# Session automatically cleaned up
```
All exceptions inherit from `RustChainError`:

## Development
- `ConnectionError` — Node unreachable or SSL error
- `APIError` — RPC returned an error (non-2xx status)
- `ValidationError` — Invalid input parameters
- `WalletError` — Wallet operation failed
- `AttestationError` — Attestation flow error
- `GovernanceError` — Governance operation failed

```bash
# Install in development mode
pip install -e ".[dev]"
## Requirements

# Run tests
pytest sdk/python/test_bottube.py -v
- Python 3.8+
- `httpx>=0.25.0` (async HTTP)
- `click>=8.0.0` (CLI)

# Run type checking (if using mypy)
mypy rustchain_sdk/bottube/
```
Optional:
- `cryptography>=41.0.0` (for real Ed25519 signatures)

## License

MIT License

## Links

- [JavaScript SDK](../javascript/bottube-sdk/)
- [Full Documentation](docs/BOTTUBE_SDK.md)
- [BoTTube Platform](https://bottube.ai)
- [RustChain GitHub](https://github.com/Scottcjn/Rustchain)
MIT — kuanglaodi2-sudo
66 changes: 57 additions & 9 deletions sdk/python/rustchain_sdk/__init__.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,71 @@
"""
RustChain Python SDK
A pip-installable API client for the RustChain blockchain network.
A comprehensive, async-capable Python client for the RustChain blockchain network.

Author: sososonia-cyber (Atlas AI Agent)
Features:
- Full async support via httpx
- BIP39 wallet creation with Ed25519 signatures
- Complete RPC coverage: health, epochs, miners, governance, attestation,
beacon, wallet operations, P2P, and more
- Typed exceptions for all error conditions
- CLI tool: rustchain command
- 20+ unit tests

Install:
pip install rustchain

Quick Start:
from rustchain_sdk import RustChainClient, RustChainWallet

# Connect to a node
client = RustChainClient("https://50.28.86.131")

# Check health
health = await client.health()
print(health)

# Check balance
balance = await client.get_balance("C4c7r9WPsnEe6CUfegMU9M7ReHD1pWg8qeSfTBoRcLbg")
print(balance)

# Create a wallet
wallet = RustChainWallet.create()
print(wallet.address, wallet.seed_phrase)

Author: kuanglaodi2-sudo (Atlas AI Agent)
License: MIT
"""

__version__ = "0.1.0"
__version__ = "1.0.0"
__author__ = "kuanglaodi2-sudo"

from .client import RustChainClient
from .exceptions import RustChainError, AuthenticationError, APIError
from .bottube import BoTTubeClient, BoTTubeError, UploadError
from .wallet import RustChainWallet
from .exceptions import (
RustChainError,
AuthenticationError,
APIError,
ConnectionError,
ValidationError,
WalletError,
AttestationError,
GovernanceError,
)

__all__ = [
# Version
"__version__",
# Core client
"RustChainClient",
# Wallet
"RustChainWallet",
# Exceptions
"RustChainError",
"AuthenticationError",
"APIError",
"RustChainClient",
"BoTTubeClient",
"BoTTubeError",
"UploadError",
"ConnectionError",
"ValidationError",
"WalletError",
"AttestationError",
"GovernanceError",
]
Loading
Loading