pegana-sdk
Typed Python client for the Pegana peg-risk oracle API.
v0.3.0 — full OpenAPI-generated coverage of every
/v1endpoint (typed models + a sync/async httpx client viaopenapi-python-client, in thepegana_api_clientpackage), plus the stable v0.1 receipt-verification surface (pegana_sdk). Types come from the OpenAPI 3.1 spec — the source of truth: https://api.pegana.xyz/openapi.json.
⚠️ Not on PyPI yet.
pip install pegana-sdkreturns 404 — the package has not been published. Install from source until it is. (The TypeScript sibling@peganahq/sdk-tsis published.)
# from a checkout of this repo
pip install -e sdk/python/
from pegana_api_client import Client
from pegana_api_client.api.assets import list_assets
with Client(base_url="https://api.pegana.xyz") as client:
envelope = list_assets.sync(client=client)
for asset in envelope.data:
print(asset.symbol, asset.state, asset.discount)
Live feed over WebSocket:
import asyncio
from pegana_sdk.ws import peg_feed
async def main():
async for frame in peg_feed():
if frame["op"] == "update":
print(frame["asset"], frame["payload"]["state"])
asyncio.run(main())
The API is public and keyless — no key needed for reads. Full docs: https://docs.pegana.xyz.
Install from a clone
pip install ./sdk/python
Full typed client (v0.2.0)
from pegana_api_client import Client, AuthenticatedClient
from pegana_api_client.api.assets import list_assets
# Public read endpoints (tag-organized under pegana_api_client.api.*)
with Client(base_url="https://api.pegana.xyz") as client:
assets = list_assets.sync(client=client) # ApiListAssetCard envelope
if assets:
for a in assets.data: # list envelope → .data
print(a.symbol)
# Authenticated surface (/v1/me/*) — token via POST /v1/auth/telegram
with AuthenticatedClient(base_url="https://api.pegana.xyz", token=token) as client:
... # e.g. pegana_api_client.api.me.get_me.sync(client=client)
sync_detailed() / asyncio_detailed() variants return the full Response
(status + parsed body). LIST endpoints return the ADR-0043 envelope
{ ok, generated_at, count, data } — read .data; SINGLE resources are bare.
Money fields are exact decimal STRINGS (never floats — parse with decimal).
Regenerate with openapi-python-client generate --url https://api.pegana.xyz/openapi.json --meta none.
Receipt verification (v0.1 surface, still supported)
from pegana_sdk import PeganaClient
with PeganaClient() as client:
# One-shot receipt fetch. The response is NESTED:
# { alert, evidence, evidence_status }.
receipt = client.get_audit("4cf3a1d2-7e9b-4b3a-9a7c-9d1e2f3b4c5d")
print(receipt["alert"]["id"])
print(receipt["evidence"]["receipt_sha256"])
# Recent index (last 50, excluding PEGGED)
recent = client.get_audit_index(limit=50, exclude_pegged=True)
# On-chain commitment — None unless the alert was anchored (SPL Memo
# commits are cost-gated to high-severity transitions, so None is common).
oc = client.get_onchain(receipt["alert"]["id"])
if oc:
print(oc["tx_sig"], oc["explorer_url"])
# Lightweight sha256 verification (NOT cryptographic replay — use the
# pegana-replay CLI for that).
v = client.verify_alert(
receipt["alert"]["id"], receipt["evidence"]["receipt_sha256"]
)
print(v.ok) # True
Module-level convenience functions backed by a default client:
from pegana_sdk import get_audit, get_audit_index, get_onchain, verify_alert
Options
PeganaClient(
base_url="https://api.pegana.xyz", # default
client=httpx.Client(timeout=30.0), # inject for retries / pooling
timeout=15.0, # used if no client passed
)
Live peg feed (WebSocket)
/v1/ws is the one endpoint OpenAPI can't model (it's an upgrade stub in the
spec), so the SDK ships a small async helper for it — an async iterator over the
live feed:
import asyncio
from pegana_sdk import peg_feed
async def main():
async for frame in peg_feed(["USDC", "JLP"]): # omit the list to receive all
if frame["op"] == "update":
print(frame["asset"], frame["payload"])
elif frame["op"] == "heartbeat":
print("engine alive", frame["ts"])
asyncio.run(main())
The server pushes {"op":"update", "asset", "payload"} and {"op":"heartbeat", "ts"}; passing assets subscribes to that filter on connect. Backed by the
websockets package (a declared dependency) and verifies TLS against certifi.
Roadmap
- v0.2.0 ✅ — OpenAPI-generated full coverage of every
/v1endpoint viaopenapi-python-client(typed models + sync/async httpx client inpegana_api_client). The v0.1pegana_sdkreceipt surface is retained. - v0.3.0 ✅ — version sync (pegana_sdk + pegana_api_client unified under
one package), classifier cleanup. Not yet on PyPI — install from source:
pip install -e sdk/python/. - v1.0.0 — API stability commitment, semver guarantees. Will coincide with PyPI publication.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pegana_sdk-0.3.0.tar.gz.
File metadata
- Download URL: pegana_sdk-0.3.0.tar.gz
- Upload date:
- Size: 68.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
95b8073107a345dcf1bc73df7ba1f8cd6bd59a4c41f01774d7089347159427e7
|
|
| MD5 |
1396e1eec74c6c944ea7dcd861993d97
|
|
| BLAKE2b-256 |
3264136c81437627a01e8c314a6f33bf58fb8c2455c18c71d8a1eb4cbe516f4f
|
File details
Details for the file pegana_sdk-0.3.0-py3-none-any.whl.
File metadata
- Download URL: pegana_sdk-0.3.0-py3-none-any.whl
- Upload date:
- Size: 162.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8fd6d581b95b5871bc5d643370ef3823761370bd298932ca66e411f8b46f4610
|
|
| MD5 |
ad8b3efc1d4f590e1fc715a6e1b432a3
|
|
| BLAKE2b-256 |
c1428229fc416f93ff0e01a4c5c9a75e8e758d2307dc1c88f61cd4a129797856
|