Skip to main content

Official Python SDK for the Execlave AI Governance Platform — tracing, policy enforcement, and framework auto-instrumentation for LangChain, OpenAI Agents SDK, and CrewAI

Project description

Execlave Python SDK

Official Python SDK for the Execlave AI Governance Platform. Provides tracing, agent registration, prompt-injection scanning, PII scrubbing, and OpenTelemetry integration for AI agents.

PyPI version Python 3.11+ Downloads License: MIT Docs

Framework integrations — drop in one callback/processor/helper for LangChain, OpenAI Agents SDK, or CrewAI. See the full docs or get an API key.


Installation

pip install execlave-sdk

With OpenTelemetry support:

pip install execlave-sdk[otel]

Quick Start

from execlave import Execlave

# Initialize the SDK
ag = Execlave(
    api_key="exe_prod_your_key_here",   # or set EXECLAVE_API_KEY env var
    base_url="https://api.execlave.com",  # defaults to https://api.execlave.com
    environment="production",
)

# Register an agent
agent = ag.register_agent(
    agent_id="my-assistant",
    name="Customer Support Bot",
    description="Handles tier-1 support queries",
    model="gpt-4o",
    framework="langchain",
    tags=["support", "production"],
)

# Record a trace using the decorator
@ag.trace
def answer(question: str) -> str:
    # Your LLM call here
    return llm.invoke(question)

result = answer("How do I reset my password?")

Agent Registration

Register agents to monitor them from the Execlave dashboard:

agent = ag.register_agent(
    agent_id="order-processor",
    name="Order Processor",
    description="Processes and validates customer orders",
    model="claude-3-sonnet",
    framework="custom",
    tags=["orders", "production"],
)

# Check agent status
print(agent.status)  # "active", "paused", etc.

Tracing

Decorator

The simplest way to trace function calls:

@ag.trace
def process_order(order_data: dict) -> dict:
    result = llm.invoke(json.dumps(order_data))
    return json.loads(result)

Context Manager

For more control over trace metadata:

with ag.start_trace(agent_id="my-assistant", session_id="sess_abc") as trace:
    trace.set_input({"question": "What is the refund policy?"})

    result = llm.invoke("What is the refund policy?")

    trace.set_output({"answer": result})
    trace.set_model("gpt-4o")
    trace.set_tokens(input=150, output=320)
    trace.set_cost(0.0045)

Manual Trace

trace = ag.start_trace(agent_id="my-assistant")
trace.set_input(user_query)

try:
    response = llm.invoke(user_query)
    trace.set_output(response)
    trace.set_status("success")
except Exception as e:
    trace.set_error(e)
finally:
    trace.end()

Trace Fields

Method Description
set_input(data) Input data (auto-serialized)
set_output(data) Output data (auto-serialized)
set_model(name) Model name (e.g., "gpt-4o")
set_tokens(input, output) Token counts
set_cost(amount) Cost in USD
set_status(status) "success" or "error"
set_error(exception) Records error info from an exception
set_metadata(dict) Arbitrary key-value metadata
set_duration(ms) Override duration in milliseconds

Privacy & PII Scrubbing

Built-in client-side PII scrubbing before data leaves your infrastructure:

ag = Execlave(
    api_key="exe_prod_xxx",
    privacy={
        "scrub_pii": True,           # Enable PII detection & redaction
        "scrub_fields": ["input", "output"],  # Fields to scan
    },
)

Detected PII types: email addresses, SSNs, credit card numbers, US phone numbers, IP addresses, API keys.

Prompt Injection Scanning

The SDK scans inputs for prompt-injection patterns before sending them to your LLM:

ag = Execlave(
    api_key="exe_prod_xxx",
    enable_injection_scan=True,  # Default: True
)

# Traces with detected injection attempts are flagged automatically

Detected patterns include: "ignore previous instructions", jailbreak attempts, system prompt extraction, and more.

Kill Switch / Pause Support

Execlave supports remote agent pausing via the dashboard:

from execlave import AgentPausedError

try:
    result = answer("Process this order")
