Python SDK for the Lyhna governance API
Project description
lyhna
Python SDK for Lyhna — the execution authority boundary for AI systems. Every consequential action passes through bind() before it happens. The server returns a cryptographically signed receipt (Ed25519, LyhnaReceiptV2) that can be verified offline by any party — no network call, no API key required.
Install
pip install lyhna
Requires Python 3.8+.
Authentication
Set your API key as an environment variable:
export LYHNA_API_KEY=lyhna_dev_...
Get a key by signing up at https://www.lyhna.com/signup.
Quick start
import lyhna
receipt = lyhna.bind(
action_type="deploy_service",
action_payload={"service": "api", "version": "v3"},
intent="release_v3",
intent_version="1.0",
)
if receipt.outcome == "APPROVED":
# Execute your action here
print(f"Approved under authority tier {receipt.authority_tier}")
print(f"Receipt: {receipt.receipt_id}")
# Verify the receipt offline — no network, no API key required
is_valid = lyhna.verify_receipt(receipt)
assert is_valid
API
bind(action_type, action_payload, intent, intent_version) -> Receipt
Call before any consequential action. All four parameters are required.
action_type(str) — canonical identifier, e.g."deploy_service","send_email","transfer_funds"action_payload(any) — JSON-serializable description of what will happenintent(str) — high-level intent, e.g."release_v3"intent_version(str) — version of the intent, e.g."1.0"
Returns a Receipt with one of three outcomes:
APPROVED— execute the actionESCALATED— waiting on human authority; hold the actionREFUSED— do not execute
Authority tier is resolved server-side from your tenant's authority_rules — callers cannot self-classify.
verify_receipt(receipt) -> bool
Verify a receipt offline. Returns True if:
- the receipt's canonical hash recomputes to its claimed value, AND
- the Ed25519 signature validates against the public key embedded in the receipt
No network call. No API key required. Any party holding a Lyhna receipt can verify it independently.
Fail-closed: returns False on any error. Never raises.
verify_receipt_offline(receipt) -> bool
Alias for verify_receipt. Same behavior — explicit name for clarity in code that wants to emphasize the offline verification path.
Using the client directly
For multiple calls, instantiate a client explicitly to reuse connections:
from lyhna import LyhnaClient
with LyhnaClient() as client:
for action in actions:
receipt = client.bind(
action_type=action.type,
action_payload=action.payload,
intent="batch_process",
intent_version="1.0",
)
if receipt.outcome == "APPROVED":
action.execute()
Async client available as AsyncLyhnaClient:
from lyhna import AsyncLyhnaClient
async with AsyncLyhnaClient() as client:
receipt = await client.bind(
action_type="deploy_service",
action_payload={"service": "api"},
intent="release_v3",
intent_version="1.0",
)
is_valid = await client.verify_receipt(receipt)
Errors
| Exception | Raised when |
|---|---|
LyhnaAuthError |
API key is missing, invalid, or unauthorized (401/403 from server on bind) |
LyhnaTimeoutError |
Request to the enforcement boundary timed out |
LyhnaError |
Other HTTP or network errors during bind |
verify_receipt() never raises. It returns False on any failure — by design, to match the fail-closed guarantee that any cryptographic failure must deny rather than throw.
Receipt structure
A Receipt exposes common fields (receipt_id, outcome, action_type, authority_tier, bound_at, expires_at, canonical_hash, signature) and preserves the full server response in receipt.raw for offline verification.
Learn more
- Documentation: https://docs.lyhna.com
- Source: https://github.com/lyhna/lyhna-python
- Company: https://www.lyhna.com
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
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 lyhna-0.2.0.tar.gz.
File metadata
- Download URL: lyhna-0.2.0.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1b62b42cbb1ed32bd9dc7d5b6fe00a26f391a4a09e2e59276eb9f2919aaaaf35
|
|
| MD5 |
47f93d25483713efa8ea41dfd39ec97b
|
|
| BLAKE2b-256 |
94cef27162ce4303df6e3da4b664daa57e0f44a894342b766e3ba83e190fcee7
|
File details
Details for the file lyhna-0.2.0-py3-none-any.whl.
File metadata
- Download URL: lyhna-0.2.0-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
41cf5a26a37974d2a5492e84b14dfcbadd1b9ab4121f28f98fdfd20a9e19a875
|
|
| MD5 |
0d50059bbfaaf6bcb26ee5bfc9cdd326
|
|
| BLAKE2b-256 |
bf5e21dc419df7037797fc70561a3243927278c963044b65a26cb4dd56bd78e1
|