Skip to main content

Official Python SDK for Gateplex — the governance firewall for autonomous AI agents

Project description

gateplex-python

Official Python SDK for Gateplex — the governance firewall for autonomous AI agents. Intercept, evaluate, and enforce rules on every agent action before it executes.

PyPI version Python versions


Installation

pip install gateplex-python

Optional extras for LLM auto-patching:

pip install "gateplex-python[openai]"       # OpenAI support
pip install "gateplex-python[anthropic]"    # Anthropic support
pip install "gateplex-python[all]"          # Everything

Quick start

from gateplex import GateplexClient

client = GateplexClient(api_key="gplx_your_key_here")

response = client.log_intercept(
    agent_id="my-agent-uuid",
    event_type="llm_call",       # "llm_call" | "tool_call" | "guardrail_trigger"
    input="What is the capital of France?",
    output="Paris.",
    model="gpt-4o",
    latency_ms=342,
    flagged=False,
    metadata={"user_id": "u_123"},
)

print(response.intercept_id)   # uuid
print(response.flagged)        # bool

Features

Automatic latency measurement — context manager

with client.capture(
    agent_id="my-agent",
    event_type="llm_call",
    input=user_prompt,
    model="gpt-4o",
) as ctx:
    ctx.output = call_my_llm(user_prompt)   # latency measured automatically

@monitor decorator

from gateplex import monitor

@monitor(client, agent_id="my-agent", event_type="llm_call", model="gpt-4o")
def call_llm(input: str) -> str:
    return openai_client.chat.completions.create(...)

Background batch logging

Fire-and-forget for high-throughput pipelines:

# Enqueued immediately, sent by a background thread
client.batch_intercept(
    agent_id="my-agent",
    event_type="tool_call",
    input='search("latest AI news")',
    output='["OpenAI launches...", ...]',
    model="gpt-4o",
)

# Force flush before process exit
client.flush()

OpenAI auto-patcher

Automatically intercepts every chat.completions.create call:

import openai
from gateplex import GateplexClient
from gateplex import OpenAIPatcher

gp = GateplexClient(api_key="gplx_...")
oai = openai.OpenAI(api_key="sk-...")

patcher = OpenAIPatcher(gp, agent_id="my-agent", openai_client=oai)
patcher.patch()

# Use oai normally — all calls are logged
response = oai.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello!"}],
)

patcher.unpatch()   # remove when done

Anthropic auto-patcher

import anthropic
from gateplex import GateplexClient
from gateplex import AnthropicPatcher

gp = GateplexClient(api_key="gplx_...")
ant = anthropic.Anthropic(api_key="sk-ant-...")

patcher = AnthropicPatcher(gp, agent_id="my-agent", anthropic_client=ant)
patcher.patch()

message = ant.messages.create(
    model="claude-sonnet-4-20250514",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello!"}],
)

patcher.unpatch()

Public REST endpoints

# List intercepts (paginated)
intercepts = client.get_intercepts(limit=20, offset=0, agent_id="my-agent")

# Create an intercept via the public REST API
result = client.create_intercept(
    agent_id="my-agent",
    event_type="llm_call",
    input="Hello",
    output="Hi!",
    model="gpt-4o",
)

# Fetch guardrail definitions
guardrails = client.get_guardrails()
for g in guardrails:
    print(g.name, g.enabled)

Configuration

Parameter Default Description
api_key Your gplx_... API key (required)
timeout 10.0 HTTP timeout in seconds
max_retries 3 Retries with exponential back-off (on 429/5xx)
batch_size 50 Max events in background queue before forced flush
flush_interval 5.0 Seconds between background flushes
raise_on_error False Set True to surface API errors instead of logging them
client = GateplexClient(
    api_key="gplx_...",
    timeout=5.0,
    max_retries=5,
    flush_interval=2.0,
    raise_on_error=True,   # great for dev/test
)

Error handling

from gateplex import GateplexAuthError, GateplexAPIError

try:
    client.log_intercept(...)
except GateplexAuthError:
    print("Check your API key")
except GateplexAPIError as e:
    print(f"API error: {e}")

License

MIT

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

gateplex_python-0.2.1.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

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

gateplex_python-0.2.1-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gateplex_python-0.2.1.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for gateplex_python-0.2.1.tar.gz
Algorithm Hash digest
SHA256 23338f059b5d6cdb52b5e9b7f2090e8a5bd99df534034db45dbb24a20f539851
MD5 27e629736f541f2336e7ae16beb65c81
BLAKE2b-256 517c733388421a25cff177244472a88201cbb1446a742590036ba4a253c74284

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gateplex_python-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8b7dd03b8e28cd215ef1fdecf45880b73d86cc874e0c96f9965837f8609525c7
MD5 85dcd4cc5caec975c30933fd82acf1d6
BLAKE2b-256 57cae0daf9979a71da833d4a04b0b8b3b2e2602fc964d990966b4832b08fa3b7

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