Skip to main content

Banner

Truss SDK — Python

Python SDK for the Truss trust infrastructure API — create mandates, record actions, manage agents, and verify evidence.

PyPI version Python License CI


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 API
  • ActionContext — 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.

Metadata

Release files for truss-sdk 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for truss-sdk 0.1.1
File Size Uploaded Provenance
truss_sdk-0.1.1.tar.gz 8.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for truss-sdk 0.1.1
File Interpreter ABI Platform
truss_sdk-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 15.2 kB

Release files / truss_sdk-0.1.1.tar.gz

Download URL truss_sdk-0.1.1.tar.gz
Size 8.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c35f417b70b38a5f5a82fa694b51ca1f5811f43ebea696e4d0f80e3169a3aa3c
BLAKE2b-256 checksum
How to use checksums
2c9426f189233c6bcfeb87d78911ba9c132ab59489d26756890745361d16cc90
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Release files / truss_sdk-0.1.1-py3-none-any.whl

Download URL truss_sdk-0.1.1-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fb021ca046ab869850b78b16d649a22c3974934ab9ce1d775cda35c9e0bb4fe9
BLAKE2b-256 checksum
How to use checksums
2df17eb7eea3eac49af8a07d295aaee359f329e7fbed63fceacc3e59fe6c1f27
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Security for truss-sdk 0.1.1

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page