Skip to main content

Official Python SDK for the Ralio agentic payment API.

Project description

Ralio Python SDK

PyPI version Python versions CI License: MIT Ruff

The official Python client for the Ralio agentic payment API.

It handles the machine-authentication path end to end — OAuth 2.1 client_credentials with private_key_jwt and DPoP-bound access tokens — so your integration can talk to an agent without hand-rolling JWT signing, proof generation, or token refresh.

Scope. This SDK targets autonomous integrations (CI jobs, agent hosts, server-side callers). It authenticates as a credential binding, which can hold the agents:execute and transactions:read scopes. Agent and binding management (agents:config) is a human-only operation in the console and is intentionally not part of this SDK.

Installation

pip install ralio

Requires Python 3.10+.

Authentication model

Ralio's machine path has no shared secrets. Each credential is a P-256 private key that lives on exactly one host:

  1. The owner mints a one-time registration ticket in the console (Settings → Credentials → New credential), choosing the target agent and a scope ceiling. That is where consent happens. They send you the ralio-reg-… ticket.
  2. You call ralio.register() once on the agent host. It generates a keypair locally and submits the public key with the ticket; the binding is active as soon as the server responds — no approval step, no polling. The owner gets an email receipt with a revoke link. The credentials are persisted to ~/.ralio/ — the same store the ralio CLI uses, so register() and ralio auth agent are interchangeable.
  3. From then on, RalioClient mints and refreshes DPoP-bound access tokens transparently and signs a fresh proof for every request.

See the API authentication guide for the protocol details.

Quickstart

With the owner's ticket in RALIO_REGISTRATION_TICKET, onboarding is two calls:

import ralio

ralio.register()  # run once; the binding is active when this returns

client = ralio.RalioClient()  # zero-config: reads the persisted credentials
reply = client.chat.send(message="What is my current balance?")

register() activates the binding in a single call (or raises RalioRegistrationError if the ticket is invalid, expired, or already consumed). The private key is generated locally, written to ~/.ralio/keys/<jkt>.pem, and never leaves the host.

Everything is overridable when you want to manage credentials yourself:

import ralio

binding = ralio.register(
    ticket="ralio-reg-...",                      # instead of RALIO_REGISTRATION_TICKET
    private_key_path="ralio-key.pem",            # generated and written here
    requested_scopes=["agents:execute", "transactions:read"],
)
print(binding.client_id)   # cb_... — store this alongside the key

Use the client

import ralio

# Zero-config: reads the credentials persisted by register() / `ralio auth agent`.
client = ralio.RalioClient()

# Or manage credentials yourself:
# client = ralio.RalioClient(
#     client_id="cb_...",
#     private_key_path="ralio-key.pem",
# )

# Synchronous chat — agent_id is resolved automatically for a single-agent
# credential; pass agent_id explicitly to target one of several agents.
reply = client.chat.send(message="What is my current balance?")
print(reply.reply)

# Streaming chat (server-sent events)
for event in client.chat.stream(message="List my recent payments"):
    if event.event == "text_delta":
        print(event.text, end="", flush=True)
    elif event.event == "tool_started":
        print(f"\n[tool] {event.data['tool_name']}")

# Transactions — list endpoints are paginated; a Page is iterable and sized.
page = client.transactions.list(per_page=20)
print(f"showing {len(page)} of {page.total} transactions (page {page.page})")
for txn in page:
    print(txn.date, txn.amount, txn.currency, txn.creditor, txn.status)

# Payment intents — what the agent proposed, with per-leg execution detail.
for intent in client.payment_intents.list(per_page=20):
    print(intent.created_at, intent.total_amount, intent.currency, intent.approval_status)

client.close()

RalioClient is also a context manager:

with ralio.RalioClient() as client:
    ...

Environment variables

Variable Meaning
RALIO_REGISTRATION_TICKET Default ticket for register() — same variable the CLI reads
RALIO_API_URL API origin (default https://api.ralio.co)
RALIO_CONFIG_DIR Credential store location (default ~/.ralio, shared with the CLI)

Payments

There is no payments.create() method by design. Payments are executed by the agent, not by direct REST calls: drive the agent with chat.send / chat.stream ("Pay £500 to Bob for the April invoice") and it will create the payment, subject to its spend limits and approval rules. Use transactions.list (executed payments) and payment_intents.list (what the agent proposed, with per-leg status) to read what the agent did.

Errors

All errors subclass ralio.RalioError:

Exception When
RalioAuthError (401) Missing/invalid token, failed assertion, or rejected DPoP proof
RalioPermissionError (403) Token lacks the required scope, or resource not owned
RalioNotFoundError (404) Resource doesn't exist
RalioValidationError (422) Invalid field values or business-rule violation
RalioRateLimitError (429) Rate limited — back off and retry
RalioAPIError Any other HTTP error (carries status_code, detail)
RalioRegistrationError Registration failed (invalid / expired / consumed ticket)
RalioConfigError Local configuration problem
import ralio

try:
    client.chat.send(agent_id="...", message="...")
except ralio.RalioPermissionError as exc:
    print("scope problem:", exc.detail)

Development

pip install -e ".[dev]"
ruff check .
mypy
pytest -q

License

MIT — see LICENSE.

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

ralio-0.1.0.tar.gz (28.8 kB view details)

Uploaded Source

Built Distribution

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

ralio-0.1.0-py3-none-any.whl (24.8 kB view details)

Uploaded Python 3

File details

Details for the file ralio-0.1.0.tar.gz.

File metadata

  • Download URL: ralio-0.1.0.tar.gz
  • Upload date:
  • Size: 28.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ralio-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8a96069c9ac87e5493f3a184ce7c8a25f653984ab4f4dd770004f6a4855ff6de
MD5 8bc666d9a56f0b3970934a87e3c00d8d
BLAKE2b-256 e6001d2d650de5501e51fd66074f065d9d9dec323a32db872fb727a1b5f0c93c

See more details on using hashes here.

Provenance

The following attestation bundles were made for ralio-0.1.0.tar.gz:

Publisher: release.yml on Ralioco/ralio-python

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

File details

Details for the file ralio-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ralio-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 24.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ralio-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 73169a9a19acf4e9edf15479eb955825a5277c3dbb9b47afc6bc55860c932900
MD5 cf3c86554fcce6e14a63510f848ebed7
BLAKE2b-256 a07970e5e809599e393cc63e9d418d581cfd3d75429b5a7137e411a1154df35a

See more details on using hashes here.

Provenance

The following attestation bundles were made for ralio-0.1.0-py3-none-any.whl:

Publisher: release.yml on Ralioco/ralio-python

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