trustos 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.
- trustos/__init__.py +6 -0
- trustos/client.py +130 -0
- trustos-0.1.0.dist-info/METADATA +257 -0
- trustos-0.1.0.dist-info/RECORD +7 -0
- trustos-0.1.0.dist-info/WHEEL +5 -0
- trustos-0.1.0.dist-info/licenses/LICENSE +21 -0
- trustos-0.1.0.dist-info/top_level.txt +1 -0
trustos/__init__.py
ADDED
trustos/client.py
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"""Trust OS Python SDK — Decision Verification API client."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
import requests
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
DEFAULT_BASE_URL = "https://trustos-core-gateway-v2-7jm9owrs.an.gateway.dev"
|
|
12
|
+
_VERIFY_PATH = "/v1/decision/verify"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class TrustOSError(Exception):
|
|
16
|
+
"""Raised when the Trust OS API returns a non-2xx response or an
|
|
17
|
+
unexpected payload.
|
|
18
|
+
|
|
19
|
+
Attributes:
|
|
20
|
+
status_code: HTTP status code, or None for network/parse errors.
|
|
21
|
+
response_body: Raw response text, or None when unavailable.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
def __init__(
|
|
25
|
+
self,
|
|
26
|
+
message: str,
|
|
27
|
+
*,
|
|
28
|
+
status_code: int | None = None,
|
|
29
|
+
response_body: str | None = None,
|
|
30
|
+
) -> None:
|
|
31
|
+
super().__init__(message)
|
|
32
|
+
self.status_code = status_code
|
|
33
|
+
self.response_body = response_body
|
|
34
|
+
|
|
35
|
+
def __repr__(self) -> str:
|
|
36
|
+
return (
|
|
37
|
+
f"TrustOSError(status_code={self.status_code!r}, "
|
|
38
|
+
f"message={str(self)!r})"
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class TrustOSClient:
|
|
43
|
+
"""Client for the Trust OS Decision Verification API.
|
|
44
|
+
|
|
45
|
+
Args:
|
|
46
|
+
api_key: API key for authentication. If *None*, the value of the
|
|
47
|
+
``TRUSTOS_API_KEY`` environment variable is used instead.
|
|
48
|
+
base_url: Override the API base URL. Trailing slashes are removed
|
|
49
|
+
automatically. Defaults to the production gateway.
|
|
50
|
+
timeout: Request timeout in seconds. Defaults to 10.0.
|
|
51
|
+
|
|
52
|
+
Raises:
|
|
53
|
+
ValueError: If no API key is provided and ``TRUSTOS_API_KEY`` is
|
|
54
|
+
not set in the environment.
|
|
55
|
+
|
|
56
|
+
Example::
|
|
57
|
+
|
|
58
|
+
from trustos import TrustOSClient
|
|
59
|
+
|
|
60
|
+
client = TrustOSClient(api_key="YOUR_API_KEY")
|
|
61
|
+
result = client.verify_decision({"action": "stablecoin_transfer"})
|
|
62
|
+
"""
|
|
63
|
+
|
|
64
|
+
def __init__(
|
|
65
|
+
self,
|
|
66
|
+
api_key: str | None = None,
|
|
67
|
+
base_url: str | None = None,
|
|
68
|
+
timeout: float = 10.0,
|
|
69
|
+
) -> None:
|
|
70
|
+
resolved_key = api_key or os.environ.get("TRUSTOS_API_KEY")
|
|
71
|
+
if not resolved_key:
|
|
72
|
+
raise ValueError(
|
|
73
|
+
"No API key provided. Pass api_key= to TrustOSClient() "
|
|
74
|
+
"or set the TRUSTOS_API_KEY environment variable."
|
|
75
|
+
)
|
|
76
|
+
self._api_key = resolved_key
|
|
77
|
+
self._base_url = (base_url or DEFAULT_BASE_URL).rstrip("/")
|
|
78
|
+
self._timeout = timeout
|
|
79
|
+
self._session = requests.Session()
|
|
80
|
+
self._session.headers.update({
|
|
81
|
+
"Content-Type": "application/json",
|
|
82
|
+
"x-api-key": self._api_key,
|
|
83
|
+
"User-Agent": "trustos-python-sdk/0.1.0",
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
def verify_decision(self, payload: dict[str, Any]) -> dict[str, Any]:
|
|
87
|
+
"""Submit a decision payload for verification.
|
|
88
|
+
|
|
89
|
+
Args:
|
|
90
|
+
payload: Decision fields. ``action`` is the only required key.
|
|
91
|
+
Optional keys: ``amount``, ``currency``, ``destination``,
|
|
92
|
+
``source``, ``priority``, ``metadata``.
|
|
93
|
+
|
|
94
|
+
Returns:
|
|
95
|
+
Parsed JSON response containing ``decision_id``,
|
|
96
|
+
``recommendation``, ``risk_score``, ``risk_level``, ``policy``,
|
|
97
|
+
``proof_hash``, ``verified``, and ``latency_ms``.
|
|
98
|
+
|
|
99
|
+
Raises:
|
|
100
|
+
TrustOSError: On non-2xx HTTP status or unparseable response.
|
|
101
|
+
"""
|
|
102
|
+
url = f"{self._base_url}{_VERIFY_PATH}"
|
|
103
|
+
try:
|
|
104
|
+
response = self._session.post(url, json=payload, timeout=self._timeout)
|
|
105
|
+
except requests.RequestException as exc:
|
|
106
|
+
raise TrustOSError(f"Request failed: {exc}") from exc
|
|
107
|
+
|
|
108
|
+
if not response.ok:
|
|
109
|
+
try:
|
|
110
|
+
body = response.text
|
|
111
|
+
except Exception:
|
|
112
|
+
body = None
|
|
113
|
+
raise TrustOSError(
|
|
114
|
+
f"API error {response.status_code}: {response.reason}",
|
|
115
|
+
status_code=response.status_code,
|
|
116
|
+
response_body=body,
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
try:
|
|
120
|
+
return response.json()
|
|
121
|
+
except ValueError as exc:
|
|
122
|
+
raise TrustOSError(
|
|
123
|
+
"Invalid JSON in API response",
|
|
124
|
+
status_code=response.status_code,
|
|
125
|
+
response_body=response.text,
|
|
126
|
+
) from exc
|
|
127
|
+
|
|
128
|
+
def verify(self, payload: dict[str, Any]) -> dict[str, Any]:
|
|
129
|
+
"""Alias for :meth:`verify_decision`."""
|
|
130
|
+
return self.verify_decision(payload)
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: trustos
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python SDK for the Trust OS Decision Verification API
|
|
5
|
+
Author-email: "Trustfolio Inc." <admin@trust-os.io>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://trust-os.io
|
|
8
|
+
Project-URL: Documentation, https://trust-os.io/docs
|
|
9
|
+
Project-URL: Source, https://github.com/trustos-trustfolio/trustos-python-sdk
|
|
10
|
+
Project-URL: Issues, https://github.com/trustos-trustfolio/trustos-python-sdk/issues
|
|
11
|
+
Project-URL: OpenAPI, https://trust-os.io/openapi.json
|
|
12
|
+
Keywords: trust-os,decision-verification,ai-agents,fintech,api-client
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
22
|
+
Requires-Python: >=3.9
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: requests>=2.31.0
|
|
26
|
+
Provides-Extra: dev
|
|
27
|
+
Requires-Dist: pytest>=8.0.0; extra == "dev"
|
|
28
|
+
Requires-Dist: responses>=0.25.0; extra == "dev"
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
|
|
31
|
+
# Trust OS Python SDK
|
|
32
|
+
|
|
33
|
+
Python SDK for the [Trust OS Decision Verification API](https://trust-os.io/docs/api).
|
|
34
|
+
|
|
35
|
+
Verify high-impact decisions before execution — payments, treasury operations, AI agent actions, and compliance workflows — with a single function call.
|
|
36
|
+
|
|
37
|
+
## Links
|
|
38
|
+
|
|
39
|
+
| Resource | URL |
|
|
40
|
+
|---|---|
|
|
41
|
+
| Website | https://trust-os.io |
|
|
42
|
+
| Developer Docs | https://trust-os.io/docs |
|
|
43
|
+
| API Reference | https://trust-os.io/docs/api |
|
|
44
|
+
| Playground | https://demo.trust-os.io |
|
|
45
|
+
| Operations Demo | https://ops.trust-os.io |
|
|
46
|
+
| GitHub Organization | https://github.com/trustos-trustfolio |
|
|
47
|
+
| OpenAPI Spec | https://trust-os.io/openapi.json |
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Installation
|
|
52
|
+
|
|
53
|
+
> **PyPI release coming soon.** For now, install directly from GitHub once the repository is published:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
pip install git+https://github.com/trustos-trustfolio/trustos-python-sdk.git
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Once published to PyPI:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
pip install trustos
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## Quick Start
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
from trustos import TrustOSClient
|
|
71
|
+
|
|
72
|
+
client = TrustOSClient(api_key="YOUR_API_KEY")
|
|
73
|
+
|
|
74
|
+
result = client.verify_decision({
|
|
75
|
+
"action": "stablecoin_transfer",
|
|
76
|
+
"amount": 50000,
|
|
77
|
+
"currency": "USDC",
|
|
78
|
+
"destination": "wallet_abc",
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
print(result["recommendation"]) # APPROVE | REVIEW | DENY
|
|
82
|
+
print(result["proof_hash"]) # SHA-256: 0x4a3f...9c2b
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## Environment Variables
|
|
88
|
+
|
|
89
|
+
Store your API key as an environment variable instead of hardcoding it:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
# .env (never commit this file)
|
|
93
|
+
TRUSTOS_API_KEY=your_api_key_here
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
The client reads `TRUSTOS_API_KEY` automatically when no `api_key=` argument is provided:
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
from trustos import TrustOSClient
|
|
100
|
+
|
|
101
|
+
client = TrustOSClient() # reads TRUSTOS_API_KEY from environment
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## Examples
|
|
107
|
+
|
|
108
|
+
### Stablecoin Payment
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
from trustos import TrustOSClient
|
|
112
|
+
|
|
113
|
+
client = TrustOSClient()
|
|
114
|
+
|
|
115
|
+
result = client.verify_decision({
|
|
116
|
+
"action": "stablecoin_transfer",
|
|
117
|
+
"amount": 250000,
|
|
118
|
+
"currency": "USDC",
|
|
119
|
+
"destination": "wallet_0x4f3b9c2a8d1e6f5a",
|
|
120
|
+
"source": "Payment API",
|
|
121
|
+
"priority": "High",
|
|
122
|
+
"metadata": {"region": "SG", "workflow": "merchant_settlement"},
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
if result["recommendation"] == "APPROVE":
|
|
126
|
+
# safe to execute the transfer
|
|
127
|
+
print("Approved:", result["decision_id"])
|
|
128
|
+
elif result["recommendation"] == "REVIEW":
|
|
129
|
+
# queue for human review
|
|
130
|
+
queue_for_review(result["decision_id"])
|
|
131
|
+
else:
|
|
132
|
+
# block the transfer
|
|
133
|
+
raise ValueError("Payment denied by Trust OS policy")
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Treasury Disbursement
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
result = client.verify_decision({
|
|
140
|
+
"action": "treasury_disbursement",
|
|
141
|
+
"amount": 1_000_000,
|
|
142
|
+
"currency": "USDC",
|
|
143
|
+
"destination": "dao_multisig_0x91a3b7c2",
|
|
144
|
+
"source": "governance-system",
|
|
145
|
+
"priority": "High",
|
|
146
|
+
})
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### AI Agent Action
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
result = client.verify_decision({
|
|
153
|
+
"action": "execute_tool",
|
|
154
|
+
"destination": "database_write",
|
|
155
|
+
"source": "agent-framework",
|
|
156
|
+
"priority": "High",
|
|
157
|
+
"metadata": {"tool": "write_record", "agent_id": "agent_alpha_001"},
|
|
158
|
+
})
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
More complete examples are in the [`examples/`](./examples/) directory.
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
## API Reference
|
|
166
|
+
|
|
167
|
+
### `TrustOSClient(api_key=None, base_url=None, timeout=10.0)`
|
|
168
|
+
|
|
169
|
+
| Parameter | Type | Default | Description |
|
|
170
|
+
|---|---|---|---|
|
|
171
|
+
| `api_key` | `str \| None` | `None` | API key. Falls back to `TRUSTOS_API_KEY` env var. |
|
|
172
|
+
| `base_url` | `str \| None` | Production gateway | Override the API base URL. |
|
|
173
|
+
| `timeout` | `float` | `10.0` | Request timeout in seconds. |
|
|
174
|
+
|
|
175
|
+
Raises `ValueError` if no API key is found.
|
|
176
|
+
|
|
177
|
+
### `client.verify_decision(payload: dict) -> dict`
|
|
178
|
+
|
|
179
|
+
Submit a decision for verification. Returns the parsed JSON response.
|
|
180
|
+
|
|
181
|
+
**Request fields:**
|
|
182
|
+
|
|
183
|
+
| Field | Type | Required | Description |
|
|
184
|
+
|---|---|---|---|
|
|
185
|
+
| `action` | string | **Yes** | Decision action type |
|
|
186
|
+
| `amount` | number | No | Transaction amount |
|
|
187
|
+
| `currency` | string | No | Currency or asset symbol |
|
|
188
|
+
| `destination` | string | No | Target wallet or account |
|
|
189
|
+
| `source` | string | No | Originating system |
|
|
190
|
+
| `priority` | string | No | `"High"`, `"Medium"`, or `"Low"` |
|
|
191
|
+
| `metadata` | object | No | Additional context fields |
|
|
192
|
+
|
|
193
|
+
**Response fields:**
|
|
194
|
+
|
|
195
|
+
| Field | Type | Description |
|
|
196
|
+
|---|---|---|
|
|
197
|
+
| `decision_id` | string | Unique identifier — store for audit trail |
|
|
198
|
+
| `recommendation` | string | `APPROVE`, `REVIEW`, or `DENY` |
|
|
199
|
+
| `risk_score` | number | 0.0 (no risk) to 1.0 (maximum) |
|
|
200
|
+
| `risk_level` | string | `LOW`, `MEDIUM`, or `HIGH` |
|
|
201
|
+
| `policy` | string | Policy name and version applied |
|
|
202
|
+
| `proof_hash` | string | SHA-256 cryptographic proof |
|
|
203
|
+
| `verified` | boolean | True when cryptographically verified |
|
|
204
|
+
| `latency_ms` | number | Evaluation latency in milliseconds |
|
|
205
|
+
|
|
206
|
+
### `client.verify(payload: dict) -> dict`
|
|
207
|
+
|
|
208
|
+
Alias for `verify_decision()`.
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
## Error Handling
|
|
213
|
+
|
|
214
|
+
```python
|
|
215
|
+
from trustos import TrustOSClient, TrustOSError
|
|
216
|
+
|
|
217
|
+
client = TrustOSClient()
|
|
218
|
+
|
|
219
|
+
try:
|
|
220
|
+
result = client.verify_decision({"action": "stablecoin_transfer"})
|
|
221
|
+
except TrustOSError as e:
|
|
222
|
+
print(f"Status code: {e.status_code}")
|
|
223
|
+
print(f"Response body: {e.response_body}")
|
|
224
|
+
print(f"Message: {e}")
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
`TrustOSError` is raised on:
|
|
228
|
+
|
|
229
|
+
- Non-2xx HTTP responses (401 unauthorized, 429 rate limit, 500 server error, etc.)
|
|
230
|
+
- Network errors or timeouts
|
|
231
|
+
- Invalid JSON in the response body
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
## Security
|
|
236
|
+
|
|
237
|
+
- **Never commit your API key.** Use environment variables or a secrets manager.
|
|
238
|
+
- **Never hardcode keys in example scripts.** All examples use `TrustOSClient()` with no inline key.
|
|
239
|
+
- See [SECURITY.md](./SECURITY.md) for the vulnerability disclosure policy.
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
## Contributing
|
|
244
|
+
|
|
245
|
+
See [CONTRIBUTING.md](./CONTRIBUTING.md) for guidelines.
|
|
246
|
+
|
|
247
|
+
---
|
|
248
|
+
|
|
249
|
+
## Changelog
|
|
250
|
+
|
|
251
|
+
See [CHANGELOG.md](./CHANGELOG.md) for version history.
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
255
|
+
## License
|
|
256
|
+
|
|
257
|
+
MIT — see [LICENSE](./LICENSE).
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
trustos/__init__.py,sha256=2ZYdVg8_zzKng45Fn3XMJiYRHAHG1EXntj_gFU_uHj4,150
|
|
2
|
+
trustos/client.py,sha256=cboZ63EmpPgMenrivskhwzezLu7bL92nyFuHlhTlJ_4,4277
|
|
3
|
+
trustos-0.1.0.dist-info/licenses/LICENSE,sha256=FNhLNRUeGl_PzaXQaUfYmy6KxaL19KSBDXj3v5zdglg,1083
|
|
4
|
+
trustos-0.1.0.dist-info/METADATA,sha256=l7NrW0bTbVVNcausBMNT2RB378tkzj0e2h0E-3G9K_o,7251
|
|
5
|
+
trustos-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
6
|
+
trustos-0.1.0.dist-info/top_level.txt,sha256=r5B1QqBxVi_5HaVyysYSAF77AftJEwxMGbKF_8rPYfg,8
|
|
7
|
+
trustos-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Trust OS / Trustfolio 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.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
trustos
|