Python SDK
Install reqlo and enforce decisions from Python 3.10+, sync or async, with approvals, delegations and webhook verification.
The server-side Python SDK. Python 3.10+, no dependencies, sync and asyncio. Install reqlo-sdk; import reqlo.
pip install reqlo-sdkEnforce before acting
enforce returns only on allow. A deny or approval requirement raises ReqloDeniedError; a timeout, network
failure or HTTP error raises another ReqloError. Either way the code after it never runs.
import os
from reqlo import Reqlo, ReqloDeniedError
reqlo = Reqlo(api_key=os.environ["REQLO_API_KEY"])
def read_document(session, document_id):
doc = documents.get(document_id) # authoritative facts from your database
try:
reqlo.enforce(
agent={"id": "<YOUR_AGENT_ID>"},
subject={"id": session.user_id, "kind": "user"}, # from your verified session
action="documents.read",
resource={"type": "document", "id": doc.id, "attributes": {"owner_id": doc.owner_id}},
context={"document_classification": doc.classification},
)
except ReqloDeniedError as denied:
return {"error": "Not allowed to read this document.", "reason": denied.decision["reason_code"]}
# Any other ReqloError propagates: the document is not read.
return {"content": doc.content}Use authorize(...) when you want the decision without raising. Act only when decision["decision"] == "allow".
Async
AsyncReqlo has the same methods for asyncio (FastAPI, the OpenAI Agents SDK, LangGraph). Requests run in a worker
thread, so the event loop isn't blocked.
from reqlo import AsyncReqlo
reqlo = AsyncReqlo(api_key=os.environ["REQLO_API_KEY"])
decision = await reqlo.enforce(agent={"id": "<YOUR_AGENT_ID>"}, action="documents.read",
resource={"type": "document", "id": "doc_831", "attributes": {"owner_id": "usr_94"}},
subject={"id": "usr_94", "kind": "user"}, context={"document_classification": "internal"})Approvals and delegations
decision = reqlo.authorize(**request)
if decision["decision"] == "approval_required":
save_for_later(request, decision["approval"]["id"]) # redeem later with approval_id=... once approved
approval = reqlo.approvals.retrieve(approval_id) # pending, approved, rejected, expired or consumed
pending = reqlo.approvals.list(status="pending")["data"]
grant = reqlo.delegations.create("<YOUR_AGENT_ID>", {"id": "usr_94", "kind": "user"}, ["calendar.schedule"], "2026-12-31T00:00:00Z")
reqlo.delegations.list(subject_id="usr_94")
reqlo.delegations.revoke(grant["id"])See Human approvals and Delegated access.
Webhooks
Verify the signature on the exact raw body before trusting an event:
from reqlo import webhooks, ReqloSignatureError
@app.post("/webhooks/reqlo")
async def receive(request: Request):
body = await request.body()
try:
event = webhooks.construct_event(body, request.headers.get("Reqlo-Signature"), os.environ["REQLO_WEBHOOK_SECRET"])
except ReqloSignatureError:
return Response(status_code=400)
if event["type"] == "approval.requested":
notify_approvers(event["data"]["object"]["id"])
return Response(status_code=204)Configuration
| Option | Default | Description |
|---|---|---|
api_key | required | Your project API key (rq_test_…) |
timeout | 3.0 | Seconds per attempt |
max_retries | 2 | Retries for 429 and 5xx, with backoff |
base_url | https://api.reqlo.io/v1 | HTTPS only; loopback HTTP for development |
Timeouts and network errors are never retried, and creating a delegation is never retried, because a request that timed out may have reached ReQlo.
Errors
| Exception | When |
|---|---|
ReqloDeniedError | enforce got deny or approval_required. .decision has the reason. |
ReqloAPIError | HTTP error. .status, .code and .request_id. |
ReqloTimeoutError, ReqloNetworkError | No answer. |
ReqloResponseError | A malformed response. Never permission to act. |
ReqloConfigurationError | Invalid options or arguments. |
ReqloSignatureError | A webhook signature is missing, invalid or too old. |
All extend ReqloError.
Something wrong or unclear? Report an issue with this page.