Skip to main content

Python SDK for AgenTrux — A2A authenticated pub/sub client

Project description

AgenTrux SDK

Python SDK for AgenTrux — A2A authenticated pub/sub client.

Status: Beta (0.3.0b1) — OAuth 2.1 (Phase 1.9+) + cursor-based pagination + SSE hint-only consumer.

Install

pip install agentrux-sdk

Quick Start

from agentrux.sdk import AgenTruxClient

# 1) Confidential client (script credentials issued by Console)
client = await AgenTruxClient.from_client_credentials(
    "https://api.agentrux.com",
    client_id="crd_<uuid>",        # script credential client_id
    client_secret="aks_<base64>",  # script credential client_secret
)

# 2) Activation code (one-shot redemption → persisted client_credentials)
client = await AgenTruxClient.from_activation_code(
    "https://api.agentrux.com",
    activation_code="act_<base64>",
    save_credentials_to="~/.agentrux/credentials.json",
)

# 3) Public client via device flow (RFC 8628 + DCR)
dcr = await AgenTruxClient.register_dcr_client(
    "https://api.agentrux.com", client_name="my-plugin",
)
auth = await AgenTruxClient.start_device_flow(
    "https://api.agentrux.com", oauth_client_id=dcr.client_id,
    scope="topic:abc:read topic:abc:write",
)
print(f"User: visit {auth.verification_uri_complete} and approve.")
client = await AgenTruxClient.complete_device_flow(
    "https://api.agentrux.com",
    device_code=auth.device_code,
    oauth_client_id=dcr.client_id,
)

# --- Publish & subscribe ----------------------------------------------

await client.publish("top_<uuid>", "hello.world", {"msg": "Hello!"})

async with client.subscribe("top_<uuid>") as sub:
    async for envelope in sub:
        print(envelope.event_type, envelope.payload)

OAuth 2.1

Factory Grant Refresh
from_client_credentials(client_id="crd_<uuid>", client_secret=...) client_credentials automatic re-issue (no refresh_token; the SDK re-runs the credential exchange)
from_activation_code(activation_code="act_<base64>") redeems AC → client_credentials same as above
complete_device_flow(device_code=..., oauth_client_id="dcr_<uuid>") device_code → access+refresh OAuthRefreshTokenRefresher (RFC 6749 §6)
from_access_token(access_token=..., refresh_token=..., oauth_client_id=...) bring-your-own wired automatically when oauth_client_id is provided

on_token_refreshed: Callable[[TokenBundle], None] is invoked after each successful refresh; use it to persist the rotated tokens.

TokenBundle dataclass

@dataclass(frozen=True)
class TokenBundle:
    access_token: str
    refresh_token: str | None     # client_credentials path → None
    expires_at_unix: int          # absolute unix epoch seconds

Persistence example

def save(bundle: TokenBundle) -> None:
    Path("~/.agentrux/credentials").expanduser().write_text(
        f"access_token={bundle.access_token}\n"
        f"refresh_token={bundle.refresh_token}\n"
        f"expires_at_unix={bundle.expires_at_unix}\n"
    )

client = await AgenTruxClient.from_access_token(
    "https://api.agentrux.com",
    access_token=loaded.access_token,
    refresh_token=loaded.refresh_token,
    oauth_client_id="dcr_<uuid>",
    on_token_refreshed=save,
)

Subscribe modes

  • mode="hybrid" (default): pull-driven, SSE hints accelerate the next pull.
  • mode="pull": pull only; works without SSE reachability.
  • mode="sse": alias for hybrid with SSE enabled (kept for naming clarity).

Pass on_resync_required= to be notified when the server emits event: resync_required (the cursor became invalid — reset checkpoint and resubscribe). The hybrid consumer always surfaces a ResyncRequiredError to the iterator after the callback returns; the callback itself is for logging/metrics only.

Used by

This SDK is the shared transport layer for all AgenTrux Python plugins:

  • agentrux-agent-tools — AI agent toolkit
  • (Dify Tools / Dify Trigger — once migrated to v0.3)

License

MIT

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

agentrux_sdk-0.3.0b2.tar.gz (44.8 kB view details)

Uploaded Source

Built Distribution

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

agentrux_sdk-0.3.0b2-py3-none-any.whl (54.7 kB view details)

Uploaded Python 3

File details

Details for the file agentrux_sdk-0.3.0b2.tar.gz.

File metadata

  • Download URL: agentrux_sdk-0.3.0b2.tar.gz
  • Upload date:
  • Size: 44.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for agentrux_sdk-0.3.0b2.tar.gz
Algorithm Hash digest
SHA256 31211c369fc9b714975122d176206be37e49fa952de09ab75030850e31093d34
MD5 966b85076f300360bf4421625ee71aca
BLAKE2b-256 2b7756adc979e200c0265b676ba093297d86c6548563238be3241b553f5e6da5

See more details on using hashes here.

File details

Details for the file agentrux_sdk-0.3.0b2-py3-none-any.whl.

File metadata

  • Download URL: agentrux_sdk-0.3.0b2-py3-none-any.whl
  • Upload date:
  • Size: 54.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for agentrux_sdk-0.3.0b2-py3-none-any.whl
Algorithm Hash digest
SHA256 eb85c65f240b275476b1ab84b86c2740c73f9a1cfa5be2ae69d7b074dfd30e68
MD5 cf6138f8789e800184a8d60f7f6523ed
BLAKE2b-256 814400352e87fcaa636bea75e212b7d843c80b92f7bb3f0e9b017b8ef2516111

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