Skip to main content

Python REST SDK for Ecto Ledger - The Cryptographic Veto Engine for AI Agents

Project description

Ecto Ledger SDK — Python

A typed async REST client for Ecto Ledger with built-in LangChain and AutoGen support.

Installation

# Core client only
pip install ectoledger-sdk

# With LangChain support
pip install 'ectoledger-sdk[langchain]'

# With AutoGen support
pip install 'ectoledger-sdk[autogen]'

Quick start

import asyncio
from ectoledger_sdk import LedgerClient

async def main():
    async with LedgerClient("http://localhost:3000", bearer_token="your_token") as client:
        sessions = await client.list_sessions()
        print(f"Found {len(sessions)} active sessions.")

asyncio.run(main())

Constructor

LedgerClient(
    base_url="http://localhost:3000",  # Server URL (required in production)
    bearer_token=None,                 # Optional RBAC token
    timeout=30.0,                      # HTTP timeout in seconds
)

Note: The default base_url only works for local development. In Docker Compose or Kubernetes you must pass the correct service URL.

Error handling

All methods raise LedgerSdkError on non-2xx responses:

from ectoledger_sdk import LedgerSdkError

try:
    await client.verify_chain(session_id)
except LedgerSdkError as exc:
    print(exc.status_code, exc.body)

LangChain integration

from ectoledger_sdk.langchain import LedgerTool

ledger_tool = LedgerTool(
    session_id="your-session-uuid",
    base_url="http://localhost:3000",
)
# Add ledger_tool to your agent's tool list

AutoGen integration

from ectoledger_sdk.autogen import LedgerHook

hook = LedgerHook(session_id="your-session-uuid")
hook.attach(my_agent)

Testing

cd sdk/python
pip install ".[dev]"
pytest tests/ -v

API Reference

Status

Method Returns Description
get_status() StatusResponse Server status (demo mode, version)

Sessions

Method Returns Description
list_sessions(limit=50) list[Session] List recent sessions
create_session(goal, policy_hash=None, session_did=None) Session Open a new audit session
get_session(session_id) Session Fetch a single session
seal_session(session_id) None Mark session as finished

Chat

Method Returns Description
chat(session_id, message) dict Send a message within a running session

Events

Method Returns Description
get_events(session_id) list[LedgerEvent] Fetch all events for a session
append_event(session_id, payload) AppendResult Sign and append an event
stream_events(session_id) AsyncIterator[dict] SSE live event stream

Chain Verification & Compliance

Method Returns Description
verify_chain(session_id) bool Verify hash chain integrity
prove_compliance(session_id) dict JSON compliance bundle
export_certificate(session_id) bytes Download audit certificate (PDF)

Reports & Verifiable Credentials

Method Returns Description
get_report(session_id) dict Audit report as a dictionary
get_session_vc(session_id) dict W3C Verifiable Credential (VC-JWT)
verify_session_vc(session_id) dict Verify VC structural integrity

Metrics

Method Returns Description
get_metrics() MetricsSummary System metrics summary
get_security_metrics() SecurityMetrics Security event counters
get_prometheus_metrics() str Raw Prometheus text output

Configuration

Method Returns Description
get_config() ConfigResponse Current server configuration
update_config(patch) dict Apply partial config update

Tripwire Configuration

Method Returns Description
get_tripwire_config() TripwireConfig Current tripwire guard config
update_tripwire_config(patch) dict Apply partial tripwire update

Policies

Method Returns Description
list_policies() list[str] List available policy names
get_policy(name) str Retrieve policy TOML content
save_policy(name, content) None Create or overwrite a policy
delete_policy(name) None Remove a policy

RBAC Tokens

Method Returns Description
list_tokens() list[TokenListRow] List tokens (hashed, not raw)
create_token(role, label=None) CreateTokenResponse Create a new API token
delete_token(token_hash) None Revoke a token

Webhooks

Method Returns Description
list_webhooks() list[WebhookListRow] List configured webhooks
create_webhook(label, url, siem_format="json", filter_kinds=None) WebhookListRow Register a webhook
delete_webhook(webhook_id) None Remove a webhook
toggle_webhook(webhook_id, enabled) dict Enable/disable a webhook

Approval Gates

Method Returns Description
get_pending_approval(session_id) PendingApproval | None Get pending approval gate
post_approval_decision(session_id, gate_id, approved, reason=None) None Submit decision

Admin

Method Returns Description
reset_demo() dict Reset server to demo defaults

Licensing & Contact

Licensed under the Apache License 2.0.

Maintained by Björn Roman Kohlberger.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ectoledger_sdk-0.6.1.tar.gz (51.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ectoledger_sdk-0.6.1-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file ectoledger_sdk-0.6.1.tar.gz.

File metadata

  • Download URL: ectoledger_sdk-0.6.1.tar.gz
  • Upload date:
  • Size: 51.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for ectoledger_sdk-0.6.1.tar.gz
Algorithm Hash digest
SHA256 fce3dfffad17f98f10568a93bd49a73f8796683632c3acff85e100c5415614c6
MD5 655324a6642e265190b2641a8ba57164
BLAKE2b-256 f3f8212bb160f5272042334843e86a743276e8ee318eb1ecf0acfd5fe8776cde

See more details on using hashes here.

File details

Details for the file ectoledger_sdk-0.6.1-py3-none-any.whl.

File metadata

  • Download URL: ectoledger_sdk-0.6.1-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for ectoledger_sdk-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 77269ae4a8fa0c92d297d1290d843cac9a0c173ea56d2e0717250d1bbe610edf
MD5 1b14027d8fe9a10d11e172fc6014e434
BLAKE2b-256 ef14f048960d171a3b1547118eb752486419b375d0ba6727de080c944612e2c2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page