Skip to main content

Faramesh Python SDK - Production-ready client for the Faramesh Execution Governor API

Project description

Faramesh Python SDK

Production-ready Python client for the Faramesh Execution Governor API.

Installation

pip install faramesh-sdk

Or install from source:

git clone https://github.com/faramesh/faramesh-python-sdk.git
cd faramesh-python-sdk
pip install -e .

Quick Start

from faramesh import configure, submit_action, approve_action

# Configure SDK (optional - defaults to http://127.0.0.1:8000)
configure(
    base_url="http://localhost:8000",
    token="your-token",  # Optional, can also use FARAMESH_TOKEN env var
)

# Submit an action
action = submit_action(
    agent_id="my-agent",
    tool="http",
    operation="get",
    params={"url": "https://example.com"}
)

print(f"Action {action.id} status: {action.status}")

# If action requires approval
if action.status == "pending_approval":
    approved = approve_action(
        action.id,
        action.approval_token,
        reason="Looks safe"
    )
    print(f"Action approved: {approved.status}")

Features

  • Simple API: Easy-to-use functions for all API operations
  • Batch Operations: Submit multiple actions at once
  • Submit and Wait: Automatically wait for action completion
  • Policy Building: Build policies in Python code
  • Deterministic Hashing: Client-side request_hash computation
  • Gate Endpoint: Pre-check decisions without creating actions
  • Replay Helpers: Verify decision determinism
  • Error Handling: Typed exceptions for all error cases

Gate Endpoint & Deterministic Hashing

The SDK provides helpers for deterministic decision verification:

Compute Request Hash Locally

from faramesh import compute_request_hash

payload = {
    "agent_id": "my-agent",
    "tool": "http",
    "operation": "get",
    "params": {"url": "https://example.com"},
    "context": {}
}

# Compute hash locally (matches server's request_hash)
hash_value = compute_request_hash(payload)
print(f"Request hash: {hash_value}")

Gate Decide (Decision Only)

from faramesh import gate_decide

# Get decision without creating an action
decision = gate_decide(
    agent_id="my-agent",
    tool="http",
    operation="get",
    params={"url": "https://example.com"}
)

if decision.outcome == "EXECUTE":
    print("Action would be allowed")
elif decision.outcome == "HALT":
    print(f"Action would be denied: {decision.reason_code}")
else:  # ABSTAIN
    print("Action requires approval")

Execute If Allowed (Gated Execution)

from faramesh import execute_if_allowed

def my_executor(tool, operation, params, context):
    # Your actual execution logic
    return {"status": "done"}

result = execute_if_allowed(
    agent_id="my-agent",
    tool="http",
    operation="get",
    params={"url": "https://example.com"},
    executor=my_executor
)

if result["executed"]:
    print("Action executed:", result["execution_result"])
else:
    print("Action blocked:", result["reason_code"])

Replay Decision

from faramesh import replay_decision

# Verify decision is deterministic
result = replay_decision(action_id="abc123")

if result.success:
    print("Decision replay passed!")
else:
    print("Mismatches:", result.mismatches)

Documentation

Full documentation is available at: https://github.com/faramesh/faramesh-docs

See docs/SDK-Python.md for detailed API reference.

Repository

Source: https://github.com/faramesh/faramesh-python-sdk

License

Elastic License 2.0

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

faramesh_sdk-0.3.0.tar.gz (27.6 kB view details)

Uploaded Source

Built Distribution

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

faramesh_sdk-0.3.0-py3-none-any.whl (30.6 kB view details)

Uploaded Python 3

File details

Details for the file faramesh_sdk-0.3.0.tar.gz.

File metadata

  • Download URL: faramesh_sdk-0.3.0.tar.gz
  • Upload date:
  • Size: 27.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for faramesh_sdk-0.3.0.tar.gz
Algorithm Hash digest
SHA256 300b3a6b25c792d174093f3faf29bddac401981abe5f5b0cb177541c7029da84
MD5 1d91008f566de37dcfc9aecb118da624
BLAKE2b-256 32b96fc03c08a4672c6c9e58bafb1d90d4a05195ebbc299e0f8e475d4164b62e

See more details on using hashes here.

File details

Details for the file faramesh_sdk-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: faramesh_sdk-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 30.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for faramesh_sdk-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 60c6fbd8e12842f1809fa5ed5e9a81edc7ffc61691e6ef748d43409b6f597462
MD5 a92e2c915101ee49b9171537dc7ebf8b
BLAKE2b-256 b33bf2db323b583646387bb9c1b7940f8b04e7f9922c4e3dd13516ec825e8e9a

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