Skip to main content

Agentium SDK for Python - DID and Verifiable Credentials

Project description

Agentium SDK for Python

Python SDK for Agentium Network - DID and Verifiable Credentials.

Installation

pip install agentium-sdk

Requirements

  • Python: 3.8 or higher
  • For end users: No additional dependencies (prebuilt wheels available for most platforms)
  • For development/building from source:
    • Rust toolchain (1.70+) - Install Rust
    • Maturin build tool: pip install maturin

Quick Start

Google Sign-In

import agentium_sdk

# Connect with Google Sign-In (async)
wallet_address, did = await agentium_sdk.connect_google(google_id_token)

# Or use the sync version
wallet_address, did = agentium_sdk.connect_google_sync(google_id_token)

Note: The google_id_token is obtained from Google's OAuth 2.0 authentication flow. See Google Identity documentation for implementation details.

Wallet Sign-In (SIWE/EIP-4361)

import agentium_sdk
import os

# Connect with wallet using local signing (async)
wallet_address, did = await agentium_sdk.connect_wallet(
    address="0x742d35Cc6634C0532925a3b844Bc9e7595f1b2b7",
    chain_id="eip155:84532",  # CAIP-2 format (Base Sepolia)
    private_key=os.getenv("WALLET_PRIVATE_KEY"),  # hex string or bytes
)

# Or use the sync version
wallet_address, did = agentium_sdk.connect_wallet_sync(
    address, chain_id, private_key
)

Security Warning: Never hardcode private keys in your source code. Always use environment variables, secure key management systems, or hardware wallets in production.

AgentiumClient

The AgentiumClient is the main interface for API interactions.

Configuration

from agentium_sdk import AgentiumClient

# Default: connects to https://api.agentium.network
async with AgentiumClient() as client:
    pass

# Custom endpoint
async with AgentiumClient(base_url="https://custom.endpoint") as client:
    pass

Methods

connect_google_identity(google_token: str) -> ConnectIdentityResponse

Connect a Google identity to create/retrieve a DID.

response = await client.connect_google_identity(google_id_token)
print(response.did)           # did:pkh:eip155:1:0x...
print(response.access_token)  # JWT for authenticated calls
print(response.is_new)        # True if newly created

exchange_api_key(api_key: str) -> OAuthTokenResponse

Exchange an API key for JWT tokens (M2M authentication).

response = await client.exchange_api_key(api_key)
print(response.access_token)
print(response.refresh_token)

refresh_token(refresh_token: str) -> OAuthTokenResponse

Refresh an expired access token.

response = await client.refresh_token(old_refresh_token)

fetch_membership_credential(token: str) -> str

Fetch a membership credential JWT.

credential_jwt = await client.fetch_membership_credential(access_token)

fetch_issuer_did_document() -> dict[str, Any]

Fetch the issuer's DID document from /.well-known/did.json.

did_document = await client.fetch_issuer_did_document()
print(did_document["id"])  # did:web:api.agentium.network

verify_credential(jwt: str) -> VerificationResult

Verify a credential against the issuer's public key (fetches DID document automatically).

result = await client.verify_credential(credential_jwt)
if result.valid:
    print(result.claims)  # dict with JWT claims

request_wallet_challenge(address: str, chain_id: str) -> WalletChallengeResponse

Request a SIWE challenge message for wallet sign-in.

challenge = await client.request_wallet_challenge(
    address="0x742d35Cc6634C0532925a3b844Bc9e7595f1b2b7",
    chain_id="eip155:84532",  # CAIP-2 format
)
print(challenge.message)  # SIWE message to sign
print(challenge.nonce)    # Unique nonce for replay protection

verify_wallet_signature(message: str, signature: str) -> OAuthTokenResponse

Verify a signed challenge and obtain JWT tokens.

response = await client.verify_wallet_signature(challenge.message, signature)
print(response.access_token)
print(response.refresh_token)

connect_wallet(address: str, chain_id: str, private_key: bytes | str) -> ConnectIdentityResponse

Full wallet sign-in flow with local signing (challenge → sign → verify).

import os

