Python SDK for the Bastion trust proxy
Project description
bastion-sdk
Python SDK for the Bastion trust proxy. Supports both sync and async usage.
Installation
pip install bastion-sdk
Requires Python 3.10+.
Quick Start
from bastion_sdk import BastionClient
with BastionClient("http://localhost:3000", api_key="your-project-api-key") as client:
print(client.health())
Async
from bastion_sdk import AsyncBastionClient
async with AsyncBastionClient("http://localhost:3000", api_key="your-key") as client:
print(await client.health())
Admin Operations
Use the admin API key (PROJECT_API_KEY) to manage agents, credentials, and policies.
Agents
# Create an agent (returns one-time agentSecret)
agent = client.create_agent("Support Bot", description="Handles refund requests")
agent_secret = agent["agentSecret"] # save this — shown only once
# List, get, update, delete
agents = client.list_agents()
agent = client.get_agent(agent["id"])
client.update_agent(agent["id"], isActive=False)
client.delete_agent(agent["id"]) # soft-delete
Credentials
# Store a credential (encrypted at rest, raw value never returned)
credential = client.create_credential(
name="Stripe Production",
type="API_KEY",
value="sk_live_...",
agent_id=agent["id"],
)
credentials = client.list_credentials(agent_id=agent["id"])
client.revoke_credential(credential["id"])
Policies
policy = client.create_policy(
agent_id=agent["id"],
credential_id=credential["id"],
allowed_actions=["charges.*"],
denied_actions=["transfers.*"],
constraints={
"maxAmountPerTransaction": 1000,
"maxDailySpend": 5000,
"rateLimit": {"maxRequests": 100, "windowSeconds": 3600},
},
requires_approval_above=500,
)
# Dry-run evaluation (no side effects)
result = client.evaluate_policy(
agent_id=agent["id"],
credential_id=credential["id"],
action="charges.create",
params={"amount": 750},
)
# result["decision"] → "ESCALATE"
Agent Operations
Use an agent secret (bst_...) for proxy execution.
agent_client = BastionClient("http://localhost:3000", api_key=agent_secret)
result = agent_client.execute(
credential_id=credential["id"],
action="charges.create",
target={
"url": "https://api.stripe.com/v1/charges",
"method": "POST",
"body": {"amount": 5000, "currency": "usd"},
},
params={"amount": 50},
)
# result["upstream"]["status"] → 200
# result["upstream"]["body"] → Stripe's response
# result["meta"]["policyDecision"] → "ALLOW"
Custom Credential Injection
agent_client.execute(
credential_id=credential["id"],
action="test",
target={"url": "https://api.example.com"},
injection={"location": "header", "key": "X-Api-Key"},
)
HITL (Human-in-the-Loop)
pending = client.list_pending_requests()
client.approve_request(pending[0]["requestId"])
client.deny_request(request_id, "Too risky")
Audit
records = client.query_audit_records(
agent["id"],
from_="2026-01-01",
policy_decision="DENY",
limit=10,
)
verification = client.verify_chain(agent["id"])
# verification["valid"] → True
Error Handling
All API errors raise typed exceptions:
from bastion_sdk import BastionForbiddenError, BastionNotFoundError
try:
agent_client.execute(...)
except BastionForbiddenError as e:
print(f"Policy denied: {e.message}")
| Error Class | Status | When |
|---|---|---|
BastionValidationError |
400 | Invalid input |
BastionUnauthorizedError |
401 | Bad or missing auth |
BastionForbiddenError |
403 | Policy DENY or HITL timeout |
BastionNotFoundError |
404 | Resource not found |
BastionConflictError |
409 | State conflict |
BastionBadGatewayError |
502 | Upstream API failure |
License
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 bastion_sdk-0.1.0.tar.gz.
File metadata
- Download URL: bastion_sdk-0.1.0.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
70d5f224120bfc58e86e937c6999875093383225d5db067b2dee0a7baf16f842
|
|
| MD5 |
33b794b58fc21e5abb28aea114666b6f
|
|
| BLAKE2b-256 |
266e14afe5d6486a9d21131015829252fc481933311db7ea2aac62fff3d4de28
|
File details
Details for the file bastion_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: bastion_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b926251855a26fce420ee9121f545cb014d1f801f3b9646c52fb6ec1ee3a416e
|
|
| MD5 |
034f8e65334bfe44f00a15297371b18d
|
|
| BLAKE2b-256 |
821885744f622d523f1f64bc2c6b31f6bd3d4a125ee9a94327dc0f6c6213f695
|