Metadata-Version: 2.4
Name: akash
Version: 0.5.0
Summary: Python SDK for Akash Network - interact with the blockchain and deploy and manage workloads on the decentralized cloud
Author-email: Akash community <contact@cosmosrescue.com>
License: Apache-2.0
Project-URL: Homepage, https://github.com/cosmosrescue/akash-py
Project-URL: Documentation, https://akash-py.cosmosrescue.com
Project-URL: Repository, https://github.com/cosmosrescue/akash-py
Project-URL: Bug Tracker, https://github.com/cosmosrescue/akash-py/issues
Project-URL: Akash Network, https://akash.network/
Project-URL: Akash Docs, https://docs.akash.network/
Keywords: akash,blockchain,kubernetes,cloud,decentralized,deployment,docker,grpc,cosmos,sdk
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: System :: Distributed Computing
Classifier: Topic :: System :: Networking
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: grpcio>=1.50.0
Requires-Dist: grpclib>=0.4.0
Requires-Dist: protobuf>=4.21.0
Requires-Dist: googleapis-common-protos>=1.57.0
Requires-Dist: ecdsa>=0.18.0
Requires-Dist: bech32>=1.2.0
Requires-Dist: requests>=2.20.0
Requires-Dist: mnemonic>=0.20
Requires-Dist: pycryptodome>=3.15.0
Requires-Dist: cryptography>=41.0.0
Requires-Dist: pyyaml>=5.1.0
Requires-Dist: websocket-client>=1.0.0
Provides-Extra: dev
Requires-Dist: pytest>=6.0; extra == "dev"
Requires-Dist: pytest-cov>=2.10; extra == "dev"
Requires-Dist: black>=22.0; extra == "dev"
Requires-Dist: flake8>=4.0; extra == "dev"
Requires-Dist: mypy>=0.900; extra == "dev"
Requires-Dist: build>=0.8.0; extra == "dev"
Requires-Dist: twine>=4.0.0; extra == "dev"
Provides-Extra: docs
Requires-Dist: sphinx>=4.0; extra == "docs"
Requires-Dist: sphinx-rtd-theme>=1.0; extra == "docs"
Requires-Dist: myst-parser>=0.18; extra == "docs"
Dynamic: license-file

# Akash Python SDK

Python SDK for interacting with the Akash blockchain and deploying workloads on the decentralized cloud
marketplace.

[![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE)
[![Documentation](https://img.shields.io/badge/docs-akash--py.cosmosrescue.com-blue.svg)](https://akash-py.cosmosrescue.com/)

## Installation

```bash
pip install akash
```

### Prerequisites

- Python 3.8+

## Quick start

### Setup

```python
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

```python
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

```python
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

```python
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

```python
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

```python
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

```python
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.

```python
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.

```python
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

- [This SDK documentation](https://akash-py.cosmosrescue.com/)
- [Akash documentation](https://docs.akash.network/)
- [SDL specification](https://akash.network/docs/getting-started/stack-definition-language)
