truto-python-sdk 0.2.0__tar.gz → 0.3.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.
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/PKG-INFO +18 -1
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/README.md +17 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/pyproject.toml +1 -1
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/__init__.py +3 -2
- truto_python_sdk-0.3.0/truto_python_sdk/errors.py +106 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/truto_api.py +6 -5
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/LICENSE +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/alarm.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/analytics.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/api_token.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/base_resource.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/batch_request.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/category.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/custom_api.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/daemon.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/daemon_job.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/daemon_job_cron_trigger.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/daemon_job_run.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/datastore.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/dict_to_query_string.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/documentation.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/environment.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/environment_integration.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/environment_integration_webhook.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/environment_unified_model.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/environment_unified_model_resource_method.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/integrated_account.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/integrated_account_webhook.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/integration.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/link_token.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/log.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/mcp.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/observability_destination.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/pagination_result.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/proxy_api.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/sandbox_integrated_account.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/static_gate.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/sync_job.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/sync_job_cron_trigger.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/sync_job_run.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/sync_job_run_state.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/sync_job_template.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/team.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/tenant.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/unified_api.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/unified_model.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/unified_model_resource_method.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/user.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/webhook.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/workflow.py +0 -0
- {truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/workflow_run.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: truto-python-sdk
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Python3 SDK for the Truto API
|
|
5
5
|
License-File: LICENSE
|
|
6
6
|
Author: Roopendra Talekar
|
|
@@ -111,6 +111,23 @@ page = await truto_api.unified_api.list(
|
|
|
111
111
|
).next_page()
|
|
112
112
|
```
|
|
113
113
|
|
|
114
|
+
## Errors
|
|
115
|
+
|
|
116
|
+
A 4xx or 5xx response raises `TrutoApiError`. It subclasses `aiohttp.ClientResponseError`, so `.status`, `.message` and `.headers` work as before, and it also carries the response body Truto sent:
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
from truto_python_sdk import TrutoApiError
|
|
120
|
+
|
|
121
|
+
try:
|
|
122
|
+
await truto_api.integrated_accounts.get("missing-id")
|
|
123
|
+
except TrutoApiError as e:
|
|
124
|
+
print(e.status) # 404
|
|
125
|
+
print(e.error) # Truto's error message, if the body is JSON
|
|
126
|
+
print(e.truto_error_insight) # extra detail Truto attaches to some errors, or None
|
|
127
|
+
print(e.data) # the full parsed JSON body, or None
|
|
128
|
+
print(e.body) # the raw body as text
|
|
129
|
+
```
|
|
130
|
+
|
|
114
131
|
## Full reference
|
|
115
132
|
|
|
116
133
|
Every resource and method, with examples, is documented at **[truto.one/docs/sdks/python](https://truto.one/docs/sdks/python)**: the Unified, Proxy and Custom APIs, MCP, integrated accounts, tenants, integrations, unified models and mappings, sync jobs, webhooks, workflows, datastores, analytics, and more.
|
|
@@ -91,6 +91,23 @@ page = await truto_api.unified_api.list(
|
|
|
91
91
|
).next_page()
|
|
92
92
|
```
|
|
93
93
|
|
|
94
|
+
## Errors
|
|
95
|
+
|
|
96
|
+
A 4xx or 5xx response raises `TrutoApiError`. It subclasses `aiohttp.ClientResponseError`, so `.status`, `.message` and `.headers` work as before, and it also carries the response body Truto sent:
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
from truto_python_sdk import TrutoApiError
|
|
100
|
+
|
|
101
|
+
try:
|
|
102
|
+
await truto_api.integrated_accounts.get("missing-id")
|
|
103
|
+
except TrutoApiError as e:
|
|
104
|
+
print(e.status) # 404
|
|
105
|
+
print(e.error) # Truto's error message, if the body is JSON
|
|
106
|
+
print(e.truto_error_insight) # extra detail Truto attaches to some errors, or None
|
|
107
|
+
print(e.data) # the full parsed JSON body, or None
|
|
108
|
+
print(e.body) # the raw body as text
|
|
109
|
+
```
|
|
110
|
+
|
|
94
111
|
## Full reference
|
|
95
112
|
|
|
96
113
|
Every resource and method, with examples, is documented at **[truto.one/docs/sdks/python](https://truto.one/docs/sdks/python)**: the Unified, Proxy and Custom APIs, MCP, integrated accounts, tenants, integrations, unified models and mappings, sync jobs, webhooks, workflows, datastores, analytics, and more.
|
|
@@ -8,9 +8,10 @@ A Python3 SDK for the Truto API.
|
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
10
|
__title__ = 'truto_python_sdk'
|
|
11
|
-
__version__ = '0.
|
|
11
|
+
__version__ = '0.3.0'
|
|
12
12
|
__author__ = 'Roopendra Talekar <roopendra@truto.dev>'
|
|
13
13
|
__license__ = 'MIT'
|
|
14
14
|
__copyright__ = 'Copyright 2023 Yin Yang Inc.'
|
|
15
15
|
|
|
16
|
-
from .truto_api import TrutoApi
|
|
16
|
+
from .truto_api import TrutoApi
|
|
17
|
+
from .errors import TrutoApiError
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import codecs
|
|
3
|
+
import json
|
|
4
|
+
|
|
5
|
+
import aiohttp
|
|
6
|
+
|
|
7
|
+
# Error bodies are kept on the exception, so cap how much of one we read.
|
|
8
|
+
MAX_ERROR_BODY_BYTES = 64 * 1024
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class TrutoApiError(aiohttp.ClientResponseError):
|
|
12
|
+
"""Raised when the Truto API responds with a 4xx or 5xx status.
|
|
13
|
+
|
|
14
|
+
Subclasses ``aiohttp.ClientResponseError``, so existing ``except
|
|
15
|
+
aiohttp.ClientResponseError`` handlers keep working, and ``.status``,
|
|
16
|
+
``.message``, ``.headers`` and ``.request_info`` are unchanged. On top of
|
|
17
|
+
that it carries the response body Truto sent back:
|
|
18
|
+
|
|
19
|
+
- ``body``: the raw response body as text (``None`` if it could not be read)
|
|
20
|
+
- ``data``: the body parsed as JSON, or ``None`` if it isn't JSON
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
def __init__(
|
|
24
|
+
self,
|
|
25
|
+
request_info,
|
|
26
|
+
history,
|
|
27
|
+
*,
|
|
28
|
+
status=None,
|
|
29
|
+
message="",
|
|
30
|
+
headers=None,
|
|
31
|
+
body=None,
|
|
32
|
+
data=None,
|
|
33
|
+
):
|
|
34
|
+
# Defaults match aiohttp.ClientResponseError: copy/pickle rebuild the
|
|
35
|
+
# error as ``cls(request_info, history)`` and then restore __dict__.
|
|
36
|
+
super().__init__(request_info, history, status=status, message=message, headers=headers)
|
|
37
|
+
self.body = body
|
|
38
|
+
self.data = data
|
|
39
|
+
|
|
40
|
+
@property
|
|
41
|
+
def error(self):
|
|
42
|
+
"""Truto's error message (the ``error`` field of a JSON error body), if any."""
|
|
43
|
+
if isinstance(self.data, dict):
|
|
44
|
+
for key in ("error", "message"):
|
|
45
|
+
value = self.data.get(key)
|
|
46
|
+
if isinstance(value, str) and value:
|
|
47
|
+
return value
|
|
48
|
+
return None
|
|
49
|
+
|
|
50
|
+
@property
|
|
51
|
+
def truto_error_insight(self):
|
|
52
|
+
"""Truto's ``truto_error_insight`` object from the error body, if any."""
|
|
53
|
+
if isinstance(self.data, dict):
|
|
54
|
+
return self.data.get("truto_error_insight")
|
|
55
|
+
return None
|
|
56
|
+
|
|
57
|
+
def __str__(self):
|
|
58
|
+
base = super().__str__()
|
|
59
|
+
detail = self.error
|
|
60
|
+
if detail is None and self.body:
|
|
61
|
+
detail = self.body[:500]
|
|
62
|
+
return f"{base}, body={detail!r}" if detail else base
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _codec(charset):
|
|
66
|
+
"""The response's charset if Python knows it, else utf-8."""
|
|
67
|
+
if charset:
|
|
68
|
+
try:
|
|
69
|
+
return codecs.lookup(charset).name
|
|
70
|
+
except LookupError:
|
|
71
|
+
pass
|
|
72
|
+
return "utf-8"
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
async def raise_for_status(response: aiohttp.ClientResponse):
|
|
76
|
+
"""Like ``response.raise_for_status()`` but reads the body first so the
|
|
77
|
+
raised ``TrutoApiError`` carries Truto's error message."""
|
|
78
|
+
if response.ok:
|
|
79
|
+
return
|
|
80
|
+
body = None
|
|
81
|
+
data = None
|
|
82
|
+
try:
|
|
83
|
+
# read(n) returns as soon as anything is buffered, so a body sent in
|
|
84
|
+
# several chunks would be cut short. readexactly waits for n bytes and
|
|
85
|
+
# hands back what arrived when the body ends first.
|
|
86
|
+
try:
|
|
87
|
+
raw = await response.content.readexactly(MAX_ERROR_BODY_BYTES)
|
|
88
|
+
except asyncio.IncompleteReadError as e:
|
|
89
|
+
raw = e.partial
|
|
90
|
+
body = raw.decode(_codec(response.charset), errors="replace")
|
|
91
|
+
except Exception:
|
|
92
|
+
body = None
|
|
93
|
+
if body:
|
|
94
|
+
try:
|
|
95
|
+
data = json.loads(body)
|
|
96
|
+
except ValueError:
|
|
97
|
+
data = None
|
|
98
|
+
raise TrutoApiError(
|
|
99
|
+
response.request_info,
|
|
100
|
+
response.history,
|
|
101
|
+
status=response.status,
|
|
102
|
+
message=response.reason or "",
|
|
103
|
+
headers=response.headers,
|
|
104
|
+
body=body,
|
|
105
|
+
data=data,
|
|
106
|
+
)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import aiohttp
|
|
2
2
|
|
|
3
3
|
from .dict_to_query_string import dict_to_query_string
|
|
4
|
+
from .errors import raise_for_status
|
|
4
5
|
from .alarm import Alarm
|
|
5
6
|
from .daemon import Daemon
|
|
6
7
|
from .daemon_job import DaemonJob
|
|
@@ -114,7 +115,7 @@ class TrutoApi:
|
|
|
114
115
|
query_string = dict_to_query_string(params) if params else ""
|
|
115
116
|
async with aiohttp.ClientSession() as session:
|
|
116
117
|
async with session.get(f"{url}?{query_string}", headers=self.headers) as response:
|
|
117
|
-
|
|
118
|
+
await raise_for_status(response)
|
|
118
119
|
return await self._process_response(response)
|
|
119
120
|
|
|
120
121
|
async def _post(self, endpoint, data=None, params=None):
|
|
@@ -122,7 +123,7 @@ class TrutoApi:
|
|
|
122
123
|
query_string = dict_to_query_string(params) if params else ""
|
|
123
124
|
async with aiohttp.ClientSession() as session:
|
|
124
125
|
async with session.post(f"{url}?{query_string}", headers=self.headers, json=data) as response:
|
|
125
|
-
|
|
126
|
+
await raise_for_status(response)
|
|
126
127
|
return await self._process_response(response)
|
|
127
128
|
|
|
128
129
|
async def _patch(self, endpoint, data=None, params=None):
|
|
@@ -130,7 +131,7 @@ class TrutoApi:
|
|
|
130
131
|
query_string = dict_to_query_string(params) if params else ""
|
|
131
132
|
async with aiohttp.ClientSession() as session:
|
|
132
133
|
async with session.patch(f"{url}?{query_string}", headers=self.headers, json=data) as response:
|
|
133
|
-
|
|
134
|
+
await raise_for_status(response)
|
|
134
135
|
return await self._process_response(response)
|
|
135
136
|
|
|
136
137
|
async def _put(self, endpoint, data=None, params=None):
|
|
@@ -138,7 +139,7 @@ class TrutoApi:
|
|
|
138
139
|
query_string = dict_to_query_string(params) if params else ""
|
|
139
140
|
async with aiohttp.ClientSession() as session:
|
|
140
141
|
async with session.put(f"{url}?{query_string}", headers=self.headers, json=data) as response:
|
|
141
|
-
|
|
142
|
+
await raise_for_status(response)
|
|
142
143
|
return await self._process_response(response)
|
|
143
144
|
|
|
144
145
|
async def _delete(self, endpoint, params=None):
|
|
@@ -146,7 +147,7 @@ class TrutoApi:
|
|
|
146
147
|
query_string = dict_to_query_string(params) if params else ""
|
|
147
148
|
async with aiohttp.ClientSession() as session:
|
|
148
149
|
async with session.delete(f"{url}?{query_string}", headers=self.headers) as response:
|
|
149
|
-
|
|
150
|
+
await raise_for_status(response)
|
|
150
151
|
return await self._process_response(response)
|
|
151
152
|
|
|
152
153
|
async def ping(self):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/daemon_job_cron_trigger.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/environment_integration.py
RENAMED
|
File without changes
|
|
File without changes
|
{truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/environment_unified_model.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/integrated_account_webhook.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/observability_destination.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/sandbox_integrated_account.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{truto_python_sdk-0.2.0 → truto_python_sdk-0.3.0}/truto_python_sdk/unified_model_resource_method.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|