Scute is the one object you create. It holds the app id, the secret key, an HTTP connection pool and the cached signing keys. Create one per process and reuse it.
from scute import Scutescute = Scute()Constructor#
Scute(app_id=None, secret=None, base_url=None, *, timeout=10.0, transport=None, client_ip=None)Attributes: app_id, has_secret (bool), client_ip, tokens, users, sessions, authz, agents, http. repr() masks the secret.
Synchronous only#
All calls are blocking and run on an httpx.Client. There is no async client. In FastAPI, the dependencies in scute.contrib.fastapi are plain functions, so FastAPI runs them in its thread pool.
Retries and timeouts#
- A request that fails at the transport level (connection refused, timeout) is retried once when it is idempotent. GET is idempotent by default; the SDK also marks PATCH updates and authorization checks as idempotent.
- After the retry, or on a non-idempotent call, it raises ConnectionError.
- A response outside 2xx raises APIError with status, code (the API's error_code) and body. See Errors.
Every request sends User-Agent: scute-python/0.2.0 and Accept: application/json.
The end user's IP address#
When your server creates or signs in a user with the secret key, Scute only sees your server's address. Pass the person's address and Scute checks that sign-in against the workspace's IP rules; without it, the sign-in is not checked. On other secret-key calls the address is recorded on sessions and audit events.
The SDK sends it as X-Scute-Client-IP on secret-key calls. It never sends it on calls made with a user's session (sessions.current_user, refresh, sign_out).
# Per request: a copy that shares the connection pool and key cachescute.with_client_ip(request.remote_addr).users.create("ada@example.com")# A client that only ever acts for one personScute(client_ip="203.0.113.24")# One low-level callscute.request("POST", scute.auth_path("/users"), {"identifier": "ada@example.com"}, client_ip="2001:db8::1")The value must be one IPv4 or IPv6 address. Surrounding spaces are trimmed. A range, a list, a hostname or an address with a zone (%) raises ValueError. None or a blank string sends nothing.
with_client_ip returns a copy. Close the original client, not the copies. The FastAPI and Flask helpers fill the address in from the request.
Low-level calls#
For endpoints the SDK has no method for, use the client's request helpers. They apply the same credentials, retries and errors.
scute.request(method, path, body=None, idempotent=None, *, client_ip=None)scute.user_request(method, path, *, access=None, refresh=None, body=None)- request sends the secret key as Authorization: Bearer. Raises ConfigurationError without a secret.
- user_request sends a user's access token as X-Authorization and a refresh token as X-Refresh-Token. With neither, it makes a public call.
- Both return the decoded JSON body (or None for an empty body).
Path helpers, each with the app id URL-escaped:
| Method | Returns |
|---|---|
| scute.auth_path(rest) | /v1/auth/:app_id + rest |
| scute.apps_path(rest) | /v1/apps/:app_id + rest |
| scute.app_path(rest) | /v1/:app_id + rest |
| scute.esc(value) | value URL-escaped for a path segment |
snapshot = scute.request("GET", scute.apps_path("/authz/snapshot"))Closing#
scute.close() closes the connection pool.