Skip to content

Reference

Python SDK

Async operations for OAuth and managed-secret credentials. Provider credentials are never returned to application code.

The Python SDK ships as the alter-sdk package on PyPI. Python 3.11+.

Terminal window
pip install alter-sdk
from alter_sdk import App, Agent, HttpMethod, Provider

The SDK exposes two top-level clients. They share the request surface but differ in principal and identity scoping.

Both classes expose async network and lifecycle methods. Always close them (await app.close()) or use them as async context managers.

async with App(api_key="alter_rk_…") as app:
page = await app.list_grants()

The constructor accepts an api_key argument; application code is responsible for sourcing it. The convention is to read it from the process environment:

VariableUsed byDescription
ALTER_API_KEYapplication code (typical app workload)Conventional name when the application owns one app-level key.
AGENT_API_KEYapplication code (agent workload)Conventional name when the workload runs as a managed agent.

For agent workloads, the convention is to read AGENT_API_KEY in application code:

import os
from alter_sdk import Agent
agent = Agent(api_key=os.environ["AGENT_API_KEY"])
  • Network and lifecycle methods are async. Constructors, properties, with_constraints(), get_agent(), trace(), and is_valid_key() are synchronous.
  • Response and input models are Pydantic objects with snake_case fields matching the wire format. Most are frozen; APICallAuditLog, UserSpan, and EmitSpansResult are mutable.
  • Methods that retrieve tokens never return the token plaintext. The SDK injects it into the outbound request.
  • Public exceptions inherit from AlterSDKError. See Errors.

Report an issue with this page

Necessary

Required for sign-in, security, authorization, and remembering your choices.

Always active

Analytics

Helps us understand which product and documentation features are useful.

Performance diagnostics

Uses performance tracing and privacy-masked session replay to diagnose problems.

You can change these choices at any time from Cookie settings.