pegana-sdk
Typed Python client for the Pegana peg-risk oracle API.
Asset and state responses may carry market_observed_at, the timestamp of the
latest market price tick. Their state_reason may include market_unavailable,
market_reference_divergence, depth_below_floor, or premium_hold_timeout.
Webhook receivers can call pegana_sdk.verify_webhook(headers, body, pubkeys_b64)
with the exact raw body and active keys from /v1/meta/webhook-keys. It
requires a valid v2 signature when that header is present, accepts legacy
v1 only when v2 is absent, and enforces a 300-second replay window.
v0.4.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.
Install with
pip install pegana-sdk. The latest release on PyPI may lag this source; see CHANGELOG.md for what each version contains.
# 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:
# discount = 1 - market/intrinsic: positive = trading below fair value,
# negative = premium. It is None until the asset has a snapshot.
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
from pegana_api_client import Client
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)
# Every endpoint is public and read-only; the open-source API has no /v1/me/*
# or /v1/auth/* surface (receipts live under /v1/audit).
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. Published on PyPI as
pegana-sdk 0.3.0. Install withpip install pegana-sdk. - v0.4.0: regenerated from the current spec; drops the removed
/v1/alerts,/v1/auth/*and/v1/me/*modules (breaking). See CHANGELOG.md. - v1.0.0 — API stability commitment and semver guarantees.
Metadata
Release files for pegana-sdk 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pegana_sdk-0.4.0.tar.gz | 70.0 kB | Without provenance | Details for pegana_sdk-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pegana_sdk-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for pegana_sdk-0.4.0-py3-none-any.whl |
Total release size: 193.0 kB
Release files / pegana_sdk-0.4.0.tar.gz
| Download URL | pegana_sdk-0.4.0.tar.gz |
|---|---|
| Size | 70.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1899611ee6189f68b54d4e32b7b948d12b951960bdca703fabc0c6e1aaa1ce15
|
|
BLAKE2b-256 checksum How to use checksums |
3855a8eec750d454752b2e4df523a6b5445a5d07e67175d473a9496d486f7d6d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.12 {"installer":{"name":"uv","version":"0.12.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / pegana_sdk-0.4.0-py3-none-any.whl
| Download URL | pegana_sdk-0.4.0-py3-none-any.whl |
|---|---|
| Size | 123.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
df59f9fc80b830469b72f5554f774c06c09b7e703d89ddd879070a0c011e7afe
|
|
BLAKE2b-256 checksum How to use checksums |
780308b7aa49570fbfd6daccf7ee042c151d03a37dc46a67eee38fe30170c8d1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.12 {"installer":{"name":"uv","version":"0.12.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for pegana-sdk 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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.