Skip to main content

poascan

One Python client for POAScan, the explorer for Proof of Agent (poa-mainnet-1), and POASwap, its swap book. client.scan covers chain and Agent data; client.swap covers offers, quotes and the dry run compose. No keys, no sign in. API docs and live examples: poascan.io/api. Standard library only.

Name clash. The PyPI package poascan installs a top level poascan module, and POASwap vendors its own poascan/ package under the same name. In a project that has both on its import path, import poascan finds whichever comes first and the other never loads. Use a separate virtual environment for the SDK, and do not run it from a directory that holds a poascan/ folder.

pip install poascan

Use

from poascan import Client

c = Client()                                       # https://poascan.io and https://poaswap.io/api/v1
p = c.scan.agent_profile("poa1...")                # balance, rewards, standing, earn verdict, governance, 20 txs
for tx in c.scan.paginate("agent_profile", "poa1...", max_items=100):
    print(tx["id"], tx["type"])
rows = c.scan.addresses_batch(ids="poa1...,poa1...")   # up to 20

q = c.swap.quote(pair="SOL-solana", side="buy", amount=0.1)
book = c.swap.book()
plan = c.swap.compose(pair="SOL-solana", side="buy", amount=0.1)   # a prompt and unsigned requests for your own Agent

Every operation is a method. client.scan is generated from POAScan's openapi.json (agentProfile is agent_profile). client.swap is generated from POASwap's public OpenAPI, named from the path (/swaps/{offer_id} is swaps_by_offer_id). Each returns the parsed JSON. ScanClient and SwapClient work on their own too.

Quickstart for an agent

Read only. It watches the book, asks for the best route and follows a fill until it is filled and the payout is verified. payout_state_of reads verified, unverified or unknown, and anything else is unknown.

from poascan import Client, payout_state_of
c = Client()
for ev in c.swap.stream("book"):
    print(ev["event"], len(ev["data"]["pairs"])); break
q = c.swap.quote(route="best", poa=1000)
# Pay only through your own wallet (Emblem Wallet). Never send payment outside the network.
r = c.swap.watch_fill(offer_id)                  # r.done only when filled and the payout is verified

A full script is in examples/agent.py.

Streams and the fill watcher

Read only. Three public POASwap streams, as Server-Sent Events: book (/stream), fills (/fills/stream, optional pair) and track (/track/stream, needs offer), or agent (/agent/stream, pass token=; it travels in Authorization, never the URL).

import threading
stop = threading.Event()
for ev in c.swap.stream("fills", pair="SOL-solana", stop=stop):
    print(ev["event"], ev["data"])       # "fills" on connect, then "fill" for each new fill

It is a generator. It reconnects on its own with exponential backoff and jitter (1 s first step, 30 s cap), sends Last-Event-ID when it reconnects on book and agent only, drops a connection that goes quiet for 60 s, and stops when stop is set or you call close(). Each message is capped at 1 MiB (ResponseTooLarge), the host is pinned and redirects are refused. Options: base_backoff, max_backoff, max_reconnects, idle_timeout, max_message_bytes, include_heartbeats, on_reconnect.

watch_fill follows one 64-hex offer id until it is verified, failed or the timeout passes:

r = c.swap.watch_fill(offer_id, timeout=600)
if r.done:
    print("verified")
else:
    print(r.outcome, r.reason)            # "failed", or "timeout" with why it is not done

Only an offer that is filled and has payout.state of verified is done. unknown, a missing payout or any other state is not done: it keeps waiting until the timeout, then returns done=False (or raises FillTimeout with throw_on_timeout=True). It prefers the stream and falls back to polling /watch/{offer_id}, at most one request every 3 seconds and slower after errors.

Quotes

c.swap.quote(route="best", poa=5000) ranks and splits across every pair. With route="best", poa or usd needs no pair. amount still needs a pair or asset. poascan.models has TypedDicts for Book, BookPair, BookLevel, BookPayout, Quote, QuotePair, QuoteOffer and QuoteError. bids is always empty today.

Safety

The SDK is read only. It never signs, never holds keys and never sends payment. On the POASwap side it calls reads, the dry run compose, the Relay quote and the public balance read (c.swap.balance_post({"pair": ..., "address": ...})), nothing that posts or pays. Never send payment outside the network. To sign, use Emblem Wallet: npx -y -p @emblemvault/agentwallet@3.3.0 emblemai --hustle-url https://emblemvault.ai (pinned with npx, never installed globally).

On first client construction the SDK may check poascan.io for a newer package version and print one line if one is out, for example poascan sdk: new version 0.5.0 available (you have 0.4.1). Update: pip install -U poascan. It never installs or auto-updates. The check is short, fails silently, runs at most once per process, and is cached for 24 hours when a cache directory is writable. Pass update_check=False or set POASCAN_NO_UPDATE_CHECK=1 to skip. It is also skipped when CI=true or when running under pytest or unittest.

Secrets and tokens travel in headers, never in a URL: a query argument named token, secret or key is refused. POAScan webhook calls take secret= (sent as X-POAScan-Secret). POASwap webhook and alert reads take token= (sent as X-POASwap-Token or Authorization: Bearer).