except AgentPausedError:
    # Agent was paused by an admin — handle gracefully
    return "Service temporarily unavailable"

The SDK polls for status changes in the background (configurable interval).

OpenTelemetry Integration

Export Execlave traces as OpenTelemetry spans for unified observability:

from execlave import Execlave
from execlave.otel import configure_otel

# Initialize with OTel mode
ag = Execlave(
    api_key="exe_prod_xxx",
    mode="otel",
    otlp_endpoint="http://localhost:4318",  # Your OTel collector
)

# Configure the OTel pipeline
configure_otel(ag)

Requires the otel extra: pip install execlave-sdk[otel]

Configuration

Constructor Options

Parameter Type Default Description
api_key str EXECLAVE_API_KEY env Your Execlave API key
base_url str https://api.execlave.com Execlave API URL
environment str "production" Environment tag
async_mode bool True Non-blocking trace ingestion
mode str "native" "native" or "otel"
otlp_endpoint str None OTel collector endpoint
batch_size int 100 Traces per flush batch
flush_interval_seconds int 10 Seconds between flushes
debug bool False Enable debug logging
privacy dict {} PII scrubbing config
enable_control_channel bool True Enable status polling
enable_injection_scan bool True Enable injection scanning

Environment Variables

Variable Description
EXECLAVE_API_KEY API key (alternative to constructor)
EXECLAVE_BASE_URL Base URL (alternative to constructor)

Error Handling

from execlave import ExeclaveError, ExeclaveAuthError, AgentPausedError

try:
    ag = Execlave(api_key="exe_invalid")
    ag.register_agent(agent_id="test")
except ExeclaveAuthError:
    print("Invalid API key")
except AgentPausedError:
    print("Agent is paused")
except ExeclaveError as e:
    print(f"SDK error: {e}")

Async Trace Buffer

The SDK uses a non-blocking circular buffer (max 10,000 traces) with a background flush thread. Traces are batched and sent to the Execlave API automatically.

# Manual flush (e.g., before shutdown)
ag.flush()

# Graceful shutdown
ag.shutdown()

Development

# Clone the repo
git clone https://github.com/execlave/sdk-python.git
cd execlave/sdk-python

# Install dev dependencies
pip install -e ".[test]"

# Run tests
pytest                    # 130 tests
pytest --cov=execlave   # With coverage

# Type checking
mypy execlave/

Legal

By using this SDK, you agree to the Execlave Terms of Service.

License

MIT — see LICENSE for details.

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

execlave_sdk-1.1.0.tar.gz (41.5 kB view details)

Uploaded Source

Built Distribution

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

execlave_sdk-1.1.0-py3-none-any.whl (41.5 kB view details)

Uploaded Python 3

File details

Details for the file execlave_sdk-1.1.0.tar.gz.

File metadata

  • Download URL: execlave_sdk-1.1.0.tar.gz
  • Upload date:
  • Size: 41.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for execlave_sdk-1.1.0.tar.gz
Algorithm Hash digest
SHA256 c8485f3d52e15c443d2649c6b46d8199d73a2c5e0f853a8ba4ae6cf9796df87f
MD5 3f727a8b3f4874253d8800bb200d3d16
BLAKE2b-256 47eb0766cad60cf97fd13b9f1c78c7eeba3b4a273eead0f2d572dc23f80434f1

See more details on using hashes here.

Provenance

The following attestation bundles were made for execlave_sdk-1.1.0.tar.gz:

Publisher: sdk-publish.yml on rishitmavani/execlave

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file execlave_sdk-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: execlave_sdk-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 41.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for execlave_sdk-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4452cb571e79aab3914c7dfa62ce56400ec4904b46310e1adffc5a9e93bf632c
MD5 1b9995b0be03f29b861f17491b46f444
BLAKE2b-256 f7a2d4f7393c2060831ad836d9b331321df942733db2148bb00116a8ca527a68

See more details on using hashes here.

Provenance

The following attestation bundles were made for execlave_sdk-1.1.0-py3-none-any.whl:

Publisher: sdk-publish.yml on rishitmavani/execlave

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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