TrustChain — decentralized trust primitives for Python
Project description
TrustChain Python SDK
Python SDK for TrustChain — decentralized trust primitives for AI agents.
trustchain-py is the Python face of the TrustChain trust primitive. At its simplest it is a one-liner (trustchain.init()) that downloads and starts the Rust sidecar binary, sets HTTP_PROXY, and makes every outbound HTTP call trust-protected. For agents that need full programmatic control it exposes the complete protocol: Ed25519 identities, half-block creation and validation, chain storage, trust computation, NetFlow Sybil resistance, QUIC transport, and gRPC. 290 tests.
Installation
pip install trustchain-py
Optional extras
pip install trustchain-py[quic] # QUIC P2P transport (aioquic)
pip install trustchain-py[grpc] # gRPC client/server (grpcio + protobuf)
pip install trustchain-py[node] # full Python node (hypercorn ASGI)
pip install trustchain-py[all] # everything above
Requires Python 3.11+.
Quick Start
Zero-config sidecar (recommended)
import trustchain
# Downloads the Rust binary if needed, starts the sidecar, sets HTTP_PROXY.
# All outbound HTTP calls from this process are now trust-protected.
trustchain.init()
That is the entire integration for most agents. The sidecar runs on port 8203 as a transparent HTTP proxy; agents never call TrustChain directly.
The sidecar binary (trustchain-node) must be available. Install it separately:
# From crates.io
cargo install trustchain-node
# Or place the binary at ~/.trustchain/bin/trustchain-node
# Or download from https://github.com/levvlad/trustchain/releases
Programmatic protocol usage
import trustchain
# Create identities
alice = trustchain.Identity()
bob = trustchain.Identity()
# Create a protocol instance backed by an in-memory block store
store = trustchain.MemoryBlockStore()
protocol = trustchain.TrustChainProtocol(alice, store)
# Alice proposes an interaction with Bob
proposal = protocol.create_proposal(
bob.pubkey_hex,
{"type": "service_call", "outcome": "completed"},
)
# Bob validates the proposal and creates the counter-signed agreement
bob_protocol = trustchain.TrustChainProtocol(bob, store)
agreement = bob_protocol.create_agreement(proposal)
print(f"Block pair recorded: seq={proposal.sequence_number}")
Trust scoring
from trustchain.trust import TrustEngine
from trustchain.blockstore import SqliteBlockStore
store = SqliteBlockStore("agent.db")
engine = TrustEngine(store)
score = engine.compute_trust(peer_pubkey)
print(f"Trust score for peer: {score:.3f}") # 0.0 to 1.0
SQLite-backed node
import asyncio
from trustchain.api import TrustChainNode
async def main():
node = TrustChainNode(db_path="agent.db")
await node.start() # serves HTTP REST on :8202
await node.run_forever()
asyncio.run(main())
Modules
| Module | Description |
|---|---|
trustchain.identity |
Ed25519 keypair generation, loading, and serialization |
trustchain.halfblock |
HalfBlock data structure, signing, and validation |
trustchain.blockstore |
MemoryBlockStore and SqliteBlockStore |
trustchain.protocol |
TrustChainProtocol — proposal/agreement state machine |
trustchain.trust |
TrustEngine — weighted three-component trust scoring |
trustchain.netflow |
NetFlow Sybil resistance (max-flow from seed nodes) |
trustchain.consensus |
CHECO checkpoint consensus |
trustchain.chain |
Chain operations, validation, and gap detection |
trustchain.crawler |
Network graph crawler and DAG view builder |
trustchain.transport |
QUIC P2P, HTTP connection pooling, peer discovery |
trustchain.grpc |
gRPC client and server (requires [grpc] extra) |
trustchain.api |
FastAPI HTTP node (full REST API, same endpoints as Rust) |
trustchain.sidecar |
Rust binary manager — download, start, health-check, proxy setup |
trustchain.delegation |
Identity delegation, succession, and revocation |
Trust Score Components
TrustEngine.compute_trust(pubkey) returns a weighted score from three components:
| Component | Weight | What it measures |
|---|---|---|
| Chain Integrity | 30% | Hash links valid, no sequence gaps, Ed25519 signatures verify |
| NetFlow | 40% | Max-flow from seed nodes — primary Sybil resistance |
| Statistical | 30% | Volume, completion rate, counterparty diversity, account age, entropy |
Architecture
Your Python agent
│
├── trustchain.init() sets HTTP_PROXY → Rust sidecar (:8203)
│ (transparent, zero-code-change integration)
│
└── trustchain.TrustChainProtocol (full programmatic control)
│
├── Identity Ed25519 keypair
├── BlockStore MemoryBlockStore / SqliteBlockStore
├── TrustEngine NetFlow + chain integrity + statistical
└── Transport QUIC P2P / HTTP REST / gRPC
The Python SDK's trustchain.api.TrustChainNode implements the same HTTP REST API as the Rust binary. The Rust binary is recommended for production deployments; the Python node is useful for testing and environments where the binary is unavailable.
Note: The sidecar delegation API endpoints (
/trustchain/delegateetc.) are implemented in the Python SDK'sTrustChainNodeonly. The Rust sidecar does not expose these endpoints — use the standard/delegateand/revokeREST endpoints on the Rust node's HTTP API instead.
Development
git clone https://github.com/levvlad/trustchain-py.git
cd trustchain-py
pip install -e ".[dev]"
pytest tests/ -v
Related Projects
- trustchain — Rust node: production sidecar binary, core crates, QUIC P2P, MCP server
- trustchain-agent-os — Agent framework adapters (LangGraph, CrewAI, AutoGen, OpenAI Agents, Google ADK, ElizaOS)
License
MIT
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 trustchain_py-2.2.0.tar.gz.
File metadata
- Download URL: trustchain_py-2.2.0.tar.gz
- Upload date:
- Size: 112.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5b7cf163082070261e37cc5cbffe0c610a1599aca39c0ba22911a5ad71018464
|
|
| MD5 |
445ff9d77459ea61e5ce7b54d030830e
|
|
| BLAKE2b-256 |
2dae51adf5b2a06fc37e9352c9a32191fe47bd1033f4a4f8a05516ff0aa83acb
|
Provenance
The following attestation bundles were made for trustchain_py-2.2.0.tar.gz:
Publisher:
publish.yml on viftode4/trustchain-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
trustchain_py-2.2.0.tar.gz -
Subject digest:
5b7cf163082070261e37cc5cbffe0c610a1599aca39c0ba22911a5ad71018464 - Sigstore transparency entry: 1013014525
- Sigstore integration time:
-
Permalink:
viftode4/trustchain-py@2656bdc2d32e31f378b5741d21f49a511d3966ea -
Branch / Tag:
refs/tags/v2.2.0 - Owner: https://github.com/viftode4
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2656bdc2d32e31f378b5741d21f49a511d3966ea -
Trigger Event:
release
-
Statement type:
File details
Details for the file trustchain_py-2.2.0-py3-none-any.whl.
File metadata
- Download URL: trustchain_py-2.2.0-py3-none-any.whl
- Upload date:
- Size: 96.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf3c5ed1d8e16a3b5c3c5a3878371c0a057c98bb6e39516bad034c8cefe655c6
|
|
| MD5 |
d53836538214d0706b05fecf24eeedef
|
|
| BLAKE2b-256 |
a4487c663248922afcd123bb00add490d125f769553ff37e89ea90b4edb72b53
|
Provenance
The following attestation bundles were made for trustchain_py-2.2.0-py3-none-any.whl:
Publisher:
publish.yml on viftode4/trustchain-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
trustchain_py-2.2.0-py3-none-any.whl -
Subject digest:
cf3c5ed1d8e16a3b5c3c5a3878371c0a057c98bb6e39516bad034c8cefe655c6 - Sigstore transparency entry: 1013014590
- Sigstore integration time:
-
Permalink:
viftode4/trustchain-py@2656bdc2d32e31f378b5741d21f49a511d3966ea -
Branch / Tag:
refs/tags/v2.2.0 - Owner: https://github.com/viftode4
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2656bdc2d32e31f378b5741d21f49a511d3966ea -
Trigger Event:
release
-
Statement type: