Skip to main content

grantex

Python SDK for the Grantex delegated authorization protocol — OAuth 2.0 for AI agents.

Grantex lets humans authorize AI agents with verifiable, revocable, audited grants built on JWT and the OAuth 2.0 model. This SDK provides a complete client for the Grantex API.

PyPI Python License

Install

pip install grantex

Quick start

from grantex import Grantex, AuthorizeParams

client = Grantex(api_key="YOUR_API_KEY")

# 1. Start the authorization flow
request = client.authorize(AuthorizeParams(
    agent_id="ag_01HXYZ...",
    user_id="usr_01HXYZ...",
    scopes=["files:read", "email:send"],
))

# Redirect the user to the consent page
print(request.consent_url)

# 2. Exchange for a grant token (after user approves)
token = client.tokens.create(auth_request_id=request.auth_request_id)
print(token.grant_token)  # RS256-signed JWT

# 3. Verify a token (online)
result = client.tokens.verify(token.grant_token)
print(result.scopes)  # ['files:read', 'email:send']

# 4. Revoke when done
client.tokens.revoke(token.grant_token)

Offline verification

Verify grant tokens without a network call using the public JWKS:

from grantex import verify_grant_token

verified = verify_grant_token(
    token="eyJhbGciOiJSUzI1NiIs...",
    jwks_url="https://api.grantex.dev/.well-known/jwks.json",
)

print(verified.scopes)       # ['files:read', 'email:send']
print(verified.principal_id) # 'usr_01HXYZ...'
print(verified.agent_did)    # 'did:web:...'

Features

Feature Description
Authorization flow client.authorize() — initiate consent, get grant tokens
Token management client.tokens.verify(), .revoke() — online verification and revocation
Offline verification verify_grant_token() — RS256 signature check against JWKS
Agent management client.agents.create(), .get(), .list(), .update(), .delete()
Grant management client.grants.list(), .get(), .revoke()
Multi-agent delegation client.grants.delegate() — scoped sub-grants with cascade revocation
Audit trail client.audit.log(), .list(), .get() — tamper-evident hash-chained log
Policy engine client.policies.create(), .list(), .update(), .delete()
Anomaly detection client.anomalies.list(), .detect()
Compliance client.compliance.summary(), .export_audit(), .export_grants(), .evidence_pack()
Webhooks client.webhooks.create(), .list(), .delete() + verify_webhook_signature()
Billing client.billing.status(), .checkout(), .portal()
SCIM 2.0 client.scim.create_user(), .list_users(), .get_user(), .update_user(), .delete_user()
OIDC SSO client.sso.create_config(), .get_config(), .login(), .callback()

Configuration

from grantex import Grantex

# Explicit API key
client = Grantex(api_key="gx_live_...")

# Or via environment variable
# export GRANTEX_API_KEY=gx_live_...
client = Grantex()

# Custom base URL (self-hosted)
client = Grantex(
    api_key="gx_live_...",
    base_url="https://auth.your-company.com",
)

# Custom timeout (seconds)
client = Grantex(api_key="gx_live_...", timeout=60.0)

The client also works as a context manager:

with Grantex(api_key="gx_live_...") as client:
    agents = client.agents.list()

Error handling

from grantex import Grantex, GrantexApiError, GrantexAuthError, GrantexNetworkError

client = Grantex(api_key="gx_live_...")

try:
    client.agents.get("ag_invalid")
except GrantexAuthError:
    # 401 — invalid or expired API key
    pass
except GrantexApiError as e:
    # Any other API error (4xx/5xx)
    print(e.status_code, e.code, e.message)
except GrantexNetworkError:
    # Connection failure, timeout, DNS error
    pass

Requirements

License

Apache 2.0

Metadata

Release files for grantex 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for grantex 0.1.1
File Size Uploaded Provenance Actions
grantex-0.1.1.tar.gz 23.4 kB Without provenance Details for grantex-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for grantex 0.1.1
File Interpreter ABI Platform Actions
grantex-0.1.1-py3-none-any.whl Python 3 none any Details for grantex-0.1.1-py3-none-any.whl

Total release size: 44.8 kB

Release files / grantex-0.1.1.tar.gz

Download URL grantex-0.1.1.tar.gz
Size 23.4 kB
Tags Source
SHA-256 checksum
How to use checksums
1da6ccfce5a308851cd06bab0ab9366e3e2fe8ac65ac35cd99fe25bb1b00c3b4
BLAKE2b-256 checksum
How to use checksums
385d680a20953ab907a090afe7876952a03a34680c73eb55e599049590098edf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.1

Release files / grantex-0.1.1-py3-none-any.whl

Download URL grantex-0.1.1-py3-none-any.whl
Size 21.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bddcb8487111baff1c88d65c69fb2f540e99bd5df4495d385455641bd58d5437
BLAKE2b-256 checksum
How to use checksums
1ecf4e149afde7629b3e492221a66969903b8143ca6c68be25116b443107ba97
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.1

Security for grantex 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page