Skip to main content

🛡️ StarkGate SDK

PyPI Python

Official Python SDK for StarkGate — The Universal Firewall for AI Agents.

Installation

pip install starkgate-sdk

Quick Start

from starkgate import StarkGate

guard = StarkGate(api_key="sk_live_your_key")

result = guard.evaluate(
    agent_id="my-bot",
    policy_id="pol_safe",
    action_type="sql_query",
    payload={"query": "DROP TABLE users;"}
)

if result.is_denied:
    print(f"🛑 Blocked: {result.reason}")

Decorator Protection

from starkgate import StarkGate

guard = StarkGate(api_key="sk_live_your_key")

@guard.protect(agent_id="devops", policy_id="pol_prod", action_type="terminal")
def run_command(cmd: str):
    import os
    os.system(cmd)

run_command("ls -la")  # ✅ Allowed
run_command("rm -rf /")  # ❌ Blocked

Async Support

import asyncio
from starkgate import StarkGate

async def main():
    guard = StarkGate(api_key="sk_live_your_key")
    result = await guard.async_evaluate(
        agent_id="trading-bot",
        policy_id="pol_trading",
        action_type="execute_trade",
        payload={"amount": 50000, "ticker": "AAPL"}
    )
    print(result.decision)

asyncio.run(main())

LangChain

pip install "starkgate-sdk[langchain]"
from starkgate.langchain_guard import make_starkgate_tool

# hors-ligne : politique inline, aucun serveur
tools = [make_starkgate_tool(policy=my_policy)]
# cloud      : politique gérée côté serveur
# tools = [make_starkgate_tool(api_key="sk_live_...", policy_id="pol_x")]

OpenAI (function calling)

pip install "starkgate-sdk[langchain]"   # ou sans LangChain
from starkgate.openai_guard import make_starkgate_function, run_starkgate_call

tools = [make_starkgate_function(policy=my_policy)]          # mode local
# … app de chat avec tools=tools ; le modèle renvoie tool_calls …

verdict = run_starkgate_call(policy=my_policy, action_type="transfer",
                            payload={"op": "payday"})
if verdict["decision"] == "ALLOW":
    exécuter_l_action()
else:
    # disjoncteur : bloqué, preuve dans verdict["auditHash"]
    refuser(verdict)

Engine local (hors-ligne)

Le moteur d'évaluation peut tourner sans aucun serveur — bit-à-bit identique au moteur serveur (mêmes verdicts, mêmes auditHash). Idéal pour l'edge, l'air-gap, le drone, la voiture ou le satellite.

from starkgate import engine

policy = {
  "id": "pol-1", "name": "demo", "mode": "enforce", "defaultDecision": "ALLOW",
  "rules": [{
    "id": "r1", "name": "block payday", "enabled": True,
    "condition": {"field": "op", "operator": "eq", "value": "payday"},
    "decision": "DENY", "message": "Bloqué.", "riskLevel": "high",
  }],
}

verdict = engine.evaluate(
  {"agentId": "bot", "policyId": "pol-1",
   "actionType": "transfer", "payload": {"op": "payday"}},
  policy,
)
print(verdict["decision"], verdict["auditHash"])  # DENY sha256:…

Transform post-ALLOW

Une règle ALLOW gagnante peut porter un transform qui mute la payload avant signature. Ops : set, floor, ceiling, replace ; chemin pointé concret (clés + index numériques). Le verdict expose transformApplied et transformedPayload ; auditHash couvre la payload finale. Fail-closed : un transform invalide → DENY (transform invalid (…)). Parité bit-à-bit avec TS/Rust (design figé : docs/TRANSFORM.md).

policy = {
  "id": "pol-2", "name": "annotate", "mode": "enforce",
  "defaultDecision": "DENY",
  "rules": [{
    "id": "r1", "name": "annotate transfer", "enabled": True,
    "condition": {"field": "op", "operator": "eq", "value": "transfer"},
    "decision": "ALLOW", "message": "annotation appliquée", "riskLevel": "medium",
    "transform": {"type": "set", "path": "meta.annotated", "value": True},
  }],
}

verdict = engine.evaluate(
  {"agentId": "bot", "policyId": "pol-2",
   "actionType": "transfer", "payload": {"op": "transfer", "amount": 100}},
  policy,
)
assert verdict["decision"] == "ALLOW"
assert verdict["transformApplied"] is True
assert verdict["transformedPayload"]["meta"]["annotated"] is True

Serveur MCP

Expose StarkGate à n'importe quel agent (Claude Desktop, Cursor, claude-code…) via le Model Context Protocol.

pip install "starkgate-sdk[mcp]"
python -m starkgate.mcp_server            # stdio

Outils : evaluate (cloud ou local), evaluate_local (100 % hors-ligne) et verify (re-vérifie une preuve sans le serveur).

Exemple de config claude_desktop_config.json :

{
  "mcpServers": {
    "starkgate": {
      "command": "python",
      "args": ["-m", "starkgate.mcp_server"]
    }
  }
}

Démo de bout en bout

pip install "starkgate-sdk[mcp]"
python examples/demo.py

Enregistre un compte, crée une policy, évalue ALLOW + DENY en production, puis re-vérifie la preuve cryptographique hors-ligne — « Trust the Math, not the Platform. »

License

MIT

Release files for starkgate-sdk 0.3.3

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

Source distribution (sdist)

Source distribution for starkgate-sdk 0.3.3
File Size Uploaded
starkgate_sdk-0.3.3.tar.gz 615.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for starkgate-sdk 0.3.3
File Interpreter ABI Platform
starkgate_sdk-0.3.3-py3-none-any.whl Python 3 none any Details

Total release size: 1.2 MB

Release files / starkgate_sdk-0.3.3.tar.gz

Download URL starkgate_sdk-0.3.3.tar.gz
Size 615.3 kB
Tags Source
SHA-256 checksum
How to use checksums
7a32d46ef0b1e00cbf7d825c315d5240b016bad688cd1faa72e35544a0fec83b
BLAKE2b-256 checksum
How to use checksums
bbc56a71982409461e9b0bf485242991da682419403109fcec28b25d0b239c4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9

Release files / starkgate_sdk-0.3.3-py3-none-any.whl

Download URL starkgate_sdk-0.3.3-py3-none-any.whl
Size 602.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5a39ab54079a4762ca6dfdb5733998f268cad9815c5a9120c91b07b91fc75cec
BLAKE2b-256 checksum
How to use checksums
ea1fe12d1942330811686239c9671ac8adfe8059204a6149ac45286ff8024a21
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9

Release history Release notifications | RSS feed

0.4.0

2 release files

This release

0.3.3 This release

2 release files

0.3.2

2 release files

0.2.0

2 release files

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