starkgate-sdk 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. starkgate_sdk-0.2.0/LICENSE +21 -0
  2. starkgate_sdk-0.2.0/MANIFEST.in +5 -0
  3. starkgate_sdk-0.2.0/PKG-INFO +202 -0
  4. starkgate_sdk-0.2.0/README.md +165 -0
  5. starkgate_sdk-0.2.0/pyproject.toml +59 -0
  6. starkgate_sdk-0.2.0/setup.cfg +4 -0
  7. starkgate_sdk-0.2.0/src/starkgate/__init__.py +42 -0
  8. starkgate_sdk-0.2.0/src/starkgate/client.py +388 -0
  9. starkgate_sdk-0.2.0/src/starkgate/ed25519.py +58 -0
  10. starkgate_sdk-0.2.0/src/starkgate/engine.py +890 -0
  11. starkgate_sdk-0.2.0/src/starkgate/langchain_guard.py +93 -0
  12. starkgate_sdk-0.2.0/src/starkgate/local_audit.py +117 -0
  13. starkgate_sdk-0.2.0/src/starkgate/mcp_server.py +207 -0
  14. starkgate_sdk-0.2.0/src/starkgate/models.py +98 -0
  15. starkgate_sdk-0.2.0/src/starkgate/normalization.py +193 -0
  16. starkgate_sdk-0.2.0/src/starkgate/openai_guard.py +148 -0
  17. starkgate_sdk-0.2.0/src/starkgate/starkgate_engine.wasm +0 -0
  18. starkgate_sdk-0.2.0/src/starkgate/wasm_native.py +243 -0
  19. starkgate_sdk-0.2.0/src/starkgate_sdk.egg-info/PKG-INFO +202 -0
  20. starkgate_sdk-0.2.0/src/starkgate_sdk.egg-info/SOURCES.txt +29 -0
  21. starkgate_sdk-0.2.0/src/starkgate_sdk.egg-info/dependency_links.txt +1 -0
  22. starkgate_sdk-0.2.0/src/starkgate_sdk.egg-info/requires.txt +16 -0
  23. starkgate_sdk-0.2.0/src/starkgate_sdk.egg-info/top_level.txt +1 -0
  24. starkgate_sdk-0.2.0/tests/test_client.py +400 -0
  25. starkgate_sdk-0.2.0/tests/test_engine_parity.py +42 -0
  26. starkgate_sdk-0.2.0/tests/test_guards.py +89 -0
  27. starkgate_sdk-0.2.0/tests/test_local_audit.py +110 -0
  28. starkgate_sdk-0.2.0/tests/test_mcp.py +95 -0
  29. starkgate_sdk-0.2.0/tests/test_merkle_parity.py +73 -0
  30. starkgate_sdk-0.2.0/tests/test_parity.py +143 -0
  31. starkgate_sdk-0.2.0/tests/test_wasm_ed25519.py +58 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Sentinel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,5 @@
