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 such as agent hosts, backend services, and other server-side automation. 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 uses the agent selected when this credential was registered.
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(message="...")
except ralio.RalioPermissionError as exc:
    print("scope problem:", exc.detail)

The target agent is fixed by the authenticated credential. To use a different agent, register or authenticate a new credential for that agent.

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.1.tar.gz (30.4 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.1-py3-none-any.whl (24.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ralio-0.1.1.tar.gz
  • Upload date:
  • Size: 30.4 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.1.tar.gz
Algorithm Hash digest
SHA256 68d464905fcf4543c0f2b513ab1c2d3046ea831d186822c4a6177264b9bf14e1
MD5 4df2de9b5ce31f7b071c1332f0160e07
BLAKE2b-256 d646518a6f0978302ba401355b7bea6eaedaf33e3349bc47197ba801339df158

See more details on using hashes here.

Provenance

The following attestation bundles were made for ralio-0.1.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: ralio-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f6f49d5de32ecf1610c3fe80cf1275eb450fa7986a18f5427fdf6eeeb2d62c9b
MD5 83f7c3df082330300d0334b02d2c824d
BLAKE2b-256 852952bef9778f0fcf45c0a190c04a9990a1f690715a01e4f42a086d6069f213

See more details on using hashes here.

Provenance

The following attestation bundles were made for ralio-0.1.1-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