Skip to main content

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 happen
  • intent (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 action
  • ESCALATED — waiting on human authority; hold the action
  • REFUSED — 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

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

lyhna-0.2.1.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

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

lyhna-0.2.1-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file lyhna-0.2.1.tar.gz.

File metadata

  • Download URL: lyhna-0.2.1.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

Hashes for lyhna-0.2.1.tar.gz
Algorithm Hash digest
SHA256 9dfb678aeb2b099aab643025292ce2ee7cde4d34672e2f80b72e4ef8745bf803
MD5 72fbef099dd4e9236af34f053a5b4c2a
BLAKE2b-256 4e0d2a8dc35a5f37be573341549ed5bad01cd923a297202bbebe01d360522e03

See more details on using hashes here.

File details

Details for the file lyhna-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: lyhna-0.2.1-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

Hashes for lyhna-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 32b28d5ef59b2238be4c109bed50d7b2ee22e7ee00508e45248a48289c927bdb
MD5 0e1800659e722b93104c6a4a1315aebb
BLAKE2b-256 a0164eabd65cfe36e47a85d59410b59af32d5e45b5d0eb73cba0fa7ff15347bb

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