postcept 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.
- postcept/__init__.py +6 -0
- postcept/_client.py +140 -0
- postcept-0.1.0.dist-info/METADATA +75 -0
- postcept-0.1.0.dist-info/RECORD +6 -0
- postcept-0.1.0.dist-info/WHEEL +4 -0
- postcept-0.1.0.dist-info/licenses/LICENSE +21 -0
postcept/__init__.py
ADDED
postcept/_client.py
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
import httpx
|
|
6
|
+
|
|
7
|
+
DEFAULT_BASE_URL = "https://api.postcept.com"
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class PostceptError(Exception):
|
|
11
|
+
"""Raised when the Postcept API returns an error response."""
|
|
12
|
+
|
|
13
|
+
def __init__(self, status_code: int, detail: str) -> None:
|
|
14
|
+
super().__init__(f"Postcept API error {status_code}: {detail}")
|
|
15
|
+
self.status_code = status_code
|
|
16
|
+
self.detail = detail
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class Postcept:
|
|
20
|
+
"""Submit Proof-of-Completion verifications for your agents' actions.
|
|
21
|
+
|
|
22
|
+
Authenticate with an organization API key (``pcpt_sk_...``):
|
|
23
|
+
|
|
24
|
+
from postcept import Postcept
|
|
25
|
+
|
|
26
|
+
pc = Postcept(api_key="pcpt_sk_...")
|
|
27
|
+
result = pc.verify_refund(
|
|
28
|
+
operation_id="refund_8F31",
|
|
29
|
+
agent_id="SupportAgent-04",
|
|
30
|
+
refund_id="re_4md82k",
|
|
31
|
+
amount_cents=12000,
|
|
32
|
+
currency="usd",
|
|
33
|
+
customer="mara.ellis@example.com",
|
|
34
|
+
idempotency_key="refund_8F31",
|
|
35
|
+
)
|
|
36
|
+
print(result["result"]) # "verified" | "incomplete" | "mismatched" | ...
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
def __init__(
|
|
40
|
+
self,
|
|
41
|
+
api_key: str,
|
|
42
|
+
*,
|
|
43
|
+
base_url: str = DEFAULT_BASE_URL,
|
|
44
|
+
timeout: float = 10.0,
|
|
45
|
+
transport: httpx.BaseTransport | None = None,
|
|
46
|
+
) -> None:
|
|
47
|
+
self._client = httpx.Client(
|
|
48
|
+
base_url=base_url.rstrip("/"),
|
|
49
|
+
headers={"Authorization": f"Bearer {api_key}"},
|
|
50
|
+
timeout=timeout,
|
|
51
|
+
transport=transport,
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
# --- verifications ---
|
|
55
|
+
|
|
56
|
+
def verify_refund(
|
|
57
|
+
self,
|
|
58
|
+
*,
|
|
59
|
+
operation_id: str,
|
|
60
|
+
agent_id: str,
|
|
61
|
+
customer: str,
|
|
62
|
+
amount_cents: int,
|
|
63
|
+
currency: str = "usd",
|
|
64
|
+
refund_id: str | None = None,
|
|
65
|
+
charge_id: str | None = None,
|
|
66
|
+
idempotency_key: str | None = None,
|
|
67
|
+
) -> dict[str, Any]:
|
|
68
|
+
"""Verify that a refund actually completed in the system of record."""
|
|
69
|
+
claim: dict[str, Any] = {
|
|
70
|
+
"customer": customer,
|
|
71
|
+
"amount_cents": amount_cents,
|
|
72
|
+
"currency": currency,
|
|
73
|
+
}
|
|
74
|
+
if refund_id is not None:
|
|
75
|
+
claim["refund_id"] = refund_id
|
|
76
|
+
if charge_id is not None:
|
|
77
|
+
claim["charge_id"] = charge_id
|
|
78
|
+
return self._create_verification(operation_id, agent_id, claim, idempotency_key)
|
|
79
|
+
|
|
80
|
+
def verify_cancellation(
|
|
81
|
+
self,
|
|
82
|
+
*,
|
|
83
|
+
operation_id: str,
|
|
84
|
+
agent_id: str,
|
|
85
|
+
subscription_id: str,
|
|
86
|
+
customer: str,
|
|
87
|
+
idempotency_key: str | None = None,
|
|
88
|
+
) -> dict[str, Any]:
|
|
89
|
+
"""Verify that a subscription was actually cancelled in the system of record."""
|
|
90
|
+
claim = {"subscription_id": subscription_id, "customer": customer}
|
|
91
|
+
return self._create_verification(operation_id, agent_id, claim, idempotency_key)
|
|
92
|
+
|
|
93
|
+
def get_verification(self, verification_id: str) -> dict[str, Any]:
|
|
94
|
+
return self._request("GET", f"/v1/verifications/{verification_id}")
|
|
95
|
+
|
|
96
|
+
def verified_completion_rate(self) -> dict[str, Any]:
|
|
97
|
+
"""The org's Verified Completion Rate (verified / claimed)."""
|
|
98
|
+
return self._request("GET", "/v1/metrics/vcr")
|
|
99
|
+
|
|
100
|
+
# --- internals ---
|
|
101
|
+
|
|
102
|
+
def _create_verification(
|
|
103
|
+
self,
|
|
104
|
+
operation_id: str,
|
|
105
|
+
agent_id: str,
|
|
106
|
+
claim: dict[str, Any],
|
|
107
|
+
idempotency_key: str | None,
|
|
108
|
+
) -> dict[str, Any]:
|
|
109
|
+
headers = {"Idempotency-Key": idempotency_key} if idempotency_key else None
|
|
110
|
+
body = {"operation_id": operation_id, "agent_id": agent_id, "claim": claim}
|
|
111
|
+
return self._request("POST", "/v1/verifications", json=body, headers=headers)
|
|
112
|
+
|
|
113
|
+
def _request(
|
|
114
|
+
self,
|
|
115
|
+
method: str,
|
|
116
|
+
path: str,
|
|
117
|
+
*,
|
|
118
|
+
json: dict[str, Any] | None = None,
|
|
119
|
+
headers: dict[str, str] | None = None,
|
|
120
|
+
) -> dict[str, Any]:
|
|
121
|
+
response = self._client.request(method, path, json=json, headers=headers)
|
|
122
|
+
if response.is_error:
|
|
123
|
+
raise PostceptError(response.status_code, _detail(response))
|
|
124
|
+
return response.json()
|
|
125
|
+
|
|
126
|
+
def close(self) -> None:
|
|
127
|
+
self._client.close()
|
|
128
|
+
|
|
129
|
+
def __enter__(self) -> Postcept:
|
|
130
|
+
return self
|
|
131
|
+
|
|
132
|
+
def __exit__(self, *_exc: object) -> None:
|
|
133
|
+
self.close()
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def _detail(response: httpx.Response) -> str:
|
|
137
|
+
try:
|
|
138
|
+
return response.json().get("detail", response.text)
|
|
139
|
+
except Exception:
|
|
140
|
+
return response.text
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: postcept
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python SDK for Postcept: Proof-of-Completion for AI agents.
|
|
5
|
+
Project-URL: Homepage, https://postcept.com
|
|
6
|
+
Project-URL: Documentation, https://postcept.com/docs
|
|
7
|
+
Project-URL: Repository, https://github.com/Postcept/postcept-python
|
|
8
|
+
Project-URL: Issues, https://github.com/Postcept/postcept-python/issues
|
|
9
|
+
Author: Postcept
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: ai-agents,postcept,proof-of-completion,receipt,stripe,verification
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
17
|
+
Classifier: Typing :: Typed
|
|
18
|
+
Requires-Python: >=3.9
|
|
19
|
+
Requires-Dist: httpx>=0.27
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
22
|
+
# Postcept Python SDK
|
|
23
|
+
|
|
24
|
+
Submit Proof-of-Completion verifications for your AI agents' high-risk actions.
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install postcept
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
from postcept import Postcept
|
|
34
|
+
|
|
35
|
+
pc = Postcept(api_key="pcpt_sk_...") # create a key in the dashboard
|
|
36
|
+
|
|
37
|
+
# After your agent issues a refund, prove it actually completed:
|
|
38
|
+
result = pc.verify_refund(
|
|
39
|
+
operation_id="refund_8F31", # stable across retries
|
|
40
|
+
agent_id="SupportAgent-04",
|
|
41
|
+
refund_id="re_4md82k",
|
|
42
|
+
amount_cents=12000,
|
|
43
|
+
currency="usd",
|
|
44
|
+
customer="mara.ellis@example.com",
|
|
45
|
+
idempotency_key="refund_8F31", # safe to retry
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
print(result["result"]) # "verified" | "incomplete" | "duplicated" | "mismatched" | "policy_failed"
|
|
49
|
+
print(result["receipt"]["id"]) # signed completion receipt
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Cancellations work the same way:
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
pc.verify_cancellation(
|
|
56
|
+
operation_id="cancel_2240",
|
|
57
|
+
agent_id="SupportAgent-04",
|
|
58
|
+
subscription_id="sub_9Kd21",
|
|
59
|
+
customer="mara.ellis@example.com",
|
|
60
|
+
)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Read your Verified Completion Rate:
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
pc.verified_completion_rate() # {"claimed": 1240, "verified": 1167, "verified_completion_rate": 0.9411, ...}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Notes
|
|
70
|
+
|
|
71
|
+
- **Auth**: pass an organization API key (`pcpt_sk_...`). All data is scoped to that org.
|
|
72
|
+
- **Idempotency**: pass `idempotency_key` so retried submissions return the original verification instead of creating a duplicate.
|
|
73
|
+
- **Errors**: non-2xx responses raise `PostceptError` (`.status_code`, `.detail`).
|
|
74
|
+
- **Base URL**: defaults to `https://api.postcept.com`. Override with `Postcept(api_key=..., base_url=...)` for staging.
|
|
75
|
+
- Use as a context manager (`with Postcept(...) as pc:`) to close the HTTP client.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
postcept/__init__.py,sha256=V8IZ1og2DPwlOqbEDLXhicSwDiVENz8-_CzhLc4tYiU,221
|
|
2
|
+
postcept/_client.py,sha256=BmWY5S4Dm6Cz3PRcB32Mzwm4qyX65pkKwHNdf3wwsF8,4368
|
|
3
|
+
postcept-0.1.0.dist-info/METADATA,sha256=vmIbPyLyGjpW-ycEW1DEUJhBpI1QWCZzDpF2v3SpvvY,2520
|
|
4
|
+
postcept-0.1.0.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
|
|
5
|
+
postcept-0.1.0.dist-info/licenses/LICENSE,sha256=u_Poz2GlsmRFjANw0D4d45KYNbZBUvKOR-FLxBYckfc,1071
|
|
6
|
+
postcept-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Postcept, Inc.
|
|
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.
|