Python
Python SDK
The official Python SDK for integrating Attest into your AI agents.
Installation
terminal
pip install attest-sdk
Quick Start
agent.py
from attest import Attest # Initialize the client client = Attest(api_key="sk_live_...") # Validate an action decision = client.validate( action="send_email", payload={ "to": "customer@example.com", "subject": "Your order has shipped", "body": email_content } ) if decision.approved: send_email(decision.payload) elif decision.escalated: print(f"Pending review: {decision.review_id}") else: print(f"Blocked: {decision.reason}")
Async Support
The SDK supports async/await for high-throughput applications:
async_agent.py
from attest import AsyncAttest client = AsyncAttest(api_key="sk_live_...") async def process_action(action, payload): decision = await client.validate( action=action, payload=payload ) return decision
Configuration
| Option | Type | Default | Description |
|---|---|---|---|
api_key | str | Required | Your Attest API key |
timeout | float | 30.0 | Request timeout in seconds |
max_retries | int | 3 | Max retry attempts |
base_url | str | api.attest.ai | API base URL |
LangChain Integration
Use the built-in LangChain callback handler:
langchain_example.py
from attest.integrations.langchain import AttestCallbackHandler from langchain.agents import AgentExecutor handler = AttestCallbackHandler(api_key="sk_live_...") agent = AgentExecutor( agent=my_agent, tools=my_tools, callbacks=[handler] )
Error Handling
error_handling.py
from attest import Attest from attest.exceptions import ( AttestError, ValidationError, RateLimitError, AuthenticationError ) try: decision = client.validate(action="...", payload={...}) except RateLimitError as e: print(f"Rate limited. Retry after {e.retry_after}s") except AuthenticationError: print("Invalid API key") except AttestError as e: print(f"Attest error: {e}")
Requirements
- Python 3.8+
- httpx >= 0.24.0
- pydantic >= 2.0