Skip to main content

Autonomi client API

Project description

Autonomi Python Bindings

The Autonomi client library provides Python bindings for easy integration with Python applications.

Installation

We recommend using uv for Python environment management:

Make sure you have installed:

  • Python
  • uv

Quick Start

# make sure you are in the autonomi directory
cd autonomi/

# make a virtual environment
uv venv
source .venv/bin/activate
uv sync
maturin develop --uv

# Then you can test with pytest
pytest tests/python/test_bindings.py

# or you can run the examples or your own scripts!
python python/examples/autonomi_pointers.py 
from autonomi_client import *

Client, Wallet, PaymentOption *

# Initialize a wallet with a private key
wallet = Wallet.new_from_private_key(Network(True),
                                     "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80")
print(f"Wallet address: {wallet.address()}")
print(f"Wallet balance: {await wallet.balance()}")

# Connect to the network
client = await Client.init()

# Create payment option using the wallet
payment = PaymentOption.wallet(wallet)

# Upload some data
data = b"Hello, Safe Network!"
[cost, addr] = await client.data_put_public(data, payment)
print(f"Data uploaded to address: {addr}")

# Download the data back
downloaded = await client.data_get_public(addr)
print(f"Downloaded data: {downloaded.decode()}")

API Reference

Client

The main interface to interact with the Autonomi network.

Connection Methods

  • connect(peers: List[str]) -> Client
    • Connect to network nodes
    • peers: List of multiaddresses for initial network nodes

Data Operations

  • data_put_public(data: bytes, payment: PaymentOption) -> str

    • Upload public data to the network
    • Returns address where data is stored
  • data_get_public(addr: str) -> bytes

    • Download public data from the network
    • addr: Address returned from data_put_public
  • data_put(data: bytes, payment: PaymentOption) -> DataMapChunk

    • Store private (encrypted) data
    • Returns access information for later retrieval
  • data_get(access: DataMapChunk) -> bytes

    • Retrieve private data
    • access: DataMapChunk from previous data_put

Pointer Operations

  • pointer_get(address: str) -> Pointer

    • Retrieve pointer from network
    • address: Hex-encoded pointer address
  • pointer_put(pointer: Pointer, wallet: Wallet)

    • Store pointer on network
    • Requires payment via wallet
  • pointer_cost(key: VaultSecretKey) -> str

    • Calculate pointer storage cost
    • Returns cost in atto tokens

Scratchpad

Manage mutable encrypted data on the network.

Scratchpad Class

  • Scratchpad(owner: SecretKey, data_encoding: int, unencrypted_data: bytes, counter: int) -> Scratchpad

    • Create a new scratchpad instance
    • owner: Secret key for encrypting and signing
    • data_encoding: Custom value to identify data type (app-defined)
    • unencrypted_data: Raw data to be encrypted
    • counter: Version counter for tracking updates
  • address() -> ScratchpadAddress

    • Get the address of the scratchpad
  • decrypt_data(sk: SecretKey) -> bytes

    • Decrypt the data using the given secret key

Client Methods for Scratchpad

  • scratchpad_get_from_public_key(public_key: PublicKey) -> Scratchpad

    • Retrieve a scratchpad using owner's public key
  • scratchpad_get(addr: ScratchpadAddress) -> Scratchpad

    • Retrieve a scratchpad by its address
  • scratchpad_check_existance(addr: ScratchpadAddress) -> bool

    • Check if a scratchpad exists on the network
  • scratchpad_put(scratchpad: Scratchpad, payment: PaymentOption) -> Tuple[str, ScratchpadAddress]

    • Store a scratchpad on the network
    • Returns (cost, address)

scratchpad_create(owner: SecretKey, content_type: int, initial_data: bytes, payment: PaymentOption) -> Tuple[str, ScratchpadAddress]

  • Create a new scratchpad with a counter of 0

  • Returns (cost, address)

  • scratchpad_update(owner: SecretKey, content_type: int, data: bytes) -> None

    • Update an existing scratchpad
    • Note: Counter is automatically incremented by 1 during update
    • The scratchpad must exist before updating
  • scratchpad_cost(public_key: PublicKey) -> str

    • Calculate the cost to store a scratchpad
    • Returns cost in atto tokens

Important Notes on Scratchpad Counter

  1. When creating a new scratchpad with scratchpad_create, the counter starts at 0
  2. When updating with scratchpad_update, the counter is automatically incremented
  3. If you need to set a specific counter value, create a new Scratchpad instance and use scratchpad_put
  4. Only the scratchpad with the highest counter is kept on the network when there are conflicts

