Installation

Terminal
$ pip install openleash-sdk

Quick Example

Request authorization before performing a risky action. The SDK signs the request with your agent's Ed25519 private key and returns a decision with an optional proof token.

authorize.py
from openleash import (
authorize,
generate_ed25519_keypair,
)
# Generate a keypair (do this once, store the keys)
public_key, private_key = generate_ed25519_keypair()
# Request authorization for an action
result = authorize(
base_url="http://localhost:8787",
agent_id="agent-uuid",
private_key=private_key,
request={
"action": "purchase",
"resource": "office-supplies",
"context": {"amount": 42.00},
},
)
# result.decision: "ALLOW" | "DENY" | "REQUIRE_APPROVAL" | ...
# result.proof_token: signed PASETO v4.public token (if allowed)

Available Functions

The Python SDK provides 13 functions covering the full agent authorization lifecycle. All functions use snake_case naming:

  • authorize — request an authorization decision for an action
  • sign_request — sign an HTTP request body with Ed25519
  • register_agent — register an agent with the OpenLeash server
  • verify_proof_offline — verify a proof token locally using the public key
  • verify_proof_online — verify a proof token via the server API
  • generate_ed25519_keypair — generate a new Ed25519 signing keypair
  • create_approval_request — create a pending approval request
  • get_approval_request — fetch the status of an approval request
  • poll_approval_request — poll until an approval request is resolved
  • get_agent — retrieve agent details from the server
  • list_policies — list all policies visible to the agent
  • list_approval_requests — list all approval requests for the agent
  • propose_policy — propose a new policy for owner review

Proof Verification

Counterparties can verify proof tokens offline without contacting the OpenLeash server. The token is a PASETO v4.public token signed with Ed25519. Note: pyseto requires PEM-formatted keys.

verify.py
from openleash import verify_proof_offline
claims = verify_proof_offline(
proof_token=proof_token,
public_key=owner_public_key,
)
# claims["action"], claims["resource"], claims["decision"], claims["exp"]

Links