llpro 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.
llpro-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,40 @@
1
+ Metadata-Version: 2.1
2
+ Name: llpro
3
+ Version: 0.1.0
4
+ Summary: Tiny stdlib client for LLPRO's agent tools: cited public facts, signed checks of agent work, public agent records, free agent key.
5
+ Keywords: agents,ai-agents,mcp,verification,llpro,countersign
6
+ Author-email: LLPRO LLC <support@llpro.ai>
7
+ Requires-Python: >=3.9
8
+ Description-Content-Type: text/markdown
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Operating System :: OS Independent
11
+ Project-URL: Homepage, https://llpro.ai/connect?via=pypi
12
+
13
+ # llpro (Python)
14
+
15
+ Tiny client (standard library only) for LLPRO's agent tools. By LLPRO LLC, https://llpro.ai. Free daily allowance, no sign-up.
16
+
17
+ ## Install
18
+
19
+ ```bash
20
+ pip install llpro
21
+ ```
22
+
23
+ ## Use
24
+
25
+ ```python
26
+ import llpro
27
+ k = llpro.agent_key("my-agent") # free, no sign-up, shown once: named agent, double daily allowance, public Agent Record
28
+ print(k["badge"]["markdown"]) # paste into your README: links to your public record
29
+ c = llpro.Client(agent_key=k["key"], agent_id=k["agent_id"])
30
+ c.ground_truth("weather", place="Lafayette, LA") # cited, time-stamped public fact
31
+ s = c.countersign("12 * 4 = 48", kind="calculation") # independent signed check
32
+ print(s["share_url"]) # public page anyone can open to verify the stamp
33
+ c.agent_record("io.github.example/server") # public record of an agent or MCP server
34
+ ```
35
+
36
+ Past the free allowance a call raises `llpro.PaymentRequired`; its message says how to get a prepaid credit key (pass `api_key=` or set `LLPRO_API_KEY`).
37
+ Stamps are logged publicly: never send private text. Tests: `python -m unittest discover tests`.
38
+
39
+ More: https://llpro.ai/connect?via=pypi
40
+
llpro-0.1.0/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # llpro (Python)
2
+
3
+ Tiny client (standard library only) for LLPRO's agent tools. By LLPRO LLC, https://llpro.ai. Free daily allowance, no sign-up.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pip install llpro
9
+ ```
10
+
11
+ ## Use
12
+
13
+ ```python
14
+ import llpro
15
+ k = llpro.agent_key("my-agent") # free, no sign-up, shown once: named agent, double daily allowance, public Agent Record
16
+ print(k["badge"]["markdown"]) # paste into your README: links to your public record
17
+ c = llpro.Client(agent_key=k["key"], agent_id=k["agent_id"])
18
+ c.ground_truth("weather", place="Lafayette, LA") # cited, time-stamped public fact
19
+ s = c.countersign("12 * 4 = 48", kind="calculation") # independent signed check
20
+ print(s["share_url"]) # public page anyone can open to verify the stamp
21
+ c.agent_record("io.github.example/server") # public record of an agent or MCP server
22
+ ```
23
+
24
+ Past the free allowance a call raises `llpro.PaymentRequired`; its message says how to get a prepaid credit key (pass `api_key=` or set `LLPRO_API_KEY`).
25
+ Stamps are logged publicly: never send private text. Tests: `python -m unittest discover tests`.
26
+
27
+ More: https://llpro.ai/connect?via=pypi
llpro-0.1.0/llpro.py ADDED
@@ -0,0 +1,140 @@
1
+ """Small stdlib client for LLPRO's agent tools: Ground Truth (cited public facts), Countersign (signed checks of agent work),
2
+ Agent Record (public records of agents and MCP servers) and the free agent key.
3
+
4
+ No sign-up is needed for the free daily allowance. Get a free agent key with agent_key(): send it on later calls (agent_key=...) and you
5
+ count as a named agent with double the free daily limit and a public Agent Record. Past the free limit, pass a prepaid credit key
6
+ (llk_..., api_key=... or LLPRO_API_KEY): the call is then taken from the key's balance. The only network addresses used are the ones below.
7
+ """
8
+ import http.client
9
+ import json
10
+ import os
11
+ import urllib.error
12
+ import urllib.request
13
+
14
+ __version__ = "0.1.0"
15
+ VIA = "python"
16
+ UA = "llpro-python/" + __version__
17
+ ENDPOINTS = {
18
+ "ground_truth": "https://gt.llpro.ai/v1/ask",
19
+ "countersign": "https://countersign.llpro.ai/v1/stamp",
20
+ "agent_record": "https://agentrecord.llpro.ai/v1/lookup",
21
+ "agent_key": "https://llpro.ai/agents/key",
22
+ }
23
+
24
+
25
+ class LLPROError(Exception):
26
+ """A call that did not return an answer. status is the HTTP status (0 = no response)."""
27
+
28
+ def __init__(self, message, status=0, body=None):
29
+ super().__init__(message)
30
+ self.status = status
31
+ self.body = body if isinstance(body, dict) else {}
32
+
33
+
34
+ class PaymentRequired(LLPROError):
35
+ """The free daily allowance is used up (HTTP 402). The message says how to pay."""
36
+
37
+
38
+ def _tagged(url):
39
+ if not isinstance(url, str) or not url.startswith("https://"):
40
+ return ""
41
+ if "via=" in url:
42
+ return url
43
+ return url + ("&" if "?" in url else "?") + "via=" + VIA
44
+
45
+
46
+ def _payment_message(body):
47
+ first = str(body.get("error") or "The free daily allowance for this tool is used up.").strip()
48
+ buy = _tagged(body.get("get_a_key") or (body.get("credit") or {}).get("buy"))
49
+ how = (" Get a prepaid credit key (card, no wallet needed): %s, then pass it as api_key or set LLPRO_API_KEY."
50
+ % buy) if buy else " Pass a prepaid credit key as api_key or set LLPRO_API_KEY."
51
+ return first + how + " Pay-per-call with x402 (USDC on Base) also works on this endpoint."
52
+
53
+
54
+ def call(tool, payload, api_key=None, agent_id=None, agent_key=None, timeout=60.0):
55
+ """POST payload (a dict) to one tool and return the JSON answer as a dict. Raises LLPROError / PaymentRequired.
56
+ agent_key: the free key from agent_key() (header X-Agent-Key). api_key: prepaid credit key (else LLPRO_API_KEY)."""
57
+ if tool not in ENDPOINTS:
58
+ raise ValueError("unknown tool %r (use one of %s)" % (tool, ", ".join(sorted(ENDPOINTS))))
59
+ if not isinstance(payload, dict):
60
+ raise ValueError("payload must be a dict")
61
+ if tool != "agent_key" and not payload:
62
+ raise ValueError("payload must be a non-empty dict")
63
+ key = api_key if api_key is not None else os.environ.get("LLPRO_API_KEY", "")
64
+ headers = {"Content-Type": "application/json", "Accept": "application/json", "User-Agent": UA, "X-LLPRO-Via": VIA}
65
+ if key and tool != "agent_key":
66
+ headers["Authorization"] = "Bearer " + key.strip()
67
+ if agent_key and tool != "agent_key":
68
+ headers["X-Agent-Key"] = str(agent_key).strip()
69
+ if agent_id:
70
+ headers["X-Agent-Id"] = str(agent_id)
71
+ req = urllib.request.Request(ENDPOINTS[tool], data=json.dumps(payload).encode("utf-8"), headers=headers, method="POST")
72
+ try:
73
+ with urllib.request.urlopen(req, timeout=timeout) as r:
74
+ raw = r.read()
75
+ except urllib.error.HTTPError as e:
76
+ try:
77
+ body = json.loads(e.read() or b"{}")
78
+ except ValueError:
79
+ body = {}
80
+ if not isinstance(body, dict):
81
+ body = {}
82
+ if e.code == 402:
83
+ raise PaymentRequired(_payment_message(body), 402, body)
84
+ err = body.get("error")
85
+ msg = str((err.get("message") if isinstance(err, dict) else err) or body.get("message") or e.reason or "request failed")
86
+ if e.code == 400:
87
+ msg = "Bad input, nothing was charged: " + msg
88
+ elif e.code == 429:
89
+ msg = "Daily ceiling reached, try again later: " + msg
90
+ raise LLPROError(msg, e.code, body)
91
+ except (urllib.error.URLError, OSError, http.client.HTTPException) as e:
92
+ raise LLPROError("Could not reach %s: %s" % (ENDPOINTS[tool], getattr(e, "reason", e)), 0)
93
+ try:
94
+ out = json.loads(raw or b"{}")
95
+ except ValueError:
96
+ raise LLPROError("The answer was not JSON", 200)
97
+ return out if isinstance(out, dict) else {"answer": out}
98
+
99
+
100
+ def agent_key(name=None, timeout=30.0):
101
+ """Get a free agent key (no sign-up, no email). Returns {agent_id, key, record, badge, ...}. The key is shown once: keep it.
102
+ Send it on later calls as agent_key=..., and paste result['badge']['markdown'] into your README to show your public Agent Record."""
103
+ return call("agent_key", {"name": name} if name else {}, timeout=timeout)
104
+
105
+
106
+ class Client:
107
+ """The whole API in one object. LLPRO LLC, https://llpro.ai.
108
+
109
+ import llpro
110
+ c = llpro.Client() # no sign-up: free daily allowance
111
+ k = llpro.agent_key("my-agent") # optional, free: named agent, double allowance, public record + badge
112
+ c = llpro.Client(agent_key=k["key"], agent_id=k["agent_id"])
113
+ c.ground_truth("weather", place="Lafayette, LA")
114
+ s = c.countersign("12 * 4 = 48", producer_agent_id="my-agent") # s["share_url"] opens a public page anyone can check
115
+ c.agent_record("io.github.example/server")
116
+ """
117
+
118
+ def __init__(self, api_key=None, agent_key=None, agent_id=None, timeout=60.0):
119
+ self.api_key, self.agent_key, self.agent_id, self.timeout = api_key, agent_key, agent_id, timeout
120
+
121
+ def _c(self, tool, payload):
122
+ return call(tool, payload, api_key=self.api_key, agent_id=self.agent_id, agent_key=self.agent_key, timeout=self.timeout)
123
+
124
+ def ground_truth(self, topic, place=None, lat=None, lon=None, max_age_minutes=None):
125
+ p = {"topic": topic, "place": place, "lat": lat, "lon": lon, "max_age_minutes": max_age_minutes}
126
+ return self._c("ground_truth", {k: v for k, v in p.items() if v is not None})
127
+
128
+ def countersign(self, output, kind=None, producer_agent_id=None, producer_model=None, claims=None):
129
+ producer = {"agent_id": producer_agent_id or self.agent_id or "llpro-python-client"}
130
+ if producer_model:
131
+ producer["model"] = producer_model
132
+ p = {"output": output, "producer": producer}
133
+ if kind:
134
+ p["kind"] = kind
135
+ if claims:
136
+ p["claims"] = claims
137
+ return self._c("countersign", p)
138
+
139
+ def agent_record(self, target):
140
+ return self._c("agent_record", {"target": target})
@@ -0,0 +1,17 @@
1
+ [build-system]
2
+ requires = ["flit_core==3.9.0"]
3
+ build-backend = "flit_core.buildapi"
4
+
5
+ [project]
6
+ name = "llpro"
7
+ version = "0.1.0"
8
+ description = "Tiny stdlib client for LLPRO's agent tools: cited public facts, signed checks of agent work, public agent records, free agent key."
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ dependencies = []
12
+ authors = [{ name = "LLPRO LLC", email = "support@llpro.ai" }]
13
+ keywords = ["agents", "ai-agents", "mcp", "verification", "llpro", "countersign"]
14
+ classifiers = ["Programming Language :: Python :: 3", "Operating System :: OS Independent"]
15
+
16
+ [project.urls]
17
+ Homepage = "https://llpro.ai/connect?via=pypi"