Skip to Content
SDKsPython

Python SDK

The relynt package provides a typed client for the Relynt authorization gateway in Python, with both sync and async support.

Install

pip install relynt

Quick start

import os from relynt import RelyntClient client = RelyntClient( base_url=os.environ["RELYNT_API_BASE_URL"], agent_secret=os.environ["RELYNT_AGENT_SECRET"], ) result = client.request_action( action="update_deal", resource="crm:deal:123", payload={ "amount": 52000, "previous_amount": 50000, }, ) print(result.decision) # "allow" | "deny" | "pending_approval" print(result.receipt_id)

Handling approvals

When the policy requires human approval, the decision will be "pending_approval" and an approval_id is returned. Use poll_approval to wait for the decision:

if result.decision == "pending_approval": approval = client.poll_approval( approval_id=result.approval_id, timeout_ms=300_000, # 5 minutes ) print(approval.status) # "approved" | "denied" | "expired" print(approval.decided_by) # e.g. "slack:U12345"

Async support

All methods have async variants:

import asyncio from relynt import RelyntClient client = RelyntClient( base_url="https://your-relynt-instance", agent_secret=os.environ["RELYNT_AGENT_SECRET"], ) async def main(): result = await client.async_request_action( action="update_deal", resource="crm:deal:123", payload={"amount": 52000}, ) print(result.decision) asyncio.run(main())

Idempotency

Pass an idempotency_key to prevent duplicate processing:

result = client.request_action( action="update_deal", resource="crm:deal:123", payload={"amount": 52000}, idempotency_key="my-unique-key-abc123", )

Error handling

The SDK raises typed exceptions:

from relynt import ( RelyntClient, AuthenticationError, RequestError, ApprovalTimeoutError, NetworkError, ) try: result = client.request_action(...) except AuthenticationError: # Invalid or expired agent secret (401/403) ... except RequestError as e: # Bad request (4xx) print(e.status_code, e.code) except NetworkError: # Gateway unreachable or timeout ...

API reference

RelyntClient(base_url, agent_secret, *, timeout_s=30.0)

ParameterTypeRequiredDescription
base_urlstrYesRelynt gateway URL
agent_secretstrYesAgent credential from rotation
timeout_sfloatNoRequest timeout in seconds (default: 30)

client.request_action(...)

Returns ActionResult:

FieldTypeDescription
decisionstr"allow", "deny", or "pending_approval"
receipt_idstrUUID of the signed receipt
approval_idstr | NonePresent for pending_approval
tool_responsedict | NoneConnector response if executed
reasonstr | NonePolicy reason
risk_levelstr | None"low", "medium", or "high"
policy_versionstr | NonePolicy version used

client.poll_approval(...)

Returns ApprovalResult:

FieldTypeDescription
statusstr"approved", "denied", or "expired"
decided_bystr | NoneWho decided
decided_atstr | NoneISO 8601 timestamp

Async variants

  • client.async_request_action(...) — async version of request_action
  • client.async_poll_approval(...) — async version of poll_approval

Environment variables

VariableDescription
RELYNT_API_BASE_URLGateway URL
RELYNT_AGENT_SECRETAgent credential (from dashboard rotation)
RELYNT_AGENT_IDAgent UUID (informational)
RELYNT_ORG_IDOrganization UUID (informational)
Last updated on