plures 1.0.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.
- plures-1.0.0/.gitignore +6 -0
- plures-1.0.0/LICENSE +21 -0
- plures-1.0.0/PKG-INFO +75 -0
- plures-1.0.0/README.md +57 -0
- plures-1.0.0/pyproject.toml +27 -0
- plures-1.0.0/src/plures/__init__.py +110 -0
- plures-1.0.0/src/plures/py.typed +0 -0
plures-1.0.0/.gitignore
ADDED
plures-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Plures Labs LLC
|
|
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.
|
plures-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: plures
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Human judgment as an API for AI agents. Send a decision to ID verified people and get their consensus back.
|
|
5
|
+
Project-URL: Homepage, https://plures.si/developers
|
|
6
|
+
Project-URL: Documentation, https://plures.si/docs
|
|
7
|
+
Project-URL: Source, https://github.com/plureslabs/plures
|
|
8
|
+
Author-email: Plures Labs LLC <hello@plures.si>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: agents,ai-agents,hitl,human-approval,human-in-the-loop,human-review,llm,plures
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
15
|
+
Classifier: Typing :: Typed
|
|
16
|
+
Requires-Python: >=3.8
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# plures
|
|
20
|
+
|
|
21
|
+
The official Python client for [Plures](https://plures.si): human judgment as an API for AI agents. Send a decision to ID verified people and get their consensus back before your agent acts. A human in the loop step you can call like any other API.
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install plures
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Python 3.8+, standard library only.
|
|
28
|
+
|
|
29
|
+
## Use it
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
from plures import Plures
|
|
33
|
+
|
|
34
|
+
plures = Plures() # reads PLURES_API_KEY, or Plures("pk_test_...")
|
|
35
|
+
|
|
36
|
+
task = plures.verify(
|
|
37
|
+
"Does the invoice match the order?",
|
|
38
|
+
["Matches", "Does not match"],
|
|
39
|
+
context="Order: 48 chairs, $4,218. Invoice: 48 chairs plus $180 freight, $4,398.",
|
|
40
|
+
verifiers=3,
|
|
41
|
+
)
|
|
42
|
+
result = task["result"]
|
|
43
|
+
if result and result["agreement"] == 1:
|
|
44
|
+
print("Act on:", result["answer"])
|
|
45
|
+
else:
|
|
46
|
+
print("Not unanimous: send to the team")
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Get a free test key at [plures.si](https://plures.si/?for=developers#join). Test keys complete at once with the first option (or `metadata["test_answer"]`) and never reach real people.
|
|
50
|
+
|
|
51
|
+
## Production: webhooks
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
plures.create_task(
|
|
55
|
+
"Should this customer get a refund?", ["Approve", "Decline"],
|
|
56
|
+
context=ticket_text, webhook_url="https://your.app/plures",
|
|
57
|
+
metadata={"order_id": order_id}, idempotency_key="refund-%s" % order_id,
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
# In your webhook handler (Flask shown), pass the raw body exactly as received
|
|
61
|
+
from plures import verify_webhook
|
|
62
|
+
event = verify_webhook(request.get_data(), request.headers.get("Plures-Signature"), WEBHOOK_SECRET)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## API
|
|
66
|
+
|
|
67
|
+
- `create_task(question, options, idempotency_key=None, **fields)`: fields are `context`, `image_url`, `instructions`, `verifiers` (1, 3, 5, 7 or 9), `max_verifiers`, `presence_check` (default True), `webhook_url`, `metadata`, `expires_in`
|
|
68
|
+
- `get_task(id)`, `list_tasks(status=None, limit=None, starting_after=None)`, `cancel_task(id)`
|
|
69
|
+
- `wait_for(id, timeout=600, interval=3)`: poll until settled
|
|
70
|
+
- `verify(question, options, timeout=600, **fields)`: create and wait
|
|
71
|
+
- `verify_webhook(raw_body, signature_header, secret)`: check a webhook and return the event
|
|
72
|
+
|
|
73
|
+
Errors raise `PluresError` with `.status` and `.type`. Server errors are retried twice.
|
|
74
|
+
|
|
75
|
+
Examples for LangGraph and the OpenAI Agents SDK: [github.com/plureslabs/plures](https://github.com/plureslabs/plures/tree/main/examples). Full reference: [plures.si/docs](https://plures.si/docs).
|
plures-1.0.0/README.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# plures
|
|
2
|
+
|
|
3
|
+
The official Python client for [Plures](https://plures.si): human judgment as an API for AI agents. Send a decision to ID verified people and get their consensus back before your agent acts. A human in the loop step you can call like any other API.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
pip install plures
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Python 3.8+, standard library only.
|
|
10
|
+
|
|
11
|
+
## Use it
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from plures import Plures
|
|
15
|
+
|
|
16
|
+
plures = Plures() # reads PLURES_API_KEY, or Plures("pk_test_...")
|
|
17
|
+
|
|
18
|
+
task = plures.verify(
|
|
19
|
+
"Does the invoice match the order?",
|
|
20
|
+
["Matches", "Does not match"],
|
|
21
|
+
context="Order: 48 chairs, $4,218. Invoice: 48 chairs plus $180 freight, $4,398.",
|
|
22
|
+
verifiers=3,
|
|
23
|
+
)
|
|
24
|
+
result = task["result"]
|
|
25
|
+
if result and result["agreement"] == 1:
|
|
26
|
+
print("Act on:", result["answer"])
|
|
27
|
+
else:
|
|
28
|
+
print("Not unanimous: send to the team")
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Get a free test key at [plures.si](https://plures.si/?for=developers#join). Test keys complete at once with the first option (or `metadata["test_answer"]`) and never reach real people.
|
|
32
|
+
|
|
33
|
+
## Production: webhooks
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
plures.create_task(
|
|
37
|
+
"Should this customer get a refund?", ["Approve", "Decline"],
|
|
38
|
+
context=ticket_text, webhook_url="https://your.app/plures",
|
|
39
|
+
metadata={"order_id": order_id}, idempotency_key="refund-%s" % order_id,
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
# In your webhook handler (Flask shown), pass the raw body exactly as received
|
|
43
|
+
from plures import verify_webhook
|
|
44
|
+
event = verify_webhook(request.get_data(), request.headers.get("Plures-Signature"), WEBHOOK_SECRET)
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## API
|
|
48
|
+
|
|
49
|
+
- `create_task(question, options, idempotency_key=None, **fields)`: fields are `context`, `image_url`, `instructions`, `verifiers` (1, 3, 5, 7 or 9), `max_verifiers`, `presence_check` (default True), `webhook_url`, `metadata`, `expires_in`
|
|
50
|
+
- `get_task(id)`, `list_tasks(status=None, limit=None, starting_after=None)`, `cancel_task(id)`
|
|
51
|
+
- `wait_for(id, timeout=600, interval=3)`: poll until settled
|
|
52
|
+
- `verify(question, options, timeout=600, **fields)`: create and wait
|
|
53
|
+
- `verify_webhook(raw_body, signature_header, secret)`: check a webhook and return the event
|
|
54
|
+
|
|
55
|
+
Errors raise `PluresError` with `.status` and `.type`. Server errors are retried twice.
|
|
56
|
+
|
|
57
|
+
Examples for LangGraph and the OpenAI Agents SDK: [github.com/plureslabs/plures](https://github.com/plureslabs/plures/tree/main/examples). Full reference: [plures.si/docs](https://plures.si/docs).
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "plures"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "Human judgment as an API for AI agents. Send a decision to ID verified people and get their consensus back."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
requires-python = ">=3.8"
|
|
12
|
+
authors = [{ name = "Plures Labs LLC", email = "hello@plures.si" }]
|
|
13
|
+
keywords = ["human-in-the-loop", "hitl", "ai-agents", "human-review", "human-approval", "llm", "agents", "plures"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
18
|
+
"Typing :: Typed",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[project.urls]
|
|
22
|
+
Homepage = "https://plures.si/developers"
|
|
23
|
+
Documentation = "https://plures.si/docs"
|
|
24
|
+
Source = "https://github.com/plureslabs/plures"
|
|
25
|
+
|
|
26
|
+
[tool.hatch.build.targets.wheel]
|
|
27
|
+
packages = ["src/plures"]
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"""Plures: human judgment as an API for AI agents.
|
|
2
|
+
|
|
3
|
+
Send a decision to ID verified people and get their consensus back.
|
|
4
|
+
Python 3.8+, standard library only. Docs: https://plures.si/docs
|
|
5
|
+
"""
|
|
6
|
+
import hashlib
|
|
7
|
+
import hmac
|
|
8
|
+
import json
|
|
9
|
+
import os
|
|
10
|
+
import time
|
|
11
|
+
import urllib.error
|
|
12
|
+
import urllib.parse
|
|
13
|
+
import urllib.request
|
|
14
|
+
|
|
15
|
+
__version__ = "1.0.0"
|
|
16
|
+
__all__ = ["Plures", "PluresError", "verify_webhook", "__version__"]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class PluresError(Exception):
|
|
20
|
+
def __init__(self, message, status, type_):
|
|
21
|
+
super().__init__(message)
|
|
22
|
+
self.status = status
|
|
23
|
+
self.type = type_
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class Plures:
|
|
27
|
+
def __init__(self, api_key=None, base_url=None, timeout=30):
|
|
28
|
+
api_key = api_key or os.environ.get("PLURES_API_KEY")
|
|
29
|
+
if not api_key:
|
|
30
|
+
raise ValueError("Pass your Plures API key, or set PLURES_API_KEY. Get a free test key at https://plures.si/?for=developers#join")
|
|
31
|
+
base_url = base_url or os.environ.get("PLURES_BASE_URL") or "https://plures.si"
|
|
32
|
+
self.api_key = api_key
|
|
33
|
+
self.base = base_url.rstrip("/")
|
|
34
|
+
self.timeout = timeout
|
|
35
|
+
|
|
36
|
+
def _req(self, method, path, body=None, headers=None):
|
|
37
|
+
data = json.dumps(body).encode() if body is not None else None
|
|
38
|
+
h = {"authorization": "Bearer " + self.api_key, "user-agent": "plures-python/" + __version__}
|
|
39
|
+
if data is not None:
|
|
40
|
+
h["content-type"] = "application/json"
|
|
41
|
+
h.update(headers or {})
|
|
42
|
+
for attempt in range(3):
|
|
43
|
+
req = urllib.request.Request(self.base + path, data=data, method=method, headers=h)
|
|
44
|
+
try:
|
|
45
|
+
with urllib.request.urlopen(req, timeout=self.timeout) as r:
|
|
46
|
+
return json.loads(r.read() or b"{}")
|
|
47
|
+
except urllib.error.HTTPError as e:
|
|
48
|
+
if e.code >= 500 and attempt < 2:
|
|
49
|
+
time.sleep(0.5 * 2 ** attempt)
|
|
50
|
+
continue
|
|
51
|
+
try:
|
|
52
|
+
err = json.loads(e.read()).get("error", {})
|
|
53
|
+
except Exception:
|
|
54
|
+
err = {}
|
|
55
|
+
raise PluresError(err.get("message", "HTTP %d" % e.code), e.code, err.get("type", "api_error"))
|
|
56
|
+
|
|
57
|
+
def create_task(self, question, options, idempotency_key=None, **fields):
|
|
58
|
+
"""Sends a question to verified people.
|
|
59
|
+
|
|
60
|
+
fields: context, image_url, instructions, verifiers (odd, 1 to 9), max_verifiers,
|
|
61
|
+
presence_check (default True), webhook_url, metadata, expires_in (seconds).
|
|
62
|
+
"""
|
|
63
|
+
body = dict(fields, question=question, options=options)
|
|
64
|
+
headers = {"idempotency-key": idempotency_key} if idempotency_key else None
|
|
65
|
+
return self._req("POST", "/api/v1/tasks", body, headers)
|
|
66
|
+
|
|
67
|
+
def get_task(self, task_id):
|
|
68
|
+
return self._req("GET", "/api/v1/tasks/" + urllib.parse.quote(task_id))
|
|
69
|
+
|
|
70
|
+
def list_tasks(self, status=None, limit=None, starting_after=None):
|
|
71
|
+
q = {k: v for k, v in {"status": status, "limit": limit, "starting_after": starting_after}.items() if v is not None}
|
|
72
|
+
return self._req("GET", "/api/v1/tasks" + ("?" + urllib.parse.urlencode(q) if q else ""))
|
|
73
|
+
|
|
74
|
+
def cancel_task(self, task_id):
|
|
75
|
+
return self._req("POST", "/api/v1/tasks/" + urllib.parse.quote(task_id) + "/cancel")
|
|
76
|
+
|
|
77
|
+
def wait_for(self, task_id, timeout=600, interval=3):
|
|
78
|
+
"""Polls until the task is settled. Prefer webhooks in production."""
|
|
79
|
+
end = time.time() + timeout
|
|
80
|
+
while True:
|
|
81
|
+
t = self.get_task(task_id)
|
|
82
|
+
if t["status"] != "pending" or time.time() > end:
|
|
83
|
+
return t
|
|
84
|
+
time.sleep(interval)
|
|
85
|
+
|
|
86
|
+
def verify(self, question, options, timeout=600, idempotency_key=None, **fields):
|
|
87
|
+
"""Creates a task and waits for people to answer it."""
|
|
88
|
+
t = self.create_task(question, options, idempotency_key=idempotency_key, **fields)
|
|
89
|
+
return t if t["status"] != "pending" else self.wait_for(t["id"], timeout=timeout)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def verify_webhook(raw_body, signature_header, secret, tolerance=300):
|
|
93
|
+
"""Checks the Plures-Signature header and returns the parsed event.
|
|
94
|
+
|
|
95
|
+
raw_body must be the exact bytes or string received. Raises ValueError if invalid.
|
|
96
|
+
"""
|
|
97
|
+
if isinstance(raw_body, bytes):
|
|
98
|
+
raw_body = raw_body.decode()
|
|
99
|
+
parts = dict(p.split("=", 1) for p in (signature_header or "").split(",") if "=" in p)
|
|
100
|
+
try:
|
|
101
|
+
t = int(parts["t"])
|
|
102
|
+
v1 = parts["v1"]
|
|
103
|
+
except (KeyError, ValueError):
|
|
104
|
+
raise ValueError("Missing Plures-Signature header")
|
|
105
|
+
if abs(time.time() - t) > tolerance:
|
|
106
|
+
raise ValueError("Webhook timestamp is too old")
|
|
107
|
+
expected = hmac.new(secret.encode(), ("%d.%s" % (t, raw_body)).encode(), hashlib.sha256).hexdigest()
|
|
108
|
+
if not hmac.compare_digest(expected, v1):
|
|
109
|
+
raise ValueError("Webhook signature does not match")
|
|
110
|
+
return json.loads(raw_body)
|
|
File without changes
|