permiscope 2.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.
@@ -0,0 +1,62 @@
1
+ Metadata-Version: 2.4
2
+ Name: permiscope
3
+ Version: 2.2.0
4
+ Summary: Dependency-free Python client for the Permiscope governance sidecar
5
+ Author: Shubham Sharma
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/shubhusion/Permiscope
8
+ Project-URL: Documentation, https://github.com/shubhusion/Permiscope/blob/main/python/README.md
9
+ Keywords: agents,governance,policy,audit,sidecar
10
+ Requires-Python: >=3.10
11
+ Description-Content-Type: text/markdown
12
+
13
+ # Permiscope Python SDK
14
+
15
+ A dependency-free client for the Permiscope governance sidecar. It uses only the
16
+ Python standard library.
17
+
18
+ > **Release status:** packaging is prepared but not yet published to PyPI. Once
19
+ > v2.2.0 is published, install with `pip install permiscope`. Until then, run from a
20
+ > checkout with `PYTHONPATH=python python python/example_agent.py`.
21
+
22
+ ## Install
23
+
24
+ ```bash
25
+ pip install permiscope
26
+ ```
27
+
28
+ ## Start the sidecar
29
+
30
+ ```bash
31
+ PERMISCOPE_SIDECAR_TOKEN=dev-token npx permiscope serve
32
+ ```
33
+
34
+ It binds to `127.0.0.1:8787` by default. Override with `PERMISCOPE_SIDECAR_HOST`
35
+ and `PERMISCOPE_SIDECAR_PORT`. Non-loopback binding is refused unless the sidecar
36
+ is created programmatically with `allowRemote: true`.
37
+
38
+ ## Use it
39
+
40
+ ```python
41
+ from permiscope import Permiscope
42
+
43
+ scope = Permiscope(token="dev-token")
44
+
45
+ decision = scope.decide("run_command", {"command": "echo hello"})
46
+ if scope.allowed("read_file", {"path": "config.json"}):
47
+ ...
48
+
49
+ result = scope.execute("run_command", {"command": "echo governed"})
50
+ print(result["decision"], result["success"])
51
+ ```
52
+
53
+ Run the complete example from a checkout with
54
+ `PYTHONPATH=python python python/example_agent.py`, or `python example_agent.py` from this
55
+ directory once the package is installed. The sidecar must be running.
56
+
57
+ ## API
58
+
59
+ - `decide(action_name, parameters=None, reason=None) -> str` — policy decision only.
60
+ - `allowed(...) -> bool` — convenience wrapper for `decide(...) == "ALLOW"`.
61
+ - `execute(...) -> dict` — governed execution with `{ decision, success, output, error }`.
62
+ - `PermiscopeError` — raised on HTTP errors, unreachable sidecar, or invalid JSON.
@@ -0,0 +1,50 @@
1
+ # Permiscope Python SDK
2
+
3
+ A dependency-free client for the Permiscope governance sidecar. It uses only the
4
+ Python standard library.
5
+
6
+ > **Release status:** packaging is prepared but not yet published to PyPI. Once
7
+ > v2.2.0 is published, install with `pip install permiscope`. Until then, run from a
8
+ > checkout with `PYTHONPATH=python python python/example_agent.py`.
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ pip install permiscope
14
+ ```
15
+
16
+ ## Start the sidecar
17
+
18
+ ```bash
19
+ PERMISCOPE_SIDECAR_TOKEN=dev-token npx permiscope serve
20
+ ```
21
+
22
+ It binds to `127.0.0.1:8787` by default. Override with `PERMISCOPE_SIDECAR_HOST`
23
+ and `PERMISCOPE_SIDECAR_PORT`. Non-loopback binding is refused unless the sidecar
24
+ is created programmatically with `allowRemote: true`.
25
+
26
+ ## Use it
27
+
28
+ ```python
29
+ from permiscope import Permiscope
30
+
31
+ scope = Permiscope(token="dev-token")
32
+
33
+ decision = scope.decide("run_command", {"command": "echo hello"})
34
+ if scope.allowed("read_file", {"path": "config.json"}):
35
+ ...
36
+
37
+ result = scope.execute("run_command", {"command": "echo governed"})
38
+ print(result["decision"], result["success"])
39
+ ```
40
+
41
+ Run the complete example from a checkout with
42
+ `PYTHONPATH=python python python/example_agent.py`, or `python example_agent.py` from this
43
+ directory once the package is installed. The sidecar must be running.
44
+
45
+ ## API
46
+
47
+ - `decide(action_name, parameters=None, reason=None) -> str` — policy decision only.
48
+ - `allowed(...) -> bool` — convenience wrapper for `decide(...) == "ALLOW"`.
49
+ - `execute(...) -> dict` — governed execution with `{ decision, success, output, error }`.
50
+ - `PermiscopeError` — raised on HTTP errors, unreachable sidecar, or invalid JSON.
@@ -0,0 +1,91 @@
1
+ """Tiny stdlib-only client for the Permiscope governance sidecar."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ import urllib.error
7
+ import urllib.request
8
+ from typing import Any, Dict, Optional
9
+
10
+ __all__ = ["Permiscope", "PermiscopeError"]
11
+
12
+
13
+ class PermiscopeError(Exception):
14
+ """Raised when the sidecar cannot be reached or rejects a request."""
15
+
16
+
17
+ class Permiscope:
18
+ def __init__(
19
+ self,
20
+ base_url: str = "http://127.0.0.1:8787",
21
+ token: Optional[str] = None,
22
+ timeout: float = 10.0,
23
+ ) -> None:
24
+ if not token:
25
+ raise ValueError("A sidecar bearer token is required")
26
+ self.base_url = base_url.rstrip("/")
27
+ self.token = token
28
+ self.timeout = timeout
29
+
30
+ def decide(
31
+ self,
32
+ action_name: str,
33
+ parameters: Optional[Dict[str, Any]] = None,
34
+ reason: Optional[str] = None,
35
+ ) -> str:
36
+ """Ask the sidecar for a policy decision without executing anything."""
37
+ payload = self._payload(action_name, parameters, reason)
38
+ response = self._post("/v1/decide", payload)
39
+ return str(response["decision"])
40
+
41
+ def execute(
42
+ self,
43
+ action_name: str,
44
+ parameters: Optional[Dict[str, Any]] = None,
45
+ reason: Optional[str] = None,
46
+ ) -> Dict[str, Any]:
47
+ """Ask the sidecar to govern and execute a built-in action."""
48
+ return self._post("/v1/execute", self._payload(action_name, parameters, reason))
49
+
50
+ def allowed(
51
+ self,
52
+ action_name: str,
53
+ parameters: Optional[Dict[str, Any]] = None,
54
+ reason: Optional[str] = None,
55
+ ) -> bool:
56
+ return self.decide(action_name, parameters, reason) == "ALLOW"
57
+
58
+ @staticmethod
59
+ def _payload(
60
+ action_name: str,
61
+ parameters: Optional[Dict[str, Any]],
62
+ reason: Optional[str],
63
+ ) -> Dict[str, Any]:
64
+ payload: Dict[str, Any] = {
65
+ "actionName": action_name,
66
+ "parameters": parameters or {},
67
+ }
68
+ if reason:
69
+ payload["reason"] = reason
70
+ return payload
71
+
72
+ def _post(self, path: str, payload: Dict[str, Any]) -> Dict[str, Any]:
73
+ request = urllib.request.Request(
74
+ self.base_url + path,
75
+ data=json.dumps(payload).encode("utf-8"),
76
+ headers={
77
+ "Content-Type": "application/json",
78
+ "Authorization": f"Bearer {self.token}",
79
+ },
80
+ method="POST",
81
+ )
82
+ try:
83
+ with urllib.request.urlopen(request, timeout=self.timeout) as response:
84
+ return json.loads(response.read().decode("utf-8"))
85
+ except urllib.error.HTTPError as error:
86
+ body = error.read().decode("utf-8", errors="replace")
87
+ raise PermiscopeError(f"HTTP {error.code}: {body}") from error
88
+ except urllib.error.URLError as error:
89
+ raise PermiscopeError(f"Cannot reach Permiscope sidecar: {error.reason}") from error
90
+ except json.JSONDecodeError as error:
91
+ raise PermiscopeError("Sidecar returned invalid JSON") from error
@@ -0,0 +1,62 @@
1
+ Metadata-Version: 2.4
2
+ Name: permiscope
3
+ Version: 2.2.0
4
+ Summary: Dependency-free Python client for the Permiscope governance sidecar
5
+ Author: Shubham Sharma
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/shubhusion/Permiscope
8
+ Project-URL: Documentation, https://github.com/shubhusion/Permiscope/blob/main/python/README.md
9
+ Keywords: agents,governance,policy,audit,sidecar
10
+ Requires-Python: >=3.10
11
+ Description-Content-Type: text/markdown
12
+
13
+ # Permiscope Python SDK
14
+
15
+ A dependency-free client for the Permiscope governance sidecar. It uses only the
16
+ Python standard library.
17
+
18
+ > **Release status:** packaging is prepared but not yet published to PyPI. Once
19
+ > v2.2.0 is published, install with `pip install permiscope`. Until then, run from a
20
+ > checkout with `PYTHONPATH=python python python/example_agent.py`.
21
+
22
+ ## Install
23
+
24
+ ```bash
25
+ pip install permiscope
26
+ ```
27
+
28
+ ## Start the sidecar
29
+
30
+ ```bash
31
+ PERMISCOPE_SIDECAR_TOKEN=dev-token npx permiscope serve
32
+ ```
33
+
34
+ It binds to `127.0.0.1:8787` by default. Override with `PERMISCOPE_SIDECAR_HOST`
35
+ and `PERMISCOPE_SIDECAR_PORT`. Non-loopback binding is refused unless the sidecar
36
+ is created programmatically with `allowRemote: true`.
37
+
38
+ ## Use it
39
+
40
+ ```python
41
+ from permiscope import Permiscope
42
+
43
+ scope = Permiscope(token="dev-token")
44
+
45
+ decision = scope.decide("run_command", {"command": "echo hello"})
46
+ if scope.allowed("read_file", {"path": "config.json"}):
47
+ ...
48
+
49
+ result = scope.execute("run_command", {"command": "echo governed"})
50
+ print(result["decision"], result["success"])
51
+ ```
52
+
53
+ Run the complete example from a checkout with
54
+ `PYTHONPATH=python python python/example_agent.py`, or `python example_agent.py` from this
55
+ directory once the package is installed. The sidecar must be running.
56
+
57
+ ## API
58
+
59
+ - `decide(action_name, parameters=None, reason=None) -> str` — policy decision only.
60
+ - `allowed(...) -> bool` — convenience wrapper for `decide(...) == "ALLOW"`.
61
+ - `execute(...) -> dict` — governed execution with `{ decision, success, output, error }`.
62
+ - `PermiscopeError` — raised on HTTP errors, unreachable sidecar, or invalid JSON.
@@ -0,0 +1,7 @@
1
+ README.md
2
+ pyproject.toml
3
+ permiscope/__init__.py
4
+ permiscope.egg-info/PKG-INFO
5
+ permiscope.egg-info/SOURCES.txt
6
+ permiscope.egg-info/dependency_links.txt
7
+ permiscope.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ permiscope
@@ -0,0 +1,20 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "permiscope"
7
+ version = "2.2.0"
8
+ description = "Dependency-free Python client for the Permiscope governance sidecar"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "MIT"
12
+ authors = [{ name = "Shubham Sharma" }]
13
+ keywords = ["agents", "governance", "policy", "audit", "sidecar"]
14
+
15
+ [project.urls]
16
+ Homepage = "https://github.com/shubhusion/Permiscope"
17
+ Documentation = "https://github.com/shubhusion/Permiscope/blob/main/python/README.md"
18
+
19
+ [tool.setuptools]
20
+ packages = ["permiscope"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+