Agent-agnostic compliance shim for SOX 404 policy enforcement via the ALCV Vault
Project description
Ledgix Python SDK
Python SDK for customer integrations with Ledgix. Use it to request clearance before a payment, refund, or other sensitive tool runs.
What to do first
- Create a tenant API key in the Ledgix customer dashboard.
- Upload or import the policy content for the first action you want to guard.
- Set the review threshold and reviewer notifications.
- Wrap one real tool call with the SDK.
Install
python3 -m pip install ledgix-python
Optional adapters:
pip install ledgix-python[langchain]
pip install ledgix-python[llamaindex]
pip install ledgix-python[crewai]
Create the client
from ledgix_python import LedgixClient
client = LedgixClient() # Reads LEDGIX_* environment variables
Or configure explicitly:
from ledgix_python import LedgixClient, VaultConfig
client = LedgixClient(
config=VaultConfig(
vault_url="https://vault.example.com",
vault_api_key="sk_prod_example",
agent_id="payments-agent",
session_id="checkout-42",
)
)
Quick start: guard a refund
from ledgix_python import vault_enforce
@vault_enforce(client, tool_name="stripe_refund", policy_id="payments-prod")
def process_refund(amount: int, reason: str, order_event_id: str, **kwargs):
clearance = kwargs["_clearance"]
return stripe.Refund.create(
amount=amount,
reason=reason,
metadata={
"order_event_id": order_event_id,
"ledgix_request_id": clearance.request_id,
"ledgix_token": clearance.token,
},
)
Direct clearance example
from ledgix_python import ClearanceRequest
clearance = client.request_clearance(
ClearanceRequest(
tool_name="create_stripe_payment",
tool_args={
"amount": 249.99,
"currency": "USD",
"customer_id": "cus_123",
"payment_method_id": "pm_123",
"order_event_id": "ord_evt_2048",
"reasoning": "Charge matches a completed order event.",
},
agent_id="payments-agent",
session_id="checkout-42",
context={"policy_id": "payments-prod"},
)
)
if clearance.approved and clearance.token:
print("Approved token:", clearance.token)
else:
print(clearance.status, clearance.reason)
Framework adapters
LangChain
from langchain_core.tools import StructuredTool
from ledgix_python.adapters.langchain import LedgixTool
refund_tool = StructuredTool.from_function(
func=refund_customer,
name="stripe_refund",
description="Refund a customer payment",
)
guarded_tool = LedgixTool.wrap(
client,
refund_tool,
policy_id="payments-prod",
)
LlamaIndex
from llama_index.core.tools import FunctionTool
from ledgix_python.adapters.llamaindex import wrap_tool
refund_tool = FunctionTool.from_defaults(
fn=refund_customer,
name="stripe_refund",
description="Refund a customer payment",
)
guarded_tool = wrap_tool(
client,
refund_tool,
policy_id="payments-prod",
)
CrewAI
from crewai.tools import BaseTool
from ledgix_python.adapters.crewai import LedgixCrewAITool
class StripeRefundTool(BaseTool):
name = "stripe_refund"
description = "Refund a customer payment"
def _run(self, amount: int, reason: str, order_event_id: str):
return refund_customer(
amount=amount,
reason=reason,
order_event_id=order_event_id,
)
guarded_tool = LedgixCrewAITool.wrap(
client,
StripeRefundTool(),
policy_id="payments-prod",
)
Async example
result = await client.arequest_clearance(
ClearanceRequest(
tool_name="create_stripe_payment",
tool_args={"amount": 249.99, "currency": "USD"},
agent_id="payments-agent",
session_id="checkout-42",
context={"policy_id": "payments-prod"},
)
)
Configuration
| Variable | Default | Description |
|---|---|---|
LEDGIX_VAULT_URL |
http://localhost:8000 |
Vault URL |
LEDGIX_VAULT_API_KEY |
"" |
Tenant API key |
LEDGIX_VAULT_TIMEOUT |
30.0 |
Timeout in seconds |
LEDGIX_VERIFY_JWT |
true |
Verify approval tokens automatically |
LEDGIX_JWT_ISSUER |
alcv-vault |
Expected token issuer |
LEDGIX_JWT_AUDIENCE |
ledgix-sdk |
Expected token audience |
LEDGIX_AGENT_ID |
default-agent |
Calling agent or service ID |
LEDGIX_SESSION_ID |
"" |
Workflow or session ID |
Available helpers
request_clearance()andarequest_clearance()register_policy()fetch_jwks()andverify_token()fetch_ledger(),fetch_ledger_checkpoints(), andfetch_ledger_proof_bundle()verify_ledger_proof_bundle()VaultContextfor explicit context-manager style flows
Errors to handle separately
from ledgix_python import (
ClearanceDeniedError,
ManualReviewTimeoutError,
VaultConnectionError,
TokenVerificationError,
)
Treat denied or review-paused requests differently from connectivity failures.
More documentation
- Customer quickstart:
/getting-started - Policy management:
/guides/policy-ingestion-and-rag - Manual review:
/guides/manual-review-and-thresholds - Full Python guide:
/sdk/python
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 ledgix_python-0.1.8.tar.gz.
File metadata
- Download URL: ledgix_python-0.1.8.tar.gz
- Upload date:
- Size: 27.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2fe3eeb3040d16ef23c0aa580d881e255458f5e3f21c13ad671bba9a29230e87
|
|
| MD5 |
43b6e725d2502eea7678517d0f46850c
|
|
| BLAKE2b-256 |
d2c79f3c75b2530ad4872b2a88f369d9599a7c2134541c98dd427d0a1bf8a0f6
|
File details
Details for the file ledgix_python-0.1.8-py3-none-any.whl.
File metadata
- Download URL: ledgix_python-0.1.8-py3-none-any.whl
- Upload date:
- Size: 21.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
970847dbcc181aec0f75f9298cb1ee8873204489414a02ad9b01f432317f27b2
|
|
| MD5 |
c7e4118acf00873dc1c41529e275292b
|
|
| BLAKE2b-256 |
85461f1610dc599eb879ced23b218df551e03cf791cc0bba6a7b4a6576bcde80
|