Minimal Python client for the Sluice matcher API, on-chain event subscriptions for Casper.
pip install sluice-client
# optional, only if you need the live WebSocket stream:
pip install 'sluice-client[stream]'Mirrors the @sluice/client TypeScript surface so the mental model is portable across languages.
fromsluice_clientimportSluiceClientsluice=SluiceClient() # https://sluice.unitynodes.com/api# 1. inspect subssubs=sluice.subs.list()
print(f"{len(subs)} subs, {sum(1forsinsubsifs['active'])} active")
# 2. dry-run a predicate before paying CSPRprobe=sluice.predicate.validate({"and": [
{"field": "amount", "op": "gte", "value": "100000000000000"}
]})
print(f"would match {probe['matches']}/{probe['total_scanned']} (~{probe['estimated_per_day']}/day)")
# 3. why didn't this match?, per-condition tracewhy=sluice.predicate.explain(predicate, event)
forstepinwhy["trace"]:
print("✓"ifstep["pass"] else"✗", step["reason"])
# 4. fire synthetic webhooks at your receiver, no CSPR spentsluice.sandbox.dispatch("https://my.app/webhook", count=5)
# 5. live stream of every delivery the matcher fans out (requires `pip install websockets`)forenvinsluice.stream.subscribe(sub_id=42):
print(env["type"], env["data"])fromsluice_clientimportverify_hmac_signatureifnotverify_hmac_signature(raw_body, request.headers["X-Sluice-Signature"], SECRET):
returnResponse(status=401)Works in FastAPI / Flask / Django, wherever you have access to the raw bytes (FastAPI: raw = await request.body(); Flask: request.get_data(cache=True, as_text=False)).
sluice=SluiceClient(base_url="http://localhost:8080/api")| Namespace | Method |
|---|---|
sluice | health(), snapshot(), metrics_text(), badge_url(metric), openapi_url() |
sluice.subs | list(), get(id), replay_last(id, n=10), ics(id), og(id) |
sluice.predicate | validate(predicate), explain(predicate, event) |
sluice.sandbox | dispatch(webhook, predicate=None, count=3) |
sluice.chain | head() |
sluice.stream | subscribe(sub_id=None), yields envelope dicts |
sluice.tx | test_webhook(sub_id), replay(event_hash) |
Errors raise SluiceApiError with .status and .body attributes.
MIT