Skip to main content

oryne (Python)

Give an AI agent a wallet it can spend from, with limits it cannot break.

agent.fetch() makes an HTTP request. When a service answers 402 Payment Required (x402), it pays in USDC from the agent's Oryne wallet on Stellar and retries. The wallet's smart contract checks every payment against the mandate the owner set: per-payment limit, budget, allowed payees, expiry. Nothing the agent does can get past it.

The same SDK as @oryne/agent for TypeScript, for Python agents: LangChain, CrewAI, LlamaIndex, or a plain script. It also has the other side: charge agents per request from a FastAPI or Flask API.

pip install oryne

Needs Python 3.10 or later.

Use

Connect an agent in the Oryne dashboard. You get its secret key once.

import os
from oryne import OryneAgent

agent = OryneAgent(os.environ["ORYNE_AGENT_SECRET"])

response = agent.fetch("https://api.example.com/search", params={"q": "stellar"})
print(response.json())

fetch takes the same keyword arguments as httpx.Client.request (params, json, headers, content, …) and returns an httpx.Response.

When the wallet refuses a payment, fetch raises PaymentRefusedError with the reason (OverPerTxLimit, OverBudget, PayeeNotAllowed, …). The agent can then ask the owner:

from oryne import PaymentRefusedError

try:
    agent.fetch(url)
except PaymentRefusedError as refused:
    if refused.source != "wallet":
        raise  # refused before signing, see below
    approval = agent.request_approval(
        pay_to=refused.requirements["payTo"],
        amount="30",
        description="Research report for the weekly summary",
        resource=refused.requirements["resource"],
        reason=refused.reason,
    )
    agent.wait_for_approval(approval["id"])  # the owner approves in the dashboard
    agent.fetch(url)                         # now within what was approved

Check a payment before signing

The wallet contract is the hard limit. Before signing, the SDK can also check whether a payment request makes sense at all. That catches a request that is inside the mandate but still wrong: a service that suddenly asks for more, or a hijacked endpoint that asks to be paid at someone else's address.

agent = OryneAgent(
    os.environ["ORYNE_AGENT_SECRET"],
    payees="directory",  # only services in the Oryne directory, at the address they're listed with
    # Your own rule, last before signing: True to pay, or a reason to refuse.
    before_pay=lambda payment: payment.url.startswith("https://api.example.com/") or "only example.com",
)

# This search should cost at most 0.10; a 402 asking more is refused unpaid.
agent.fetch("https://api.example.com/search?q=stellar", max_price="0.10")

A refusal here raises PaymentRefusedError with source == "client". Nothing was signed and no money moved. Refusals from the wallet contract have source == "wallet".

The directory doesn't verify who owns a listed URL yet. payees="directory" stops payments to unlisted hosts and to addresses a host isn't listed with, but for a guarantee, set the allowed payees in the agent's on-chain mandate in the dashboard.

Options

Option
secret The agent's secret key (S…).
api_url Oryne API. Defaults to ORYNE_API_URL, then https://testnet-apiv1.oryne.org (Stellar testnet).
max_per_request Most this client pays for one request, whatever a service asks, e.g. "1".
payees Who it may pay: "any" (default), "directory", or a list of Stellar addresses.
before_pay (PaymentCheck) -> True | False | reason. Last say before signing.
on_payment Called with a PaymentEvent: paying, then paid or refused.
http Your own httpx.Client, e.g. with other timeouts or a proxy.

Per request: agent.fetch(url, max_price="0.10", on_payment=...).

Amounts are strings ("0.05"), never floats, so money doesn't depend on float rounding.

