Python SDK for the Truss trust infrastructure API
Project description
Truss SDK — Python
Python SDK for the Truss trust infrastructure API — create mandates, record actions, manage agents, and verify evidence.
What is Truss?
Truss is an accountability layer for AI agents — it records every agent action as a cryptographically signed, tamper-evident audit trail. Learn more →
Features
- Ed25519 cryptography — Key generation, payload signing, and signature verification via
PyNaCl TrussClient— Full-featured HTTP client for the Truss APIActionContext— Builder pattern for recording actions with chain-of-custody linkage- Dataclass models — Mirroring Truss TAP schemas with full type annotations
- Python ≥3.9
Installation
pip install truss-sdk
Quick start
from truss_sdk import TrussClient, generate_keypair, sign_payload, verify_signature
# 1. Generate an Ed25519 keypair
kp = generate_keypair()
print(f"Public key: {kp.public_key}")
print(f"Private key: {kp.private_key}") # keep secret!
# 2. Sign and verify
sig = sign_payload({"action": "read", "value": 42}, kp.private_key)
assert verify_signature({"action": "read", "value": 42}, sig, kp.public_key)
print("Signature valid: True")
# 3. Create an API client
client = TrussClient(api_key="tr_your_api_key")
# 4. Register an agent
agent = client.create_agent(
name="My Agent",
public_key=kp.public_key,
description="My autonomous agent",
)
# 5. Create a mandate
mandate = client.create_mandate(
mandate_id="mnd_001",
agent_id=agent.id,
agent_name=agent.name,
issuing_principal={
"entity": "org_1",
"human_id": "usr_1",
"role": "Admin",
},
scope={"permitted_actions": ["read", "write"]},
jurisdiction_context={
"deploying_org_jurisdiction": "US",
"operating_jurisdictions": ["US"],
},
validity={
"issued_at": "2026-06-06T00:00:00Z",
"expires_at": "2026-12-31T23:59:59Z",
},
private_key=kp.private_key,
)
# 6. Record an action using the builder pattern
ctx = client.action("read", mandate.id, kp.private_key)
ctx.record_input({"file": "/data/report.pdf"})
ctx.record_output({"summary": "Report contains 42 records"})
result = ctx.commit(agent_id=agent.id, chain_position=1, prev_record_hash=None)
print(f"Action recorded: {result.id}")
API reference
generate_keypair()
Returns a Keypair namedtuple with .public_key and .private_key fields.
sign_payload(payload, private_key)
Signs any JSON-serialisable dict and returns a hex-encoded Ed25519 signature string.
verify_signature(payload, signature, public_key)
Verifies an Ed25519 signature. Returns bool.
TrussClient(api_key, api_url=None)
| Parameter | Type | Description |
|---|---|---|
api_key |
str |
Truss API key (tr_ prefix) |
api_url |
str |
API base URL (default http://localhost:4000) |
Client methods: create_agent, get_agent, list_agents, create_mandate, get_mandate, list_mandates, record_action, get_action, list_actions, create_delegation, generate_evidence, verify_evidence, and more.
client.action(action_type, mandate_id, private_key)
Returns an ActionContext builder with .record_input(), .record_output(), .commit().
Related packages
| Package | Description |
|---|---|
| @tensflare/tap | Core Zod schemas for mandates, actions, and delegations |
| @tensflare/truss-sdk | TypeScript SDK equivalent |
| @tensflare/cli | Command-line interface |
Development
pip install -e ".[dev]"
pytest
Contributing
Pull requests are welcome. Please see the contribution guidelines.
License
Apache 2.0 — see 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 truss_sdk-0.1.1.tar.gz.
File metadata
- Download URL: truss_sdk-0.1.1.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c35f417b70b38a5f5a82fa694b51ca1f5811f43ebea696e4d0f80e3169a3aa3c
|
|
| MD5 |
3b764c0ecd3bc65515c61ee49adb2732
|
|
| BLAKE2b-256 |
2c9426f189233c6bcfeb87d78911ba9c132ab59489d26756890745361d16cc90
|
File details
Details for the file truss_sdk-0.1.1-py3-none-any.whl.
File metadata
- Download URL: truss_sdk-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb021ca046ab869850b78b16d649a22c3974934ab9ce1d775cda35c9e0bb4fe9
|
|
| MD5 |
ec7801f47a03941bf9160c5ceb697908
|
|
| BLAKE2b-256 |
2df17eb7eea3eac49af8a07d295aaee359f329e7fbed63fceacc3e59fe6c1f27
|