Skip to main content

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.

Python 3.8+ License Documentation

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


Download files

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

Source Distribution

akash-0.6.0.tar.gz (610.1 kB view details)

Uploaded Source

Built Distribution

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

akash-0.6.0-py3-none-any.whl (1.1 MB view details)

Uploaded Python 3

File details

Details for the file akash-0.6.0.tar.gz.

File metadata

  • Download URL: akash-0.6.0.tar.gz
  • Upload date:
  • Size: 610.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for akash-0.6.0.tar.gz
Algorithm Hash digest
SHA256 bd65802deaad244accf40fb1667cb240efb2f111016e6859001ee62881315f69
MD5 fd6c698947bbfceffd4f071c2da02040
BLAKE2b-256 b8b40b209a7c840c798dbdefb50ef78015daff029e3a977a9fbc6ca32241a8d2

See more details on using hashes here.

File details

Details for the file akash-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: akash-0.6.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

Hashes for akash-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3586e38569d32ee4ec120b995e09f42dee4759d5022a33ea49ef378e4c36e224
MD5 a60486c42b16ba67222387e119a22f2b
BLAKE2b-256 801e9344842dc93419d35c39bf8f15b19c9038d982cd71e0b2f9004f59259959

See more details on using hashes here.

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