response = await client.connect_wallet(
    address="0x742d35Cc6634C0532925a3b844Bc9e7595f1b2b7",
    chain_id="eip155:84532",
    private_key=os.getenv("WALLET_PRIVATE_KEY"),  # hex string or bytes
)
print(response.did)           # did:pkh:eip155:84532:0x...
print(response.access_token)  # JWT for authenticated calls
print(response.is_new)        # True if newly created

Security Note: Use secure key management practices. Never commit private keys to version control.

Native Functions

Low-level cryptographic operations powered by Rust.

verify_jwt(jwt: str, public_key_jwk: str) -> VerificationResult

Verify a JWT signature against a public key.

from agentium_sdk import verify_jwt

result = verify_jwt(jwt_string, public_key_jwk_json)
if result.valid:
    print(result.claims)           # dict[str, Any]
else:
    print(result.error.code)       # e.g., "JWT_EXPIRED"
    print(result.error.message)

parse_jwt_header(jwt: str) -> JwtHeader

Parse JWT header without verification.

from agentium_sdk import parse_jwt_header

header = parse_jwt_header(jwt_string)
print(header.alg)  # "EdDSA"
print(header.kid)  # Key ID for DID document lookup

extract_public_key_jwk(did_document_json: str, kid: str | None) -> str

Extract a public key from a DID document.

from agentium_sdk import extract_public_key_jwk

public_key_jwk = extract_public_key_jwk(did_doc_json, kid="#key-1")

generate_keypair() -> GeneratedKeyPair

Generate a new Ed25519 key pair.

from agentium_sdk import generate_keypair

keypair = generate_keypair()
print(keypair.public_key_jwk)   # Safe to share
print(keypair.private_key_jwk)  # Keep secret!

get_public_key(private_key_jwk: str) -> str

Derive public key from a private key.

from agentium_sdk import get_public_key

public_jwk = get_public_key(private_key_jwk_json)

sign_challenge(message: bytes, chain_id: str, private_key: bytes) -> str

Sign a wallet authentication challenge message.

from agentium_sdk import sign_challenge
import os

# Load private key securely from environment
private_key = bytes.fromhex(os.getenv("WALLET_PRIVATE_KEY"))

signature = sign_challenge(
    message=challenge_message.encode("utf-8"),
    chain_id="eip155:84532",
    private_key=private_key,
)
print(signature)  # 0x-prefixed hex signature

validate_caip2(chain_id: str) -> bool

Validate a CAIP-2 chain identifier format.

from agentium_sdk import validate_caip2

if validate_caip2("eip155:84532"):
    print("Valid chain ID")

Telemetry

Enable structured tracing with a custom callback.

from agentium_sdk import init_tracing

def telemetry_handler(event: dict):
    """Receives events with: kind, level, target, name, fields, ts_ms"""
    print(f"[{event['level']}] {event['target']}: {event['fields']}")

# Initialize once per process
init_tracing(telemetry_handler, "debug")  # filter: "info", "debug", "agentium=trace"

Note: init_tracing can only be called once. Subsequent calls are ignored.

Types

Type Description
ConnectIdentityResponse DID, tokens, badge status, is_new flag
OAuthTokenResponse access_token, refresh_token, expires_in, scope
WalletChallengeResponse message, nonce for wallet sign-in challenge
Caip2 Parsed CAIP-2 chain identifier with namespace and reference
VerificationResult valid, claims (dict), error
VerificationError code, message
JwtHeader alg, typ, kid
GeneratedKeyPair private_key_jwk, public_key_jwk
Badge status

Exceptions

AgentiumApiError

Raised on API failures.

from agentium_sdk import AgentiumApiError

try:
    await client.connect_google_identity(invalid_token)
except AgentiumApiError as e:
    print(e.message)
    print(e.status_code)  # 401, 403, etc.

Development

This SDK is a Python binding to native Rust code, providing high-performance cryptographic operations. Building from source requires the Rust toolchain.

Setup

# Install Rust toolchain (if not already installed)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Install Maturin (build tool for Rust-based Python packages)
pip install maturin

# Build and install in development mode
# This compiles the Rust code and creates a Python package
maturin develop

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest

About Maturin

Maturin is the build tool that bridges Rust and Python, compiling the native Rust extensions and packaging them as a Python wheel. The maturin develop command builds the Rust code in debug mode and installs it in your current Python environment.

