Metadata-Version: 2.4
Name: rescontre
Version: 0.1.1
Summary: Clearinghouse SDK for agent-to-agent payments.
Project-URL: Homepage, https://github.com/Rescontre/facilitator
Project-URL: Repository, https://github.com/Rescontre/sdk-py
Project-URL: Issues, https://github.com/Rescontre/sdk-py/issues
Author-email: Jungyoon Lim <46868943+Jungyoonlim@users.noreply.github.com>
License-Expression: MIT
License-File: LICENSE
Keywords: agents,clearinghouse,payments,settlement,x402
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Requires-Dist: httpx>=0.27
Requires-Dist: pydantic>=2.6
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: respx>=0.21; extra == 'dev'
Description-Content-Type: text/markdown

# rescontre

Python SDK for Rescontre, a clearinghouse for agent-to-agent payments. Agents and resource
servers record commitments against a bilateral ledger and settle in periodic
batches instead of on every request.

## Why?

Instead of settling every API call on-chain, Rescontre nets obligations and settles the differences. Up to ~90% fewer settlement transactions. 

## Install

```bash
pip install rescontre
```

## Quickstart

The SDK requires an API key for `verify` and `settle` calls. Mint one on the facilitator with `POST /admin/keys` (operator-only, requires `X-Internal-Secret`), then either set `RESCONTRE_API_KEY` in your environment or pass `api_key=` to the client:

```bash
export RESCONTRE_API_KEY=<64-char hex key>
```

```python
from rescontre import Client, Direction

# Picks up RESCONTRE_API_KEY from the environment...
with Client("http://localhost:3000") as c:
    ...

# ...or pass it explicitly:
with Client("http://localhost:3000", api_key="<64-char hex key>") as c:
    c.register_agent("agent-1", wallet_address="0xAAA...")
    c.register_server("server-1", wallet_address="0xBBB...", endpoints=["/api/data"])
    c.create_agreement("agent-1", "server-1", credit_limit=10_000_000, settlement_frequency=100)

    check = c.verify("agent-1", "server-1", amount=1_000_000, nonce="n-1")
    assert check.valid, check.reason

    receipt = c.settle(
        "agent-1", "server-1",
        amount=1_000_000, nonce="n-1",
        description="GET /api/data",
        direction=Direction.AgentToServer,
    )
    print(receipt.commitment_id, receipt.net_position)
```

Amounts are integers in microdollars (`$1 == 1_000_000`).

## Connect

```python
# Local development
with Client("http://localhost:3000") as c:

# Production
with Client("https://rescontre-production.up.railway.app") as c:
```

```python
    # After multiple settle calls in both directions...
    result = c.bilateral_settlement("agent-1", "server-1")
    print(f"Gross: ${result.gross_volume / 1_000_000:.2f}")
    print(f"Net:   ${result.net_amount / 1_000_000:.2f}")
    print(f"Compression: {result.compression:.0%}")
```

## Examples

End-to-end demo of the x402 → verify → settle → net flow lives in [`examples/`](./examples). The example server uses FastAPI, which is *not* a dependency of the SDK itself. Install it separately:

```bash
pip install fastapi uvicorn

# Terminal 1
python examples/demo_server.py

# Terminal 2
python examples/demo_client.py
```
