payapi-client 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.
- payapi_client/__init__.py +9 -0
- payapi_client/__main__.py +5 -0
- payapi_client/client.py +70 -0
- payapi_client-0.1.0.dist-info/METADATA +37 -0
- payapi_client-0.1.0.dist-info/RECORD +8 -0
- payapi_client-0.1.0.dist-info/WHEEL +5 -0
- payapi_client-0.1.0.dist-info/licenses/LICENSE +21 -0
- payapi_client-0.1.0.dist-info/top_level.txt +1 -0
payapi_client/client.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""HTTP client for the PayAPI Market discovery and MCP endpoints."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from urllib.request import Request, urlopen
|
|
5
|
+
|
|
6
|
+
DEFAULT_BASE = "https://payapi.market"
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class PayAPIClient:
|
|
10
|
+
def __init__(self, base=DEFAULT_BASE, opener=None):
|
|
11
|
+
self.base = base.rstrip("/")
|
|
12
|
+
self._open = opener or urlopen
|
|
13
|
+
|
|
14
|
+
def search(self, query, verified_only=True):
|
|
15
|
+
url = self.base + "/agent/search?q=" + _query(query)
|
|
16
|
+
if verified_only:
|
|
17
|
+
url += "&verified_only=1"
|
|
18
|
+
return self._get(url)
|
|
19
|
+
|
|
20
|
+
def quote_and_pay(self, listing_id):
|
|
21
|
+
if not listing_id or not isinstance(listing_id, str):
|
|
22
|
+
raise ValueError("A listing id is required")
|
|
23
|
+
body = {
|
|
24
|
+
"jsonrpc": "2.0",
|
|
25
|
+
"id": 1,
|
|
26
|
+
"method": "tools/call",
|
|
27
|
+
"params": {"name": "quote_and_pay", "arguments": {"id": listing_id}},
|
|
28
|
+
}
|
|
29
|
+
payload = self._post(self.base + "/mcp", body)
|
|
30
|
+
if payload.get("error"):
|
|
31
|
+
raise RuntimeError(payload["error"].get("message") or "MCP request failed")
|
|
32
|
+
result = payload.get("result") or {}
|
|
33
|
+
text = ""
|
|
34
|
+
for part in result.get("content") or []:
|
|
35
|
+
if part.get("type") == "text":
|
|
36
|
+
text = part.get("text") or ""
|
|
37
|
+
break
|
|
38
|
+
if result.get("isError"):
|
|
39
|
+
raise RuntimeError(text or "The tool returned an error")
|
|
40
|
+
if not text:
|
|
41
|
+
return result
|
|
42
|
+
try:
|
|
43
|
+
return json.loads(text)
|
|
44
|
+
except json.JSONDecodeError:
|
|
45
|
+
return text
|
|
46
|
+
|
|
47
|
+
def _get(self, url):
|
|
48
|
+
request = Request(url, headers={"Accept": "application/json"})
|
|
49
|
+
with self._open(request) as response:
|
|
50
|
+
return json.loads(response.read().decode("utf-8"))
|
|
51
|
+
|
|
52
|
+
def _post(self, url, body):
|
|
53
|
+
data = json.dumps(body).encode("utf-8")
|
|
54
|
+
request = Request(
|
|
55
|
+
url,
|
|
56
|
+
data=data,
|
|
57
|
+
headers={
|
|
58
|
+
"Content-Type": "application/json",
|
|
59
|
+
"Accept": "application/json, text/event-stream",
|
|
60
|
+
},
|
|
61
|
+
method="POST",
|
|
62
|
+
)
|
|
63
|
+
with self._open(request) as response:
|
|
64
|
+
return json.loads(response.read().decode("utf-8"))
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _query(value):
|
|
68
|
+
from urllib.parse import quote
|
|
69
|
+
|
|
70
|
+
return quote(value or "", safe="")
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: payapi-client
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Client for PayAPI Market. It finds a listing and reads the provider's x402 quote. It does not hold funds.
|
|
5
|
+
Author: PayAPI Market
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://payapi.market
|
|
8
|
+
Project-URL: Repository, https://github.com/chetparker/x402-marketplace
|
|
9
|
+
Requires-Python: >=3.9
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Dynamic: license-file
|
|
13
|
+
|
|
14
|
+
# payapi-client
|
|
15
|
+
|
|
16
|
+
A Python client for PayAPI Market.
|
|
17
|
+
|
|
18
|
+
`search` reads the public discovery endpoint. `quote_and_pay` makes one unpaid request to the listing's own route and returns the provider's HTTP 402 unchanged, including payTo, amount and asset. It does not hold funds, sign or settle. The payment goes to the provider's own `payTo`.
|
|
19
|
+
|
|
20
|
+
Free to list, PayAPI takes 0% of each job.
|
|
21
|
+
|
|
22
|
+
## Install
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
pip install payapi-client
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Use
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from payapi_client import PayAPIClient
|
|
32
|
+
|
|
33
|
+
client = PayAPIClient()
|
|
34
|
+
quote = client.quote_and_pay("listing-uuid")
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Pass `opener` to point tests at a stand-in.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
payapi_client/__init__.py,sha256=SR74UFJ-yIpJlm3HBeSVOKtmxrQnqHJquF4MGHqudXA,251
|
|
2
|
+
payapi_client/__main__.py,sha256=roZqFbKaKQJniL3HOfAoVFUmmS7DGAPFkJyrVwLi6m4,153
|
|
3
|
+
payapi_client/client.py,sha256=T9uHUMHE96vu2JsCC60ZKPDtWRLz2hwyQe8PvtxMtI4,2291
|
|
4
|
+
payapi_client-0.1.0.dist-info/licenses/LICENSE,sha256=WU_AlkL0qDhrEJK357ggIsZ59YmQRLIsaYwCIx7mqJg,1068
|
|
5
|
+
payapi_client-0.1.0.dist-info/METADATA,sha256=b0001o5Ayn8wS2MLT8uvFvdhGZS0krP_X3YR_BmqmPc,1048
|
|
6
|
+
payapi_client-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
7
|
+
payapi_client-0.1.0.dist-info/top_level.txt,sha256=e2RzBjxudbtauaBJLlFOAE_K-Elf_3bqcDVoZ5QiTRg,14
|
|
8
|
+
payapi_client-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Chet Parker
|
|
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.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
payapi_client
|