Vault Operations

  • vault_cost(key: VaultSecretKey) -> str

    • Calculate vault storage cost
  • write_bytes_to_vault(data: bytes, payment: PaymentOption, key: VaultSecretKey, content_type: int) -> str

    • Write data to vault
    • Returns vault address
  • fetch_and_decrypt_vault(key: VaultSecretKey) -> Tuple[bytes, int]

    • Retrieve vault data
    • Returns (data, content_type)
  • get_user_data_from_vault(key: VaultSecretKey) -> UserData

    • Get user data from vault
  • put_user_data_to_vault(key: VaultSecretKey, payment: PaymentOption, user_data: UserData) -> str

    • Store user data in vault
    • Returns vault address

Wallet

Ethereum wallet management for payments.

  • new(private_key: str) -> Wallet

    • Create wallet from private key
    • private_key: 64-char hex string without '0x' prefix
  • address() -> str

    • Get wallet's Ethereum address
  • balance() -> str

    • Get wallet's token balance
  • balance_of_gas() -> str

    • Get wallet's gas balance
  • set_transaction_config(config: TransactionConfig)

    • Set the transaction config for the wallet (see TransactionConfig)

TransactionConfig

Transaction configuration for wallets.

config = TransactionConfig(max_fee_per_gas=MaxFeePerGas.limited_auto(200000000))

MaxFeePerGas

Control the maximum fee per gas (gas price bid) for transactions:

  • MaxFeePerGas.auto(): Use current network gas price. No gas price limit. Use with caution.

    MaxFeePerGas.auto()
    
  • MaxFeePerGas.limited_auto(limit): Use current gas price with an upper limit. This is the recommended preset.

    # Limit to 0.2 gwei
    MaxFeePerGas.limited_auto(200000000)
    
  • MaxFeePerGas.unlimited(): No gas price limit. Use with caution.

    MaxFeePerGas.unlimited()
    
  • MaxFeePerGas.custom(wei_amount): Set exact gas price in wei.

    # Set to exactly 0.2 gwei
    MaxFeePerGas.custom(200000000)
    

PaymentOption

Configure payment methods.

  • wallet(wallet: Wallet) -> PaymentOption
    • Create payment option from wallet

Pointer

Handle network pointers for referencing data.

  • new(target: str) -> Pointer

    • Create new pointer
    • target: Hex-encoded target address
  • address() -> str

    • Get pointer's network address
  • target() -> str

    • Get pointer's target address

VaultSecretKey

Manage vault access keys.

  • new() -> VaultSecretKey

    • Generate new key
  • from_hex(hex: str) -> VaultSecretKey

    • Create from hex string
  • to_hex() -> str

    • Convert to hex string

UserData

Manage user data in vaults.

  • new() -> UserData

    • Create new user data
  • add_file_archive(archive: str) -> Optional[str]

    • Add file archive
    • Returns archive ID if successful
  • add_private_file_archive(archive: str) -> Optional[str]

    • Add private archive
    • Returns archive ID if successful
  • file_archives() -> List[Tuple[str, str]]

    • List archives as (id, address) pairs
  • private_file_archives() -> List[Tuple[str, str]]

    • List private archives as (id, address) pairs

DataMapChunk

Handle private data storage references.

  • from_hex(hex: str) -> DataMapChunk

    • Create from hex string
  • to_hex() -> str

    • Convert to hex string
  • address() -> str

    • Get short reference address

Utility Functions

  • encrypt(data: bytes) -> Tuple[bytes, List[bytes]]
    • Self-encrypt data
    • Returns (data_map, chunks)

Examples

See the examples/ directory for complete examples:

  • autonomi_example.py: Basic data operations
  • autonomi_pointers.py: Working with pointers
  • autonomi_vault.py: Vault operations
  • autonomi_private_data.py: Private data handling
  • autonomi_private_encryption.py: Data encryption
  • autonomi_scratchpad.py: Scratchpad creation and updates (with counter management)
  • autonomi_advanced.py: Advanced usage scenarios

Best Practices

  1. Always handle wallet private keys securely
  2. Check operation costs before executing
  3. Use appropriate error handling
  4. Monitor wallet balance for payments
  5. Use appropriate content types for vault storage
  6. Consider using pointers for updatable references
  7. Properly manage and backup vault keys

For more examples and detailed usage, see the examples in the repository.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

autonomi_client-0.5.0-cp38-abi3-win_amd64.whl (7.4 MB view details)

Uploaded CPython 3.8+Windows x86-64

