relaysecurity-dev 0.1.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.
@@ -0,0 +1,6 @@
1
+ .env
2
+ .env.local
3
+ node_modules/
4
+ dist/
5
+ .vite/
6
+ .next/
@@ -0,0 +1,31 @@
1
+ Metadata-Version: 2.4
2
+ Name: relaysecurity-dev
3
+ Version: 0.1.0
4
+ Summary: Python SDK for checking AI agent tool calls with Relay.
5
+ Project-URL: Homepage, https://relay-security-lemon.vercel.app
6
+ Project-URL: Repository, https://github.com/aniiketvarshney/Relay-Security
7
+ Author: Relay Security
8
+ License-Expression: MIT
9
+ Keywords: agents,ai,guardrails,relay,security
10
+ Requires-Python: >=3.9
11
+ Requires-Dist: requests>=2.31.0
12
+ Description-Content-Type: text/markdown
13
+
14
+ # Relay Python SDK
15
+
16
+ Protect risky AI agent tool calls with Relay from Python, LangGraph, and custom
17
+ agent stacks.
18
+
19
+ ```python
20
+ from relaysecurity_dev import Relay
21
+
22
+ relay = Relay()
23
+
24
+ relay.assert_allowed("github_delete_repo", {"repo_name": "myrepo"})
25
+ ```
26
+
27
+ Set your API key before running:
28
+
29
+ ```bash
30
+ RELAY_API_KEY=relay_sk_your_key_here
31
+ ```
@@ -0,0 +1,18 @@
1
+ # Relay Python SDK
2
+
3
+ Protect risky AI agent tool calls with Relay from Python, LangGraph, and custom
4
+ agent stacks.
5
+
6
+ ```python
7
+ from relaysecurity_dev import Relay
8
+
9
+ relay = Relay()
10
+
11
+ relay.assert_allowed("github_delete_repo", {"repo_name": "myrepo"})
12
+ ```
13
+
14
+ Set your API key before running:
15
+
16
+ ```bash
17
+ RELAY_API_KEY=relay_sk_your_key_here
18
+ ```
@@ -0,0 +1,8 @@
1
+ from relaysecurity_dev import Relay
2
+
3
+ relay = Relay()
4
+
5
+
6
+ def relay_guard_node(state):
7
+ relay.assert_allowed(state["tool"], state.get("arguments", {}))
8
+ return state
@@ -0,0 +1,22 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "relaysecurity-dev"
7
+ version = "0.1.0"
8
+ description = "Python SDK for checking AI agent tool calls with Relay."
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = "MIT"
12
+ authors = [
13
+ { name = "Relay Security" }
14
+ ]
15
+ keywords = ["ai", "agents", "guardrails", "security", "relay"]
16
+ dependencies = [
17
+ "requests>=2.31.0"
18
+ ]
19
+
20
+ [project.urls]
21
+ Homepage = "https://relay-security-lemon.vercel.app"
22
+ Repository = "https://github.com/aniiketvarshney/Relay-Security"
@@ -0,0 +1,3 @@
1
+ from .client import Relay, RelayPolicyError
2
+
3
+ __all__ = ["Relay", "RelayPolicyError"]
@@ -0,0 +1,75 @@
1
+ from __future__ import annotations
2
+
3
+ import os
4
+ from collections.abc import Callable
5
+ from typing import Any, TypeVar
6
+
7
+ import requests
8
+
9
+ DEFAULT_ENDPOINT = "https://relay-security-lemon.vercel.app/api/execute"
10
+
11
+ T = TypeVar("T")
12
+
13
+
14
+ class RelayPolicyError(RuntimeError):
15
+ def __init__(self, message: str, result: dict[str, Any]):
16
+ super().__init__(message)
17
+ self.result = result
18
+
19
+
20
+ class Relay:
21
+ def __init__(
22
+ self,
23
+ api_key: str | None = None,
24
+ endpoint: str | None = None,
25
+ timeout: float = 15,
26
+ ) -> None:
27
+ self.api_key = api_key or os.getenv("RELAY_API_KEY")
28
+ self.endpoint = endpoint or os.getenv("RELAY_ENDPOINT") or DEFAULT_ENDPOINT
29
+ self.timeout = timeout
30
+
31
+ def check(
32
+ self,
33
+ tool: str,
34
+ arguments: dict[str, Any] | None = None,
35
+ ) -> dict[str, Any]:
36
+ headers = {"Content-Type": "application/json"}
37
+
38
+ if self.api_key:
39
+ headers["Authorization"] = f"Bearer {self.api_key}"
40
+
41
+ response = requests.post(
42
+ self.endpoint,
43
+ headers=headers,
44
+ json={"tool": tool, "arguments": arguments or {}},
45
+ timeout=self.timeout,
46
+ )
47
+ response.raise_for_status()
48
+ return response.json()
49
+
50
+ def assert_allowed(
51
+ self,
52
+ tool: str,
53
+ arguments: dict[str, Any] | None = None,
54
+ ) -> dict[str, Any]:
55
+ result = self.check(tool, arguments)
56
+
57
+ if result.get("status") == "blocked":
58
+ raise RelayPolicyError(
59
+ result.get("reason", "Blocked by Relay policy"),
60
+ result,
61
+ )
62
+
63
+ return result
64
+
65
+ def guard_tool(
66
+ self,
67
+ tool: str,
68
+ handler: Callable[[dict[str, Any]], T],
69
+ ) -> Callable[[dict[str, Any] | None], T]:
70
+ def guarded(arguments: dict[str, Any] | None = None) -> T:
71
+ safe_arguments = arguments or {}
72
+ self.assert_allowed(tool, safe_arguments)
73
+ return handler(safe_arguments)
74
+
75
+ return guarded