Skip to main content

gatra-sdk: Zero-Trust AI Agent Security SDK (Python)

Official Python client SDK for GATRA — the Zero-Trust Security Proxy & Control Plane for AI Agents, Model Context Protocol (MCP) servers, and LLM tool calls.


Overview

gatra-sdk provides native, zero-dependency Python utilities for orchestrating autonomous AI agents behind a GATRA Security Proxy. It enables Python agent frameworks (LangChain, LlamaIndex, CrewAI, AutoGen, or custom MCP clients) to mint local Ed25519 capability tokens and route tool calls through GATRA's cryptographic policy engine.

┌─────────────────┐       ┌───────────────────────────────┐       ┌─────────────────┐
│                 │  HTTP │    GATRA Security Proxy       │  HTTP │                 │
│   LLM Agent /   ├──────>│  • Ed25519 Token Auth         ├──────>│   Downstream    │
│  Orchestrator   │       │  • Stateful Trajectory Caps   │       │   MCP Tool /    │
│  (gatra-sdk)    │       │  • Schema Auto-Discovery      │       │   API Target    │
└─────────────────┘       └───────────────────────────────┘       └─────────────────┘

Key Features

  • Asymmetric Token Minting: Mint short-lived, Ed25519-signed capability tokens locally without contacting a central authorization server.
  • Proxy Client Wrapper: Executing requests through GatraClient automatically injects security headers (X-Capability-Token, X-Gatra-Directive).
  • Ephemeral Task Directives: Pass runtime, per-task guardrails directly in requests while preserving GATRA's Monotonic Restriction Principle.
  • Zero Heavy Dependencies: Pure Python implementation using Standard Library and cryptography for lightning-fast capability token minting.

Installation

pip install gatra-sdk

Quickstart

Prerequisite: Ensure you have generated an Ed25519 keypair and the GATRA proxy is running locally on port 8080:

# 1. Generate Ed25519 keypair (prints Public Key and Private Key)
./bin/gatra gen-keys -t session_101 -p "*" --json

# 2. Start proxy using the generated PUBLIC key
./bin/gatra start -c policy.json -k "<YOUR_PUBLIC_KEY>" --port 8080 --target http://localhost:3000

1. Basic Token Minting & Tool Execution

from gatra import GatraTokenIssuer, GatraClient

# Step 1: Initialize Token Issuer with your generated PRIVATE key
issuer = GatraTokenIssuer(private_key_base64="YOUR_BASE64_PRIVATE_KEY")

# Step 2: Mint a capability token bound to a specific trajectory/session
capability_token = issuer.mint_token(
    trajectory_id="session_101",
    tool_pattern="*"
)

# Step 3: Initialize GATRA Client pointing to your security proxy instance at localhost:8080
client = GatraClient(
    proxy_url="http://localhost:8080",
    capability_token=capability_token
)

# Step 4: Execute a tool call safely through GATRA Proxy
status, response, latency_ms = client.execute_tool(
    path="/v1/action",
    payload={
        "amount": 25.00,
        "currency": "USD"
    }
)

print(f"[HTTP {status}] Executed in {latency_ms}ms:", response)

Ephemeral Task Directives

Orchestrators can dynamically inject tighter guardrails for a specific execution step without altering global proxy policies:

import json

# Define an ephemeral constraint for this specific invocation
ephemeral_directive = json.dumps({
    "max_per_call": 30.00,
    "condition": "payload.currency == 'USD'"
})

# Execute request with directive attached
status, response, latency_ms = client.execute_tool(
    path="/v1/action",
    payload={"amount": 25.00, "currency": "USD"},
    directive=ephemeral_directive
)

API Reference

GatraTokenIssuer

  • __init__(private_key_base64: str) — Initializes issuer with an Ed25519 private key.
  • mint_token(trajectory_id: str, tool_pattern: str, ttl_seconds: int = 3600) -> str — Signs and returns a compact Ed25519 capability token.

GatraClient

  • __init__(proxy_url: str, capability_token: str = None) — Initializes proxy client targeting a GATRA gateway.
  • execute_tool(path: str, payload: dict, directive: str = None) -> tuple[int, dict, float] — Dispatch HTTP POST requests with automatically managed security headers. Returns (status_code, response_json, latency_ms).

Resources


License

Distributed under the MIT License.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gatra_sdk-0.1.9.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

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

gatra_sdk-0.1.9-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file gatra_sdk-0.1.9.tar.gz.

File metadata

  • Download URL: gatra_sdk-0.1.9.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.15

File hashes

Hashes for gatra_sdk-0.1.9.tar.gz
Algorithm Hash digest
SHA256 bc96da5709789ef49ea8aa937b875f0e8d4ab54d8d28b3789b161817b014d7b5
MD5 0aee5be20b7bd24063545c8f008bace3
BLAKE2b-256 675e154cb402610dcb6fbc7bdac8b02a070ed3436b5e3e2f73be767688471a26

See more details on using hashes here.

File details

Details for the file gatra_sdk-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: gatra_sdk-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.15

File hashes

Hashes for gatra_sdk-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 56c3209eb6cfd7bcea9348ebf4588a94b27de7f0db10fd8aa7e974586ed409bb
MD5 dc86eef1c3c5b60bd2ec20b60a138ce7
BLAKE2b-256 f549d925c288fbfdcf726f7978ffa48b1fa27ad07e85ca618c25bdba4ed53e86

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 Sentry Error logging StatusPage Status page