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.4.0b2.tar.gz (55.9 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.4.0b2-py3-none-any.whl (71.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: agentrux_sdk-0.4.0b2.tar.gz
  • Upload date:
  • Size: 55.9 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.4.0b2.tar.gz
Algorithm Hash digest
SHA256 8717ad0896c4eb03d99e9f92dfad96f1440ec3d12a55c7bebe580085892bd60c
MD5 f2667a40170c7039e8cb6d4d636c6afa
BLAKE2b-256 bcefa85acf96f48f4bae74e771be0ea8417dd15cba849d5a8e89eb1fdd99aad7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: agentrux_sdk-0.4.0b2-py3-none-any.whl
  • Upload date:
  • Size: 71.9 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.4.0b2-py3-none-any.whl
Algorithm Hash digest
SHA256 6940e6f30344cfc4fa291eb3f838ac37d10984a2981eb5286e023c495fd74810
MD5 7ced1900c8809e6aa865cda570c1a621
BLAKE2b-256 01db5fb23f54da8c8b6526253f3fac1b977b41e79c81a7dc6f474da29466284e

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