1
+ include README.md
2
+ include LICENSE
3
+ include pyproject.toml
4
+ recursive-include tests *.py
5
+ recursive-include src/starkgate *.py
@@ -0,0 +1,202 @@
1
+ Metadata-Version: 2.4
2
+ Name: starkgate-sdk
3
+ Version: 0.2.0
4
+ Summary: Official Python SDK for StarkGate — The Universal Firewall for AI Agents
5
+ Author-email: StarkGate <hello@starkgate.dev>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/wenjoseph16/starkgate
8
+ Project-URL: Documentation, https://docs.starkgate.dev
9
+ Project-URL: Repository, https://github.com/wenjoseph16/starkgate
10
+ Project-URL: Issues, https://github.com/wenjoseph16/starkgate/issues
11
+ Keywords: ai,guardrails,security,agents,firewall
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Security
20
+ Classifier: Topic :: Software Development :: Libraries
21
+ Requires-Python: >=3.9
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: httpx>=0.25.0
25
+ Requires-Dist: cryptography>=41.0.0
26
+ Provides-Extra: dev
27
+ Requires-Dist: pytest>=7.0; extra == "dev"
28
+ Requires-Dist: pytest-asyncio>=0.21; extra == "dev"
29
+ Provides-Extra: wasm
30
+ Requires-Dist: wasmtime>=25.0; extra == "wasm"
31
+ Provides-Extra: mcp
32
+ Requires-Dist: mcp>=1.20; extra == "mcp"
33
+ Requires-Dist: pydantic>=2.0; extra == "mcp"
34
+ Provides-Extra: langchain
35
+ Requires-Dist: langchain-core>=0.3; extra == "langchain"
36
+ Dynamic: license-file
37
+
38
+ # 🛡️ StarkGate SDK
39
+
40
+ Official Python SDK for [StarkGate](https://github.com/wenjoseph16/starkgate) — The Universal Firewall for AI Agents.
41
+
42
+ ## Installation
43
+
44
+ ```bash
45
+ pip install starkgate-sdk
46
+ ```
47
+
48
+ ## Quick Start
49
+
50
+ ```python
51
+ from starkgate import StarkGate
52
+
53
+ guard = StarkGate(api_key="sk_live_your_key")
54
+
55
+ result = guard.evaluate(
56
+ agent_id="my-bot",
57
+ policy_id="pol_safe",
58
+ action_type="sql_query",
59
+ payload={"query": "DROP TABLE users;"}
60
+ )
61
+
62
+ if result.is_denied:
63
+ print(f"🛑 Blocked: {result.reason}")
64
+ ```
65
+
66
+ ## Decorator Protection
67
+
68
+ ```python
69
+ from starkgate import StarkGate
70
+
71
+ guard = StarkGate(api_key="sk_live_your_key")
72
+
73
+ @guard.protect(agent_id="devops", policy_id="pol_prod", action_type="terminal")
74
+ def run_command(cmd: str):
75
+ import os
76
+ os.system(cmd)
77
+
78
+ run_command("ls -la") # ✅ Allowed
79
+ run_command("rm -rf /") # ❌ Blocked
80
+ ```
81
+
82
+ ## Async Support
83
+
84
+ ```python
85
+ import asyncio
86
+ from starkgate import StarkGate
87
+
88
+ async def main():
89
+ guard = StarkGate(api_key="sk_live_your_key")
90
+ result = await guard.async_evaluate(
91
+ agent_id="trading-bot",
92
+ policy_id="pol_trading",
93
+ action_type="execute_trade",
94
+ payload={"amount": 50000, "ticker": "AAPL"}
95
+ )
96
+ print(result.decision)
97
+
98
+ asyncio.run(main())
99
+ ```
100
+
101
+ ## LangChain
102
+
103
+ ```bash
104
+ pip install "starkgate-sdk[langchain]"
105
+ ```
106
+
107
+ ```python
108
+ from starkgate.langchain_guard import make_starkgate_tool
109
+
110
+ # hors-ligne : politique inline, aucun serveur
111
+ tools = [make_starkgate_tool(policy=my_policy)]
112
+ # cloud : politique gérée côté serveur
113
+ # tools = [make_starkgate_tool(api_key="sk_live_...", policy_id="pol_x")]
114
+ ```
115
+
116
+ ## OpenAI (function calling)
117
+
118
+ ```bash
119
+ pip install "starkgate-sdk[langchain]" # ou sans LangChain
120
+ ```
121
+
122
+ ```python
123
+ from starkgate.openai_guard import make_starkgate_function, run_starkgate_call
124
+
125
+ tools = [make_starkgate_function(policy=my_policy)] # mode local
126
+ # … app de chat avec tools=tools ; le modèle renvoie tool_calls …
127
+
128
+ verdict = run_starkgate_call(policy=my_policy, action_type="transfer",
129
+ payload={"op": "payday"})
130
+ if verdict["decision"] == "ALLOW":
131
+ exécuter_l_action()
132
+ else:
133
+ # disjoncteur : bloqué, preuve dans verdict["auditHash"]
134
+ refuser(verdict)
135
+ ```
136
+
137
+ ## Engine local (hors-ligne)
138
+
139
+ Le moteur d'évaluation peut tourner **sans aucun serveur** — bit-à-bit identique
140
+ au moteur serveur (mêmes verdicts, mêmes `auditHash`). Idéal pour l'edge,
141
+ l'air-gap, le drone, la voiture ou le satellite.
142
+
143
+ ```python
144
+ from starkgate import engine
145
+
146
+ policy = {
147
+ "id": "pol-1", "name": "demo", "mode": "enforce", "defaultDecision": "ALLOW",
148
+ "rules": [{
149
+ "id": "r1", "name": "block payday", "enabled": True,
150
+ "condition": {"field": "op", "operator": "eq", "value": "payday"},
151
+ "decision": "DENY", "message": "Bloqué.", "riskLevel": "high",
152
+ }],
153
+ }
154
+
155
+ verdict = engine.evaluate(
156
+ {"agentId": "bot", "policyId": "pol-1",
157
+ "actionType": "transfer", "payload": {"op": "payday"}},
158
+ policy,
159
+ )
160
+ print(verdict["decision"], verdict["auditHash"]) # DENY sha256:…
161
+ ```
162
+
163
+ ## Serveur MCP
164
+
165
+ Expose StarkGate à n'importe quel agent (Claude Desktop, Cursor, claude-code…)
166
+ via le [Model Context Protocol](https://modelcontextprotocol.io).
167
+
168
+ ```bash
169
+ pip install "starkgate-sdk[mcp]"
170
+ python -m starkgate.mcp_server # stdio
171
+ ```
172
+
173
+ Outils : `evaluate` (cloud ou local), `evaluate_local` (100 % hors-ligne) et
174
+ `verify` (re-vérifie une preuve sans le serveur).
175
+
176
+ Exemple de config `claude_desktop_config.json` :
177
+
178
+ ```json
179
+ {
180
+ "mcpServers": {
181
+ "starkgate": {
182
+ "command": "python",
183
+ "args": ["-m", "starkgate.mcp_server"]
184
+ }
185
+ }
186
+ }
187
+ ```
188
+
189
+ ## Démo de bout en bout
190
+
191
+ ```bash
192
+ pip install "starkgate-sdk[mcp]"
193
+ python examples/demo.py
194
+ ```
195
+
196
+ Enregistre un compte, crée une policy, évalue ALLOW + DENY en production, puis
197
+ **re-vérifie la preuve cryptographique hors-ligne** — « Trust the Math, not the
198
+ Platform. »
199
+
200
+ ## License
201
+
202
+ MIT
@@ -0,0 +1,165 @@
1
+ # 🛡️ StarkGate SDK
2
+
3
+ Official Python SDK for [StarkGate](https://github.com/wenjoseph16/starkgate) — The Universal Firewall for AI Agents.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install starkgate-sdk
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```python
14
+ from starkgate import StarkGate
15
+
16
+ guard = StarkGate(api_key="sk_live_your_key")
17
+
18
+ result = guard.evaluate(
19
+ agent_id="my-bot",
20
+ policy_id="pol_safe",
21
+ action_type="sql_query",
22
+ payload={"query": "DROP TABLE users;"}
23
+ )
24
+
25
+ if result.is_denied:
26
+ print(f"🛑 Blocked: {result.reason}")
27
+ ```
28
+
29
+ ## Decorator Protection
30
+
31
+ ```python
32
+ from starkgate import StarkGate
33
+
34
+ guard = StarkGate(api_key="sk_live_your_key")
35
+
36
+ @guard.protect(agent_id="devops", policy_id="pol_prod", action_type="terminal")
37
+ def run_command(cmd: str):
38
+ import os
39
+ os.system(cmd)
40
+
41
+ run_command("ls -la") # ✅ Allowed
42
+ run_command("rm -rf /") # ❌ Blocked
43
+ ```
44
+
45
+ ## Async Support
46
+
47
+ ```python
48
+ import asyncio
49
+ from starkgate import StarkGate
50
+
51
+ async def main():
52
+ guard = StarkGate(api_key="sk_live_your_key")
53
+ result = await guard.async_evaluate(
54
+ agent_id="trading-bot",
55
+ policy_id="pol_trading",
56
+ action_type="execute_trade",
57
+ payload={"amount": 50000, "ticker": "AAPL"}
58
+ )
59
+ print(result.decision)
60
+
61
+ asyncio.run(main())
62
+ ```
63
+
64
+ ## LangChain
65
+
66
+ ```bash
67
+ pip install "starkgate-sdk[langchain]"
68
+ ```
69
+
70
+ ```python
71
+ from starkgate.langchain_guard import make_starkgate_tool
72
+
73
+ # hors-ligne : politique inline, aucun serveur
74
+ tools = [make_starkgate_tool(policy=my_policy)]
75
+ # cloud : politique gérée côté serveur
76
+ # tools = [make_starkgate_tool(api_key="sk_live_...", policy_id="pol_x")]
77
+ ```
78
+
79
+ ## OpenAI (function calling)
80
+
81
+ ```bash
82
+ pip install "starkgate-sdk[langchain]" # ou sans LangChain
83
+ ```
84
+
85
+ ```python
86
+ from starkgate.openai_guard import make_starkgate_function, run_starkgate_call
87
+
88
+ tools = [make_starkgate_function(policy=my_policy)] # mode local
89
+ # … app de chat avec tools=tools ; le modèle renvoie tool_calls …
90
+
91
+ verdict = run_starkgate_call(policy=my_policy, action_type="transfer",
92
+ payload={"op": "payday"})
93
+ if verdict["decision"] == "ALLOW":
94
+ exécuter_l_action()
95
+ else:
96
+ # disjoncteur : bloqué, preuve dans verdict["auditHash"]
97
+ refuser(verdict)
98
+ ```
99
+
100
+ ## Engine local (hors-ligne)
101
+
102
+ Le moteur d'évaluation peut tourner **sans aucun serveur** — bit-à-bit identique
103
+ au moteur serveur (mêmes verdicts, mêmes `auditHash`). Idéal pour l'edge,
104
+ l'air-gap, le drone, la voiture ou le satellite.
105
+
106
+ ```python
107
+ from starkgate import engine
108
+
109
+ policy = {
110
+ "id": "pol-1", "name": "demo", "mode": "enforce", "defaultDecision": "ALLOW",
111
+ "rules": [{
112
+ "id": "r1", "name": "block payday", "enabled": True,
113
+ "condition": {"field": "op", "operator": "eq", "value": "payday"},
114
+ "decision": "DENY", "message": "Bloqué.", "riskLevel": "high",
115
+ }],
116
+ }
117
+
118
+ verdict = engine.evaluate(
119
+ {"agentId": "bot", "policyId": "pol-1",
120
+ "actionType": "transfer", "payload": {"op": "payday"}},
121
+ policy,
122
+ )
123
+ print(verdict["decision"], verdict["auditHash"]) # DENY sha256:…
124
+ ```
125
+
126
+ ## Serveur MCP
127
+
128
+ Expose StarkGate à n'importe quel agent (Claude Desktop, Cursor, claude-code…)
129
+ via le [Model Context Protocol](https://modelcontextprotocol.io).
130
+
131
+ ```bash
132
+ pip install "starkgate-sdk[mcp]"
133
+ python -m starkgate.mcp_server # stdio
134
+ ```
135
+
136
+ Outils : `evaluate` (cloud ou local), `evaluate_local` (100 % hors-ligne) et
137
+ `verify` (re-vérifie une preuve sans le serveur).
138
+
139
+ Exemple de config `claude_desktop_config.json` :
140
+
141
+ ```json
142
+ {
143
+ "mcpServers": {
144
+ "starkgate": {
145
+ "command": "python",
146
+ "args": ["-m", "starkgate.mcp_server"]
147
+ }
148
+ }
149
+ }
150
+ ```
151
+
152
+ ## Démo de bout en bout
153
+
154
+ ```bash
155
+ pip install "starkgate-sdk[mcp]"
156
+ python examples/demo.py
157
+ ```
158
+
159
+ Enregistre un compte, crée une policy, évalue ALLOW + DENY en production, puis
160
+ **re-vérifie la preuve cryptographique hors-ligne** — « Trust the Math, not the
161
+ Platform. »
162
+
163
+ ## License
164
+
165
+ MIT
@@ -0,0 +1,59 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68.0", "wheel"]
3
+ build-backend = "setuptools.build_meta:__legacy__"
4
+
5
+ [project]
6
+ name = "starkgate-sdk"
7
+ version = "0.2.0"
8
+ description = "Official Python SDK for StarkGate — The Universal Firewall for AI Agents"
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ requires-python = ">=3.9"
12
+ authors = [{name = "StarkGate", email = "hello@starkgate.dev"}]
13
+ keywords = ["ai", "guardrails", "security", "agents", "firewall"]
14
+ classifiers = [
15
+ "Development Status :: 4 - Beta",
16
+ "Intended Audience :: Developers",
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3.9",
19
+ "Programming Language :: Python :: 3.10",
20
+ "Programming Language :: Python :: 3.11",
21
+ "Programming Language :: Python :: 3.12",
22
+ "Topic :: Security",
23
+ "Topic :: Software Development :: Libraries",
24
+ ]
25
+ dependencies = [
26
+ "httpx>=0.25.0",
27
+ "cryptography>=41.0.0",
28
+ ]
29
+
30
+ [project.optional-dependencies]
31
+ dev = [
32
+ "pytest>=7.0",
33
+ "pytest-asyncio>=0.21",
34
+ ]
35
+ wasm = [
36
+ "wasmtime>=25.0",
37
+ ]
38
+ mcp = [
39
+ "mcp>=1.20",
40
+ "pydantic>=2.0",
41
+ ]
42
+ langchain = [
43
+ "langchain-core>=0.3",
44
+ ]
45
+
46
+ [project.urls]
47
+ Homepage = "https://github.com/wenjoseph16/starkgate"
48
+ Documentation = "https://docs.starkgate.dev"
49
+ Repository = "https://github.com/wenjoseph16/starkgate"
50
+ Issues = "https://github.com/wenjoseph16/starkgate/issues"
51
+
52
+ [tool.setuptools.packages.find]
53
+ where = ["src"]
54
+
55
+ [tool.setuptools.package-data]
56
+ starkgate = ["*.wasm"]
57
+
58
+ [tool.pytest.ini_options]
59
+ testpaths = ["tests"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,42 @@
1
+ from starkgate.client import StarkGate
2
+ from starkgate.models import EvaluationResult, Policy, Rule
3
+ from starkgate.ed25519 import (
4
+ sign_ed25519,
5
+ verify_ed25519,
6
+ ed25519_public_key,
7
+ )
8
+ from starkgate.local_audit import (
9
+ audit_hash,
10
+ chain_hash,
11
+ verify_chain,
12
+ verify_audit_entry,
13
+ verify_verdict_local,
14
+ )
15
+ from starkgate.engine import (
16
+ evaluate as evaluate,
17
+ evaluate_condition,
18
+ evaluate_operator,
19
+ get_nested_value,
20
+ StarkGateLocalError,
21
+ )
22
+
23
+ __version__ = "0.2.0"
24
+ __all__ = [
25
+ "StarkGate",
26
+ "EvaluationResult",
27
+ "Policy",
28
+ "Rule",
29
+ "sign_ed25519",
30
+ "verify_ed25519",
31
+ "ed25519_public_key",
32
+ "audit_hash",
33
+ "chain_hash",
34
+ "verify_chain",
35
+ "verify_audit_entry",
36
+ "verify_verdict_local",
37
+ "evaluate",
38
+ "evaluate_condition",
39
+ "evaluate_operator",
40
+ "get_nested_value",
41
+ "StarkGateLocalError",
42
+ ]