autonomi_client-0.5.0-cp38-abi3-musllinux_1_2_x86_64.whl (8.9 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ x86-64

autonomi_client-0.5.0-cp38-abi3-musllinux_1_2_armv7l.whl (8.7 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ ARMv7l

autonomi_client-0.5.0-cp38-abi3-musllinux_1_2_aarch64.whl (8.7 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ ARM64

autonomi_client-0.5.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.7 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

autonomi_client-0.5.0-cp38-abi3-macosx_11_0_arm64.whl (7.7 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

autonomi_client-0.5.0-cp38-abi3-macosx_10_12_x86_64.whl (8.0 MB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

Details for the file autonomi_client-0.5.0-cp38-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for autonomi_client-0.5.0-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 d5c3b73fe0b25dd38606fc3b45727c8086f17d97850419c8d11cd2d9007129ae
MD5 0be39bd5408f546188caa4a316e0b525
BLAKE2b-256 25ec1afa98c4bdb970859b5742ff3e9b50e16a38c2d8aa6ed8b888d7132c3d32

See more details on using hashes here.

Provenance

The following attestation bundles were made for autonomi_client-0.5.0-cp38-abi3-win_amd64.whl:

Publisher: python-publish-client.yml on dirvine/autonomi

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

File details

Details for the file autonomi_client-0.5.0-cp38-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for autonomi_client-0.5.0-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 47116a7fb262b52c5325067380a09732ff863caeae940b18e5cf68a969f417f2
MD5 964e7a6eb4fa55debb4addcd6e344e51
BLAKE2b-256 049ab04e6e4443d3a857489696a33019e956a0193fffef618c28e46fca6f9722

See more details on using hashes here.

Provenance

The following attestation bundles were made for autonomi_client-0.5.0-cp38-abi3-musllinux_1_2_x86_64.whl:

Publisher: python-publish-client.yml on dirvine/autonomi

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

File details

Details for the file autonomi_client-0.5.0-cp38-abi3-musllinux_1_2_armv7l.whl.

File metadata

File hashes

Hashes for autonomi_client-0.5.0-cp38-abi3-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 cb7ba96c9514eec924f76edb6dbface8f241d7bd190abc40c99ca25bd67f5f2f
MD5 7df4321113c1bbc44d500f74e11b1c0d
BLAKE2b-256 d60b314309cc169125dc112008ed0c54c9f432953d6066bc50084c6d1a5c597d

See more details on using hashes here.

Provenance

The following attestation bundles were made for autonomi_client-0.5.0-cp38-abi3-musllinux_1_2_armv7l.whl:

Publisher: python-publish-client.yml on dirvine/autonomi

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

File details

Details for the file autonomi_client-0.5.0-cp38-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for autonomi_client-0.5.0-cp38-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 b31cc665cddf5374e5a49b547346c6d137c1883131237c5e30f1c3b6dc78c0f0
MD5 95d933c9cd82d338a33fbe8d3397f6a8
BLAKE2b-256 e1e02befe9d0b3f327e1bb499bca8ad6f188677bd8e95d4d78cdff6ac73f0c31

See more details on using hashes here.

Provenance

The following attestation bundles were made for autonomi_client-0.5.0-cp38-abi3-musllinux_1_2_aarch64.whl:

Publisher: python-publish-client.yml on dirvine/autonomi

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

File details

Details for the file autonomi_client-0.5.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for autonomi_client-0.5.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7582c084a835500a7f531f0087de8bab3409bfb096de3ecada933c0a5c069e80
MD5 0579eb39c9bb7843d53ec55a7acb3bca
BLAKE2b-256 8e61d8b1ef3d385d63d5e4b128be243ac5047264207b7839459376b07dadbaa1

See more details on using hashes here.

Provenance

The following attestation bundles were made for autonomi_client-0.5.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: python-publish-client.yml on dirvine/autonomi

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

File details

Details for the file autonomi_client-0.5.0-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for autonomi_client-0.5.0-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a97b299890ae8d34c2d797a3f8bce403337ad07c9a72483abfe69d8fb7f1d68d
MD5 a2a3d2386ea65c37949ace8befb7a274
BLAKE2b-256 0394ffac9568c2f4aa9a09939a6eb5935835759c5b8156e4a910e04ceccd2b35

See more details on using hashes here.

Provenance

The following attestation bundles were made for autonomi_client-0.5.0-cp38-abi3-macosx_11_0_arm64.whl:

Publisher: python-publish-client.yml on dirvine/autonomi

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

File details

Details for the file autonomi_client-0.5.0-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for autonomi_client-0.5.0-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 6111149fcd3e917b37b645f76a84f3049088de04eb874bd95717a811638a2cbd
MD5 121085223f5b1385463b0c9dc38189d9
BLAKE2b-256 3e8094ab9765a39794b13a02d928621049a7d9dde9116f8049dd810e0485dac8

See more details on using hashes here.

Provenance

The following attestation bundles were made for autonomi_client-0.5.0-cp38-abi3-macosx_10_12_x86_64.whl:

Publisher: python-publish-client.yml on dirvine/autonomi

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