Other methods: agent.me() (the agent, its mandate and what's left of its budget), agent.approval(id). OryneAgent is a context manager that closes its HTTP client.

As tools for your agent framework

oryne.tools gives your model the same four tools as Oryne's MCP server: fetch_paid (fetch a URL, paying a 402 inside the mandate), wallet_status, request_approval and find_service. Each returns text for the model; a refused payment comes back as an explanation, not an exception. The wallet contract enforces the mandate whatever the model asks.

LangChain / LangGraph (pip install "oryne[langchain]"):

from oryne.integrations.langchain import oryne_langchain_tools

tools = oryne_langchain_tools(agent)
llm_with_tools = llm.bind_tools(tools)   # or langgraph's create_react_agent(llm, tools)

CrewAI (pip install "oryne[crewai]"):

from crewai import Agent
from oryne.integrations.crewai import oryne_crewai_tools

researcher = Agent(role="Researcher", goal="...", backstory="...", tools=oryne_crewai_tools(agent))

OpenAI Agents SDK (pip install "oryne[openai-agents]"):

from agents import Agent, Runner
from oryne.integrations.openai_agents import oryne_openai_agents_tools

bot = Agent(name="Researcher", instructions="...", tools=oryne_openai_agents_tools(agent))
Runner.run_sync(bot, "Find the latest notes on x402")

Any OpenAI-style or Claude tool calling (OpenAI, DeepSeek, Groq, Ollama, Anthropic):

from oryne.tools import anthropic_tools, openai_tools, oryne_tools, run_tool

tools = oryne_tools(agent)
response = client.chat.completions.create(model=..., messages=messages, tools=openai_tools(tools))
for call in response.choices[0].message.tool_calls or []:
    result = run_tool(tools, call.function.name, call.function.arguments)  # text to send back

oryne_tools(agent, approval_timeout=120, max_response_chars=50_000, only=["fetch_paid"]) tunes them; the integrations take the same options.

Get paid by agents

You run an API and want agents to pay per call, with no accounts, cards or invoices. Put @pay(...) under the route:

pip install "oryne[fastapi]"
from fastapi import FastAPI, Request
from oryne.merchant.fastapi import paywall

app = FastAPI()
pay = paywall(pay_to="G...your Stellar address", facilitator="https://testnet-apiv1.oryne.org/v1/x402")

@app.get("/search")
@pay("0.05", "Search results")  # 0.05 USDC per call
async def search(q: str, request: Request):
    payment = request.state.oryne_settlement  # transaction, payer, network
    return {"results": [...]}

Flask is the same with pip install "oryne[flask]" and from oryne.merchant.flask import paywall; the payment is in g.oryne_settlement.

Unpaid requests get 402 Payment Required with what to pay. Paid ones are settled through the Oryne facilitator before your handler runs, in about 5 seconds, and the receipt goes back in the X-PAYMENT-RESPONSE header. Payments are final: no chargebacks. Any x402 client can pay you, not only Oryne agents. Your address needs a trustline to the USDC the facilitator uses (on mainnet, https://apiv1.oryne.org/v1/x402).

For another framework, Paywall (or AsyncPaywall) does the work and you send the answer:

from oryne.merchant import Paywall

paywall = Paywall(pay_to="G...", facilitator="https://testnet-apiv1.oryne.org/v1/x402")
result = paywall.handle(price="0.05", url=full_request_url, payment_header=request.headers.get("X-PAYMENT"))
# result.paid: serve the request. Otherwise answer result.status (402) with result.body as JSON.
# Either way, send result.receipt (when set) as the X-PAYMENT-RESPONSE header.

Develop

python -m venv .venv && .venv/bin/pip install -e ".[dev]"
.venv/bin/pytest                                  # unit tests, no network
ORYNE_TESTNET=1 .venv/bin/pytest -m testnet       # end to end on Stellar testnet

The unit tests compare signatures and encodings with fixtures produced by the TypeScript SDK, so the two can't drift apart.

MIT licensed.

Metadata

Release files for oryne 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for oryne 0.4.0
File Size Uploaded Provenance Actions
oryne-0.4.0.tar.gz 29.1 kB With provenance Details for oryne-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for oryne 0.4.0
File Interpreter ABI Platform Actions
oryne-0.4.0-py3-none-any.whl Python 3 none any Details for oryne-0.4.0-py3-none-any.whl

Total release size: 58.0 kB

Release files / oryne-0.4.0.tar.gz

Download URL oryne-0.4.0.tar.gz
Size 29.1 kB
Tags Source
SHA-256 checksum
How to use checksums
1cbc8a2e4bfedb0e0fc05e3e597a48850db1201c14c5be512471335ddb24f707
BLAKE2b-256 checksum
How to use checksums
b8fd5d41e01b1847ec7cdad4c9f80846078fd5c2b0730c7001c3c60a63b83383
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

Release files / oryne-0.4.0-py3-none-any.whl

Download URL oryne-0.4.0-py3-none-any.whl
Size 29.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
291408997eee9427a0b4105070cd83aa02db5d8073ae4c362b5f61e99d1d95c1
BLAKE2b-256 checksum
How to use checksums
44ec608e4c867024b893f0a518823f2931c83761ecf4aa64ad78b6aa3554b71d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

Security for oryne 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for oryne-0.4.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page