Python SDK for the Allowly API
Project description
Allowly Python SDK
Async Python client for the Allowly runtime API.
MCP middleware ships inside this SDK: pip install 'allowly[fastmcp]', then from allowly.mcp import AllowlyMCPMiddleware. In TypeScript, it lives in the separate @allowly/mcp package.
Subject authorization pattern
Do not send raw user/customer PII to Allowly receipts unless you intentionally want it in your audit trail. Create one authorization per subject, store the returned authorization ID in your own app database, and use that ID for later checks.
import asyncio
import os
from allowly import Allowly
async def main() -> None:
async with Allowly(
api_key=os.environ["ALLOWLY_API_KEY"],
base_url=os.getenv("ALLOWLY_API_URL", "https://api.allowly.ai"),
) as allowly:
# Your app creates a stable internal subject ID.
subject_id = "subject_abc123"
# Store this in your app table, for example:
# allowly_authorizations(subject_id, policy_id, allowly_authorization_id, status)
authorization = await allowly.authorizations.create(
user_id=f"subject:{subject_id}",
policy_id="research_agent",
metadata={"source": "import"},
)
# Before the agent acts, check whether this action is allowed.
decision = await allowly.check(
authorization_id=authorization.authorization_id,
actions=["web.search"],
resource=f"subject:{subject_id}",
context={"stage": "research"},
)
if decision.results["web.search"].decision != "allow":
raise RuntimeError("Action is not authorized")
asyncio.run(main())
Local development against the documented Caddy endpoint requires the edge token that Cloudflare injects for public traffic. Pass it explicitly:
Allowly(
api_key=os.environ["ALLOWLY_API_KEY"],
base_url="http://localhost:8443",
dangerously_allow_insecure_base_url=True,
edge_token=os.environ["ALLOWLY_EDGE_TOKEN"],
)
The token is only sent when provided; never set it for the public API.
Inline authorization creation requires agent_id, actions, and expires_at.
Policy-based creation uses policy_id instead and rejects inline action or
decision-override fields.
Unavailable checks fail closed unless an action is explicitly mapped to
"fail_open" with fallback_by_action. Unmapped actions always fail closed.
For actions that need third-party approval, define the escalation rule on the
agent policy, create the authorization from that policy_id, and then resolve
returned escalation results with
await allowly.escalations.approve(escalation_id, resolved_by="manager:123")
or reject(...), then re-check before running the action.
If you need lookup by email later, import from_email from
allowly.identifiers and store from_email(email, pepper=APP_PII_PEPPER).
The helper trims and lowercases only, prefixes the result with email_hmac:v1,
and never sends the raw email or pepper to Allowly. Keep the pepper stable and
backed up; changing it changes derived user IDs. Keep raw names, emails,
documents, and profile URLs out of Allowly receipts unless those fields are
intentionally part of your audit record.
Do not add raw HTTP fallbacks in application code for APIs the SDK is missing. Patch this SDK first, then use the typed client from the app. That keeps the integration examples honest and makes SDK gaps visible early.
Offline receipt verification
Install allowly[verifier] to verify signed receipts locally. The extra uses
allowly-receipt-format>=3.0.0,<4.0.0, which verifies receipt wire format 3 (the package major equals the wire format). alg and
key_id are signed top-level fields, and signature is the base64url string.
Key-document fetching requires HTTPS by default. For the documented local
Caddy endpoint only, pass dangerously_allow_insecure_base_url=True and its
edge_token to fetch_keys_doc, matching the client options above.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file allowly-0.2.0.tar.gz.
File metadata
- Download URL: allowly-0.2.0.tar.gz
- Upload date:
- Size: 111.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
82974223ccf48e65680d7ca208f15c5b518435f2c3fa3d3bd3fb4131e49e1c8b
|
|
| MD5 |
7b6264120e203ce7137b5363db8685a0
|
|
| BLAKE2b-256 |
eac82af397db8d522bcc3537c66dbad79709839078a3c3f9af654a202c1aa72e
|
Provenance
The following attestation bundles were made for allowly-0.2.0.tar.gz:
Publisher:
publish.yml on Allowly-AI/allowly-sdk-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
allowly-0.2.0.tar.gz -
Subject digest:
82974223ccf48e65680d7ca208f15c5b518435f2c3fa3d3bd3fb4131e49e1c8b - Sigstore transparency entry: 2287096211
- Sigstore integration time:
-
Permalink:
Allowly-AI/allowly-sdk-python@1e48f0c2e6c3e64943ff0dbdd05a18ac75f69fd8 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Allowly-AI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1e48f0c2e6c3e64943ff0dbdd05a18ac75f69fd8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file allowly-0.2.0-py3-none-any.whl.
File metadata
- Download URL: allowly-0.2.0-py3-none-any.whl
- Upload date:
- Size: 16.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a6ac48a1f416af736231ede000cac0c565ca476d5278490155ff94f26f99755
|
|
| MD5 |
2e0e95ba9fcfcc825a0080c72b678016
|
|
| BLAKE2b-256 |
67362ab5485572cbbd5b8b68d1de99bf809c57f62796f497500821560351aa60
|
Provenance
The following attestation bundles were made for allowly-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on Allowly-AI/allowly-sdk-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
allowly-0.2.0-py3-none-any.whl -
Subject digest:
9a6ac48a1f416af736231ede000cac0c565ca476d5278490155ff94f26f99755 - Sigstore transparency entry: 2287096216
- Sigstore integration time:
-
Permalink:
Allowly-AI/allowly-sdk-python@1e48f0c2e6c3e64943ff0dbdd05a18ac75f69fd8 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Allowly-AI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1e48f0c2e6c3e64943ff0dbdd05a18ac75f69fd8 -
Trigger Event:
push
-
Statement type: