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

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

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_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.4.0rc3-cp38-abi3-win_amd64.whl (8.6 MB view details)

Uploaded CPython 3.8+Windows x86-64

autonomi_client-0.4.0rc3-cp38-abi3-musllinux_1_2_x86_64.whl (10.6 MB view details)

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

autonomi_client-0.4.0rc3-cp38-abi3-musllinux_1_2_armv7l.whl (10.1 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ ARMv7l

autonomi_client-0.4.0rc3-cp38-abi3-musllinux_1_2_aarch64.whl (10.3 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ ARM64

autonomi_client-0.4.0rc3-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.4 MB view details)

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

autonomi_client-0.4.0rc3-cp38-abi3-macosx_11_0_arm64.whl (9.1 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

autonomi_client-0.4.0rc3-cp38-abi3-macosx_10_12_x86_64.whl (9.7 MB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

Details for the file autonomi_client-0.4.0rc3-cp38-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for autonomi_client-0.4.0rc3-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 a82d26281c7622c8d794bc0d8dd96be779af61ab3e69506c9de1aec6b87f0849
MD5 8878c812c2c0e88bc61846e40e007166
BLAKE2b-256 9a4a89579efee5a1eb57fe5c5eca2e6dd8327fc38d5fe61a2d24f46a45b454c1

See more details on using hashes here.

Provenance

The following attestation bundles were made for autonomi_client-0.4.0rc3-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.4.0rc3-cp38-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for autonomi_client-0.4.0rc3-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 4a668ca8a9911b2e93769c128736cda7bf752f8204f9ff5d2454b9d23f37fa98
MD5 bc1c5a253ce03a11081327d3e66a6938
BLAKE2b-256 d9189434102ee1afc12fc053d3a1e9da1dd5ca12fb970b64d6cb4d0fd1f9f07a

See more details on using hashes here.

Provenance

The following attestation bundles were made for autonomi_client-0.4.0rc3-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.4.0rc3-cp38-abi3-musllinux_1_2_armv7l.whl.

File metadata

File hashes

Hashes for autonomi_client-0.4.0rc3-cp38-abi3-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 2dee6196250682fbd27456d4ebb066f9b92f9c3505445ff2fc5cdaff6f3c8c3e
MD5 f26e5152e6fc64166070917afe10573c
BLAKE2b-256 4cf8524089a10d19e0f4a84acaad18e5b9d953553b7ee44730923f70b0ab5c78

See more details on using hashes here.

Provenance

The following attestation bundles were made for autonomi_client-0.4.0rc3-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.4.0rc3-cp38-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for autonomi_client-0.4.0rc3-cp38-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 fa6ed7dabadadb6b849b9fcd4b751bd14ce9c0d35d2d9d7485f44ed3d615b772
MD5 8d8343e3bb9ca6d1e11f17b412e0a0b2
BLAKE2b-256 1ef2009645d6100270b07ee8beee108679a0ea3e75e6e9a902f6fd12cb13b489

See more details on using hashes here.

Provenance

The following attestation bundles were made for autonomi_client-0.4.0rc3-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.4.0rc3-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for autonomi_client-0.4.0rc3-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2fa29d92b0fcdb7a6e8b29c15601b3252993c238eeb252745cefa42d92a31729
MD5 e1949771b4e027ac34c6ff0dd6dc20b9
BLAKE2b-256 64e2945b30cd6077a9b073921154d13335ca63d13619e6209c38f60536cb0bff

See more details on using hashes here.

Provenance

The following attestation bundles were made for autonomi_client-0.4.0rc3-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.4.0rc3-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for autonomi_client-0.4.0rc3-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 011be141b558bfca25e9bd86a66e7a5daa5d6f2765d311da2da7abed2324dfa9
MD5 72cfe67df0871bf161be31cad5942611
BLAKE2b-256 4c6d6a248c8cd4da7521607258ccb69241846251e907be8697f0f3cf247a5319

See more details on using hashes here.

Provenance

The following attestation bundles were made for autonomi_client-0.4.0rc3-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.4.0rc3-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for autonomi_client-0.4.0rc3-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 58f1ffece622fde8b7be2261d1c6e60b5e6fa07035fa7ffb9ef2df8bb501c469
MD5 5e026db6d056825f136bd0288bdbdffa
BLAKE2b-256 70d7a72654380be850237142b7d558ddd1d2f5dfe230c0412fcb421502780ad7

See more details on using hashes here.

Provenance

The following attestation bundles were made for autonomi_client-0.4.0rc3-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