Python client library for the Disentangle Protocol - a decentralized identity and capability system with sybil resistance through topological coherence.
pip install disentangle-sdkOr with uv:
uv pip install disentangle-sdkfrom disentangle_sdk import DisentangleAgent
# Connect to a Disentangle node
agent = DisentangleAgent("http://localhost:8000")
# Register as an AGI agent
identity = agent.register(agent_type="agi")
print(f"Registered as {identity.did}")
# Create a capability
capability = agent.create_capability(
subject_type="file",
scope="read",
delegatable=True
)
# Check your coherence score
coherence = agent.coherence()
print(f"Coherence score: {coherence.composite_score:.2f}")- Register agents (AGI, human, etc.)
- Lookup identity documents
- DID-based addressing
- Create fine-grained capabilities
- Delegate capabilities to other agents
- Invoke capabilities with coherence-based authorization
- Revoke capabilities (single or chain)
- Introduce agents to each other
- Build introduction chains
- Calculate curvature between agents
- Query neighbors
- Query your own coherence
- Look up peer coherence
- Sybil resistance through topological mass
- Relational diversity measurement
- Assign human-friendly names to DIDs
- Resolve petnames to DIDs
- Local namespace per agent
The SDK follows clean architecture principles:
- Client Layer (
DisentangleAgent) - HTTP client wrapping all RPC endpoints - Type Layer (
types.py) - Pydantic models for data validation - Exception Layer (
exceptions.py) - Typed exceptions for error handling
All operations are synchronous for simplicity. The SDK stores the signing key in memory after registration.
register(agent_type, model_hash, runtime_hash)- Register a new agentget_identity(did)- Lookup an identity documentdid- Property to get current agent's DIDis_registered- Check if registered
create_capability(subject_type, scope, constraints, delegatable)- Create capabilitydelegate(capability_id, to_did)- Delegate to another agentinvoke(capability_id)- Invoke a capabilityrevoke(capability_id, scope)- Revoke a capabilitylist_capabilities()- List all held capabilities
introduce(other_did, edge_name)- Introduce to another agentget_introduction_chain(to_did)- Get introduction pathcurvature_with(other_did)- Calculate curvatureneighbors()- Get neighbor DIDs
coherence()- Get own coherence metricspeer_coherence(did)- Get peer's coherencecurvature_with(other_did)- Calculate curvature
name(did, petname)- Assign petnameresolve_name(petname)- Resolve to DID
node_status()- Get node information
The SDK provides typed exceptions:
from disentangle_sdk import (
DisentangleError, # Base exception
DIDNotFoundError, # DID not found (404)
CapabilityDeniedError, # Capability denied (403)
NodeConnectionError, # Cannot connect to node
NotRegisteredError, # Agent not registered
)
try:
agent.invoke(capability_id)
except CapabilityDeniedError as e:
print(f"Denied - coherence: {e.coherence_score}")
except DIDNotFoundError:
print("DID not found on network")Run tests against a live Disentangle node:
# Set node URL
export DISENTANGLE_NODE_URL=http://localhost:8000
# Run tests
pytest tests/Tests are skipped if DISENTANGLE_NODE_URL is not set.
# Install dependencies
uv pip install -e ".[dev]"
# Run tests
pytest tests/
# Format code
black src/ tests/
# Type check
mypy src/The SDK supports context managers for automatic cleanup:
with DisentangleAgent("http://localhost:8000") as agent:
agent.register(agent_type="agi")
print(agent.did)
# HTTP client automatically closedApache-2.0