Python SDK for Akash Network - interact with the blockchain and deploy and manage workloads on the decentralized cloud
Project description
Akash Python SDK
Python SDK for interacting with the Akash blockchain and deploying workloads on the decentralized cloud marketplace.
Installation
pip install akash
Prerequisites
- Python 3.8+
Quick start
Setup
from akash import AkashClient, AkashWallet
wallet = AkashWallet.from_mnemonic("your twelve word mnemonic phrase here")
print(f"Wallet address: {wallet.address}")
client = AkashClient("https://akash-rpc.polkachu.com:443")
print(f"Connected: {client.health_check()}")
Send tokens
from akash import AkashClient, AkashWallet
client = AkashClient("https://akash-rpc.polkachu.com:443")
wallet = AkashWallet.from_mnemonic("your mnemonic here")
result = client.bank.send(
wallet=wallet,
to_address="akash1recipient_address",
amount="1000000",
memo=""
)
if result.success:
print(f"Transfer successful: {result.tx_hash}")
else:
print(f"Transfer failed: {result.raw_log}")
Vote on governance proposal
from akash import AkashClient, AkashWallet
client = AkashClient("https://akash-rpc.polkachu.com:443")
wallet = AkashWallet.from_mnemonic("your mnemonic here")
result = client.governance.vote(
wallet=wallet,
proposal_id=42,
option="YES"
)
if result.success:
print(f"Vote successful: {result.tx_hash}")
else:
print(f"Vote failed: {result.raw_log}")
Deploy application
from akash import AkashClient, AkashWallet
import time
wallet = AkashWallet.from_mnemonic("your mnemonic here")
client = AkashClient("https://akash-rpc.polkachu.com:443")
print("Step 1: Ensuring certificate")
success, cert_pem, key_pem = client.cert.ensure_certificate(wallet)
if not success:
print("Certificate setup failed")
exit()
print("Step 2: Creating deployment from SDL")
sdl = '''
version: "2.0"
services:
web:
image: nginx:latest
expose:
- port: 80
as: 80
to:
- global: true
profiles:
compute:
web:
resources:
cpu:
units: 0.5
memory:
size: 128Mi
storage:
size: 1Gi
placement:
akash:
attributes:
host: akash
pricing:
web:
denom: uakt
amount: 100
deployment:
web:
akash:
profile: web
count: 1
'''
deployment = client.deployment.create_deployment(
sdl_yaml=sdl,
wallet=wallet,
deposit="500000"
)
if not deployment.success:
print(f"Deployment failed: {deployment.raw_log}")
exit()
dseq = deployment.dseq
print(f"Deployment created: DSEQ {dseq}")
print("Step 3: Waiting for bids...")
time.sleep(30)
bids = client.market.get_bids(owner=wallet.address, dseq=dseq)
if not bids:
print("No bids received")
exit()
print("Step 4: Selecting best bid and creating lease")
provider_addresses = [b['bid_id']['provider'] for b in bids]
valid_providers = client.provider.filter_valid_providers(provider_addresses)
if not valid_providers:
print("No valid providers found")
exit()
valid_bids = [b for b in bids if b['bid_id']['provider'] in valid_providers]
best_bid = min(valid_bids, key=lambda b: float(b['price']['amount']))
lease = client.market.create_lease_from_bid(wallet, best_bid)
if not lease['success']:
print(f"Lease failed: {lease['error']}")
exit()
print(f"Lease created with provider: {lease['provider_endpoint']}")
print("Step 5: Submitting manifest")
time.sleep(10)
manifest_result = client.manifest.submit_manifest(
provider_endpoint=lease['provider_endpoint'],
lease_id=lease['lease_id'],
sdl_content=sdl,
cert_pem=cert_pem,
key_pem=key_pem
)
if manifest_result.get('status') == 'success':
print("Manifest submitted successfully")
print("Your nginx application is now running")
else:
print(f"Manifest submission failed: {manifest_result.get('error')}")
Query deployment manifest
from akash import AkashClient, AkashWallet
import time
wallet = AkashWallet.from_mnemonic("your mnemonic here")
client = AkashClient("https://akash-rpc.polkachu.com:443")
success, cert_pem, key_pem = client.cert.ensure_certificate(wallet)
lease_id = {
"dseq": "12345",
"gseq": 1,
"oseq": 1
}
time.sleep(10)
result = client.manifest.get_deployment_manifest(
provider_endpoint="https://provider.example.com:8443",
lease_id=lease_id,
cert_pem=cert_pem,
key_pem=key_pem
)
if result["status"] == "success":
print(f"Provider version: {result['provider_version']}")
for group in result["manifest"]:
for service in group['services']:
print(f"Service: {service['name']}")
print(f"Image: {service['image']}")
resources = service['resources']
cpu = resources['cpu']['units']['val']
mem = int(resources['memory']['size']['val']) / (1024**2)
print(f"CPU: {cpu} millicores, Memory: {mem:.0f}Mi")
else:
print(f"Query failed: {result['error']}")
Provider discovery
from akash import AkashClient
client = AkashClient("https://akash-rpc.polkachu.com:443")
all_providers = client.provider.get_providers()
gpu_providers = client.provider.get_providers_by_capabilities(["gpu"])
high_perf_providers = client.provider.get_providers_by_capabilities(["high-performance"])
us_providers = client.provider.get_providers_by_region("us-west")
if all_providers:
provider_detail = client.provider.get_provider(all_providers[0]['owner'])
print(f"Provider: {provider_detail['host_uri']}")
print(f"Total: {len(all_providers)}, GPU: {len(gpu_providers)}")
print(f"High performance: {len(high_perf_providers)}, US West: {len(us_providers)}")
Market operations
from akash import AkashClient, AkashWallet
client = AkashClient("https://akash-rpc.polkachu.com:443")
wallet = AkashWallet.from_mnemonic("provider mnemonic here")
bids = client.market.get_bids(state="open", limit=20)
print(f"Found {len(bids)} open bids")
bid = client.market.create_bid(
wallet=wallet,
owner="akash1...",
dseq=123,
gseq=1,
oseq=1,
price="1000"
)
leases = client.market.get_leases(provider=wallet.address)
print(f"Active leases: {len(leases)}")
Core components
AkashClient
Main entry point for the SDK. Manages RPC connections and provides access to all functionality.
from akash import AkashClient
client = AkashClient("https://akash-rpc.polkachu.com:443")
with AkashClient("https://akash-rpc.polkachu.com:443") as client:
deployments = client.deployment.get_deployments()
AkashWallet
Handles wallet operations, key management, and transaction signing.
from akash import AkashWallet
wallet = AkashWallet.generate()
print(f"New wallet: {wallet.address}")
print(f"Mnemonic: {wallet.mnemonic}")
wallet = AkashWallet.from_mnemonic("your mnemonic phrase")
wallet = AkashWallet.from_private_key("your private key")
signed_tx = wallet.sign_transaction(tx_data)
client = AkashClient("https://akash-rpc.polkachu.com:443")
balance = client.bank.get_balance(wallet.address)
print(f"Balance: {balance} uakt")
Sub-clients
The client provides access to all Akash modules:
- audit: Provider audit operations
- auth: Auth operations
- authz: Authz operations
- bank: Token transfers and balance queries
- cert: Certificate management
- deployment: Deployment lifecycle management
- discovery: Discovery operations
- distribution: Staking rewards distribution
- escrow: Escrow account management
- evidence: Evidence of misbehavior submission
- feegrant: Fee grant operations
- governance: Governance proposals and voting
- ibc: Inter-blockchain communication
- inflation: Inflation parameter queries
- inventory: Inventory management
- manifest: Deployment manifest operations
- market: Bidding and lease operations
- provider: Provider discovery and filtering
- slashing: Validator slashing operations
- staking: Staking operations
Network endpoints
Testnet:
- RPC:
https://rpc.sandbox-01.aksh.pw:443 - Chain ID:
sandbox-01
Mainnet:
- RPC:
https://akash-rpc.polkachu.com:443 - Chain ID:
akashnet-2
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file akash-0.5.0.tar.gz.
File metadata
- Download URL: akash-0.5.0.tar.gz
- Upload date:
- Size: 610.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f579a31e2f8769d3305913463e3f872fa2008e7f951505a698ed61c2e4780fa2
|
|
| MD5 |
423084e4efbbfa55b87fa50443290212
|
|
| BLAKE2b-256 |
2b095c472849f974b8fcc881033bd1b4bb942482eaad1268676f4a51645a07c4
|
File details
Details for the file akash-0.5.0-py3-none-any.whl.
File metadata
- Download URL: akash-0.5.0-py3-none-any.whl
- Upload date:
- Size: 1.1 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6eaf2e44de4443365770b220e5e37c3127071d101cba8cc71009e30e6f7bd006
|
|
| MD5 |
dd29809074a8839f45d7e17d9994375c
|
|
| BLAKE2b-256 |
1424ff1c7055b4f48ad870392f8a0264d05de9f0aa862cc51a3ba783b7dd63d1
|