Installation
Requirements
- Python 3.9 or higher
- httpx (sync HTTP client)
- PyJWT >= 2.8 with cryptography (for offline token verification)
pip install grantex.
Quick Start
Configuration
TheGrantex client accepts three keyword-only arguments:
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key | str | GRANTEX_API_KEY env var | Your Grantex API key. Required. |
base_url | str | https://api.grantex.dev | Override the API base URL (e.g. for self-hosted). |
timeout | float | 30.0 | Request timeout in seconds. |
API Key Resolution
The client resolves the API key in this order:- The
api_keykeyword argument passed to the constructor. - The
GRANTEX_API_KEYenvironment variable.
ValueError is raised.
Context Manager
TheGrantex client implements the context manager protocol. Using with ensures the underlying HTTP connection pool is properly closed when you are done:
client.close() manually:
Resource Clients
TheGrantex client exposes the following resource clients as attributes:
| Attribute | Type | Description |
|---|---|---|
agents | AgentsClient | Register, list, update, and delete agents |
grants | GrantsClient | Get, list, revoke, delegate, and verify grants |
tokens | TokensClient | Exchange, verify, and revoke tokens |
audit | AuditClient | Log, list, and retrieve audit entries |
webhooks | WebhooksClient | Create, list, and delete webhook endpoints |
billing | BillingClient | Subscription status, checkout, and portal |
policies | PoliciesClient | Create, list, update, and delete policies |
compliance | ComplianceClient | Summaries, exports, and evidence packs |
anomalies | AnomaliesClient | Detect, list, and acknowledge anomalies |
scim | ScimClient | SCIM 2.0 user provisioning and tokens |
sso | SsoClient | OIDC SSO configuration and login |
Standalone Functions
In addition to the client, the SDK exports standalone utility functions:Data Model Conventions
All response types are frozen dataclasses withsnake_case field names. Lists are returned as Python tuple objects for immutability.