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.

Metadata

Release files for gatra-sdk 0.1.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gatra-sdk 0.1.9
File Size Uploaded Provenance
gatra_sdk-0.1.9.tar.gz 4.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for gatra-sdk 0.1.9
File Interpreter ABI Platform
gatra_sdk-0.1.9-py3-none-any.whl Python 3 none any Details

Total release size: 9.2 kB

Release files / gatra_sdk-0.1.9.tar.gz

Download URL gatra_sdk-0.1.9.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
bc96da5709789ef49ea8aa937b875f0e8d4ab54d8d28b3789b161817b014d7b5
BLAKE2b-256 checksum
How to use checksums
675e154cb402610dcb6fbc7bdac8b02a070ed3436b5e3e2f73be767688471a26
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.15

Release files / gatra_sdk-0.1.9-py3-none-any.whl

Download URL gatra_sdk-0.1.9-py3-none-any.whl
Size 4.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
56c3209eb6cfd7bcea9348ebf4588a94b27de7f0db10fd8aa7e974586ed409bb
BLAKE2b-256 checksum
How to use checksums
f549d925c288fbfdcf726f7978ffa48b1fa27ad07e85ca618c25bdba4ed53e86
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.15

Security for gatra-sdk 0.1.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page