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
Metadata
Release files for bastion-sdk 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| bastion_sdk-0.1.0.tar.gz | 8.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| bastion_sdk-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.9 kB
Release files / bastion_sdk-0.1.0.tar.gz
| Download URL | bastion_sdk-0.1.0.tar.gz |
|---|---|
| Size | 8.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
70d5f224120bfc58e86e937c6999875093383225d5db067b2dee0a7baf16f842
|
|
BLAKE2b-256 checksum How to use checksums |
266e14afe5d6486a9d21131015829252fc481933311db7ea2aac62fff3d4de28
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / bastion_sdk-0.1.0-py3-none-any.whl
| Download URL | bastion_sdk-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b926251855a26fce420ee9121f545cb014d1f801f3b9646c52fb6ec1ee3a416e
|
|
BLAKE2b-256 checksum How to use checksums |
821885744f622d523f1f64bc2c6b31f6bd3d4a125ee9a94327dc0f6c6213f695
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Security for bastion-sdk 0.1.0
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.