Python SDK

Authorization

Ask Scute's engine whether a user may do an action on a resource, in one call or in batches, and list permissions and authorized users.

scute.authz asks Scute's engine, with the secret key, what a user may do. Roles, permissions and conditions come from the app's policy, which you manage in the dashboard or the API.

decision = scute.authz.check(    user_id=session.user_id,    action="refund",    resource="invoice:42",    context=session.authz_context(),)if decision.allowed:    ...

Check one action#

scute.authz.check(*, user_id, action, resource=None, context=None, challenge=None, approval=None) -> Decision
user_idstrrequired
The app user.
actionstrrequired
The action, for example refund. With a resource of type invoice, the permission checked is invoice:refund.
resourcestr | dict | None
A string "type:key" such as "invoice:42", a type alone such as "invoice", or a dict such as {"type": "invoice", "attributes": {"amount": 100}}.
contextdict | None
Request facts for conditions (context.*). Always include session.authz_context().
challengestr | None
Sent in the body as challenge, for a check that follows a step-up.
approvalstr | None
Sent in the body as approval, for a check that follows a reviewer's approval.

Arguments left as None (and an empty context) are not sent. The call is POST /v1/auth/:app_id/authz/check.

Support sessions

Pass session.authz_context() in context on every check made for a request. When someone is signed in as the user, it adds {"impersonated": True, "actor": ...} and the engine refuses permissions marked "not while impersonating". The FastAPI and Flask helpers do this for you.

Decision#

Decision is a frozen dataclass built from the API's answer.

FieldTypeMeaning
decisionstrallow, deny, allow_with_step_up or allow_with_approval
reasonstr or NoneWhy, for example role_grant or no_role_grants_permission
permissionstr or NoneThe permission slug checked, for example invoice:refund
roleslist[str]Roles that granted it
explanationstr or NoneA readable sentence
step_updict or NoneStep-up details on allow_with_step_up
approvaldict or NoneApproval details on allow_with_approval
saystr or NoneA line for the person, on an agent's checks
rawdictThe full API answer
PropertyTrue when
alloweddecision == "allow" only
needs_step_updecision == "allow_with_step_up"
needs_approvaldecision == "allow_with_approval"

allowed is False for a step-up or approval answer. Treat those as "not yet": the user verifies, or a reviewer approves, and you check again.

if decision.allowed:    do_refund()elif decision.needs_step_up:    ...  # ask the user to verify, then check againelif decision.needs_approval:    ...  # a reviewer approves, then check againelse:    raise PermissionError(decision.explanation)

Check many at once#

scute.authz.check_batch(checks: list[dict]) -> list[Decision]

Each dict has the same keys as check (user_id, action, resource, context, ...). None values are dropped. At most 100 checks per call (Authz.BATCH_LIMIT); more raises ValueError before any request. It returns one Decision per entry in the API's results.

decisions = scute.authz.check_batch([    {"user_id": user_id, "action": "read", "resource": "invoice:42"},    {"user_id": user_id, "action": "refund", "resource": "invoice:42"},])

A user's permissions#

scute.authz.permissions(user_id: str, resource: str | None = None)

GET /v1/auth/:app_id/authz/users/:user_id/permissions, optionally for one resource. Returns the API's JSON.

Who may do an action#

scute.authz.authorized_users(*, action: str, resource: str | None = None, limit: int | None = None, offset: int | None = None)

GET /v1/auth/:app_id/authz/authorized-users. Returns the API's JSON.

Not in this SDK#

  • Filters (which rows of a type a user may act on): call POST /v1/auth/:app_id/authz/filter with scute.request. See the API reference.
  • Policy import, role assignment and access requests: use the API.
  • Offline decisions: see Local decisions.