Building Documentation

Note: This section is for SDK contributors who want to build and preview the documentation locally.

To build and serve docs:

# From the repository root, navigate to the Python SDK directory
cd packages/agentium-native/python

# Install documentation dependencies
pip install -e ".[docs]"

# Build the SDK first (required - mkdocstrings needs to import the package)
maturin develop

# Serve docs locally with hot-reload at http://127.0.0.1:8000
mkdocs serve

# Or build static site to site/ directory
mkdocs build

The documentation uses MkDocs with the mkdocstrings plugin to auto-generate API docs from Python docstrings and type hints.

License

MIT License - see LICENSE file for details.

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

agentium_sdk-0.4.6.tar.gz (80.4 kB view details)

Uploaded Source

Built Distributions

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

agentium_sdk-0.4.6-cp313-cp313-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.13Windows x86-64

agentium_sdk-0.4.6-cp313-cp313-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

agentium_sdk-0.4.6-cp313-cp313-macosx_10_12_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

agentium_sdk-0.4.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

Details for the file agentium_sdk-0.4.6.tar.gz.

File metadata

  • Download URL: agentium_sdk-0.4.6.tar.gz
  • Upload date:
  • Size: 80.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for agentium_sdk-0.4.6.tar.gz
Algorithm Hash digest
SHA256 decd5b6c5e958ee2125d818ad82b49784106548336f385a39b39032d4066b890
MD5 66630c42ab70d27175b5bc643a885e02
BLAKE2b-256 1a29f4241a2b07e6a673694753e547ed7ae306e19e9765f3ee264301c8e2e425

See more details on using hashes here.

Provenance

The following attestation bundles were made for agentium_sdk-0.4.6.tar.gz:

Publisher: release-please.yml on semiotic-agentium/agentium-sdk

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

File details

Details for the file agentium_sdk-0.4.6-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for agentium_sdk-0.4.6-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 a4d8f7fbbe777fe7568d87821bb19c4c30595109f288da215ca22b638efe2f05
MD5 c71f2a509cc878301fc04bfb7307c86c
BLAKE2b-256 3fb80dff57d2348c8f95163c86db39352765e53b0be1fdfe9cd6b5d3dd406bba

See more details on using hashes here.

Provenance

The following attestation bundles were made for agentium_sdk-0.4.6-cp313-cp313-win_amd64.whl:

Publisher: release-please.yml on semiotic-agentium/agentium-sdk

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

File details

Details for the file agentium_sdk-0.4.6-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for agentium_sdk-0.4.6-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 07b39072dcd75a31780888c5f22eb858446d95a42964377dfe5363597d27420c
MD5 20b25851e6f85293b314bdf6f0e39bb2
BLAKE2b-256 862c992bf150b5a527a348015b7186f6d54735d8f9417935139d7fd9e3db7ca0

See more details on using hashes here.

Provenance

The following attestation bundles were made for agentium_sdk-0.4.6-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: release-please.yml on semiotic-agentium/agentium-sdk

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

File details

Details for the file agentium_sdk-0.4.6-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for agentium_sdk-0.4.6-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5649e17fa604eb681982ff890ae01d32bc1bcb3de02f75211395761c6e563590
MD5 26a663acd4101cac5f6fbcf4b4b4585c
BLAKE2b-256 187ed10bcc7353fd0495b9d46a2bc1794d648fcc9ca977236c9ccdbe5e153b03

See more details on using hashes here.

Provenance

The following attestation bundles were made for agentium_sdk-0.4.6-cp313-cp313-macosx_10_12_x86_64.whl:

Publisher: release-please.yml on semiotic-agentium/agentium-sdk

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

File details

Details for the file agentium_sdk-0.4.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for agentium_sdk-0.4.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 45a7dc2735447246345b9cc408fa10804a806353636409ce3a60bedfd0f884d1
MD5 71f736f6f770c49fd29a98b6e7d93cf4
BLAKE2b-256 337a5fa4ca22bb21b046698a1d2be191a1844e8e585d88f88baa13897fdfd454

See more details on using hashes here.

Provenance

The following attestation bundles were made for agentium_sdk-0.4.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release-please.yml on semiotic-agentium/agentium-sdk

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