relaysecurity-dev 0.1.0__py3-none-any.whl

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,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
@@ -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,5 @@
1
+ relaysecurity_dev/__init__.py,sha256=EPLBIbyOkn72sAmG0kI6Cb4d_iLbyqZOLJRyQI9EvM4,85
2
+ relaysecurity_dev/client.py,sha256=ksQHlUk28ZaiFWzxppOK9nvaFJAJs6AdH72Kfkrr_wE,2030
3
+ relaysecurity_dev-0.1.0.dist-info/METADATA,sha256=cowZLSn17Cb19-JkOTAk7AU__3eU9fOPy3DaDjppwgI,788
4
+ relaysecurity_dev-0.1.0.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
5
+ relaysecurity_dev-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.30.1
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any