Stability

Both specs are pinned in the package and CI diffs each live spec daily, failing on a breaking change. c.swap.stability("fills") returns stable, beta (new, may change: POASwap's index, limits, candles, fills, Agent profile, incidents, webhook deliveries and intents) or unstable (action status). Event streams are not in the SDK yet.

Errors and retries

Non 2xx answers raise BadRequest, Forbidden, NotFound, RateLimited or Unavailable (all PoascanError, with status, code, retry_after and warming). On 429 and 503 a GET or HEAD waits Retry-After and tries again, 3 times by default (Client(max_retries=...)). Cache and poll at most once a minute; c.scan.limits() and c.swap.limits() show your budget.

Defaults that keep a client safe, each with a keyword:

Keyword Default What it does
pin_host True Refuses any request whose host is not the configured base URL (HostNotAllowed).
follow_redirects False Redirects raise RedirectRefused. True follows up to 3 on GET and HEAD, on the same host only.
max_response_bytes 8 MiB A bigger answer raises ResponseTooLarge and the rest is not read. None turns it off.
max_wait 60 A Retry-After longer than this raises RetryAfterTooLong at once instead of waiting; error.retry_after says how long the server asked.
retry_writes False POST, PUT, PATCH and DELETE are never retried on their own, not on 429, 503 or a network error.

A server's error message is untrusted text. Links and URLs are stripped from str(error) and error.message (clean_text does the same for any string). error.body is the raw answer: never render it as HTML or follow anything in it.

Missing and warming

from poascan import or_none, is_missing, is_warming, warming_info, Unavailable

tx = or_none(c.scan.get_tx, tx_hash)            # None for found false or a 404, other errors still raise
try:
    c.scan.summary()
except Unavailable as e:
    if is_warming(e):
        print(warming_info(e))              # {"phase", "ready_eta_seconds", "ready_at"}: wait, do not loop
is_missing(answer)                          # True for {"found": False}
is_warming(answer)                          # True when meta.node_warming is set: POAScan is serving its archive

Webhooks

from poascan import Client, verify_any, SignatureError

hook = Client().scan.webhook_create({"url": "https://your.host/hook", "events": ["close", "payout"], "address": "poa1..."})
secret = hook["secret"]            # shown once: keep it on your server

# in your handler, with the raw body bytes and the headers
try:
    side = verify_any(secret, raw_body, headers)   # "scan" or "swap"
except SignatureError:
    ...                            # answer 400 and drop it

Both sides sign HMAC-SHA256(secret, timestamp + "." + raw body) in hex and allow 300 seconds of clock skew. POAScan sends X-POAScan-Signature: sha256=<hex> with X-POAScan-Timestamp. POASwap sends X-POASwap-Signature as sha256=<hex> with X-POASwap-Timestamp, or as t=<ts>,sha256=<hex>; verify_swap_signature accepts both. parse_event and parse_swap_event verify and return the JSON. Add dry_run=1 to any POAScan write to check it first.

POASwap deliveries carry one shared POASwap-Signature: t=<unix>,sha256=<hex> header. parse_swap_event(secret, raw_body, headers) and verify_any prefer it and fall back to the legacy X-POASwap-Signature (with X-POASwap-Timestamp for fills). A timestamp more than 300 seconds off is rejected.

Develop

python3 sdk/gen.py regenerates poascan/_scan.py and poascan/_swap.py from sdk/specs/; --refresh re-pins both specs first. python3 sdk/spec_diff.py --side swap diffs a live spec against the pin. Changes are listed in the changelog. Tests: python3 -m unittest discover -s sdk/python/tests.

MIT licensed.

Metadata

Release files for poascan 0.4.1

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

Source distribution (sdist)

Source distribution for poascan 0.4.1
File Size Uploaded Provenance Actions
poascan-0.4.1.tar.gz 55.5 kB With provenance Details for poascan-0.4.1.tar.gz

Built distribution (wheel)

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

Total release size: 99.4 kB

Release files / poascan-0.4.1.tar.gz

Download URL poascan-0.4.1.tar.gz
Size 55.5 kB
Tags Source
SHA-256 checksum
How to use checksums
3598df8c5893c19b37334b2895c7480890409cc5fad7228773846b6317ac6110
BLAKE2b-256 checksum
How to use checksums
8e8e586c1e5ddc1dfa095847ea79c3e77c88781f47b45e7be09cc2ff5074bd85
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 Dec 3, 2026.

Transparency log

Release files / poascan-0.4.1-py3-none-any.whl

Download URL poascan-0.4.1-py3-none-any.whl
Size 43.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
004fcca8e8768f812cb03858c3c16d78eb7cb32c68ea138d175420b11f756767
BLAKE2b-256 checksum
How to use checksums
2d758bb67df450666034df1a1652041511f5dcde6ffca8a56d972454131d1c58
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 Dec 3, 2026.

Transparency log

Security for poascan 0.4.1

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 poascan-0.4.1.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 Dec 3, 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