minikai 0.1.7__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.
Potentially problematic release.
This version of minikai might be problematic. Click here for more details.
- minikai/__init__.py +8 -0
- minikai/api/__init__.py +1 -0
- minikai/api/groups/__init__.py +1 -0
- minikai/api/groups/add_minis_to_group.py +196 -0
- minikai/api/groups/add_users_to_group.py +196 -0
- minikai/api/groups/create_group.py +178 -0
- minikai/api/groups/delete_group.py +115 -0
- minikai/api/groups/get_group.py +170 -0
- minikai/api/groups/get_group_minis.py +175 -0
- minikai/api/groups/get_group_users.py +175 -0
- minikai/api/groups/get_groups.py +150 -0
- minikai/api/groups/remove_minis_from_group.py +196 -0
- minikai/api/groups/remove_users_from_group.py +196 -0
- minikai/api/groups/update_group.py +195 -0
- minikai/api/minis/__init__.py +1 -0
- minikai/api/minis/create_mini.py +178 -0
- minikai/api/minis/delete_mini.py +115 -0
- minikai/api/minis/get_external_mini.py +183 -0
- minikai/api/minis/get_minis.py +150 -0
- minikai/api/minis/patch_mini.py +195 -0
- minikai/api/minis/update_mini.py +195 -0
- minikai/api/records/__init__.py +1 -0
- minikai/api/records/add_attachments.py +203 -0
- minikai/api/records/add_relations.py +209 -0
- minikai/api/records/create_record.py +182 -0
- minikai/api/records/delete_record.py +115 -0
- minikai/api/records/download_attachment.py +119 -0
- minikai/api/records/get_created_by.py +202 -0
- minikai/api/records/get_labels.py +194 -0
- minikai/api/records/get_records_by_external.py +248 -0
- minikai/api/records/get_states.py +194 -0
- minikai/api/records/get_updated_by.py +202 -0
- minikai/api/records/remove_attachments.py +132 -0
- minikai/api/records/remove_relations.py +132 -0
- minikai/api/records/update_attachments.py +203 -0
- minikai/api/records/update_record.py +199 -0
- minikai/api/records/update_relations.py +209 -0
- minikai/api/records/upsert_records_by_external_uri.py +182 -0
- minikai/api/users/__init__.py +1 -0
- minikai/api/users/delete_api_users_minis.py +122 -0
- minikai/api/users/get_api_users_minis.py +175 -0
- minikai/api/users/get_users.py +150 -0
- minikai/api/users/post_api_users_minis.py +187 -0
- minikai/client.py +271 -0
- minikai/errors.py +14 -0
- minikai/models/__init__.py +103 -0
- minikai/models/add_attachments_body.py +140 -0
- minikai/models/batch_upsert_result.py +124 -0
- minikai/models/create_group_command.py +127 -0
- minikai/models/create_mini_command.py +144 -0
- minikai/models/create_record_command.py +263 -0
- minikai/models/create_record_command_tags.py +63 -0
- minikai/models/cursor_paginated_list_of_record_dto.py +122 -0
- minikai/models/document_file_dto.py +171 -0
- minikai/models/document_file_metadata_dto.py +72 -0
- minikai/models/failed_upsert_item.py +83 -0
- minikai/models/form_field.py +138 -0
- minikai/models/form_field_dto.py +181 -0
- minikai/models/form_field_type.py +10 -0
- minikai/models/group_dto.py +155 -0
- minikai/models/http_validation_problem_details.py +198 -0
- minikai/models/http_validation_problem_details_errors.py +74 -0
- minikai/models/mini_dto.py +224 -0
- minikai/models/mini_template_dto.py +167 -0
- minikai/models/paginated_list_of_record_dto.py +124 -0
- minikai/models/patch_mini_command.py +102 -0
- minikai/models/problem_details.py +174 -0
- minikai/models/record.py +441 -0
- minikai/models/record_attachment.py +265 -0
- minikai/models/record_attachment_dto.py +265 -0
- minikai/models/record_attachment_dto_metadata_type_0.py +63 -0
- minikai/models/record_attachment_metadata_type_0.py +63 -0
- minikai/models/record_authorization.py +107 -0
- minikai/models/record_authorization_dto.py +107 -0
- minikai/models/record_dto.py +385 -0
- minikai/models/record_dto_tags.py +63 -0
- minikai/models/record_relation.py +105 -0
- minikai/models/record_relation_dto.py +105 -0
- minikai/models/record_state.py +10 -0
- minikai/models/record_tag.py +159 -0
- minikai/models/record_tag_dto.py +68 -0
- minikai/models/slim_mini_dto.py +197 -0
- minikai/models/tool_dto.py +95 -0
- minikai/models/update_attachments_body.py +140 -0
- minikai/models/update_group_command.py +148 -0
- minikai/models/update_mini_command.py +153 -0
- minikai/models/update_mini_template_workspaces_command.py +74 -0
- minikai/models/update_record_command.py +274 -0
- minikai/models/update_record_command_tags.py +63 -0
- minikai/models/upsert_record_dto.py +275 -0
- minikai/models/upsert_record_dto_tags.py +63 -0
- minikai/models/upsert_records_by_external_uri_command.py +79 -0
- minikai/models/user_dto.py +215 -0
- minikai/models/user_to_mini_dto.py +99 -0
- minikai/models/workspace_dto.py +99 -0
- minikai/py.typed +1 -0
- minikai/types.py +53 -0
- minikai-0.1.7.dist-info/METADATA +133 -0
- minikai-0.1.7.dist-info/RECORD +100 -0
- minikai-0.1.7.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
from http import HTTPStatus
|
|
2
|
+
from typing import Any, Optional, Union, cast
|
|
3
|
+
|
|
4
|
+
import httpx
|
|
5
|
+
|
|
6
|
+
from ...client import AuthenticatedClient, Client
|
|
7
|
+
from ...types import Response, UNSET
|
|
8
|
+
from ... import errors
|
|
9
|
+
|
|
10
|
+
from ...models.http_validation_problem_details import HttpValidationProblemDetails
|
|
11
|
+
from typing import cast
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _get_kwargs(
|
|
16
|
+
user_id: str,
|
|
17
|
+
mini_id: int,
|
|
18
|
+
|
|
19
|
+
) -> dict[str, Any]:
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
_kwargs: dict[str, Any] = {
|
|
27
|
+
"method": "post",
|
|
28
|
+
"url": "/api/Users/{user_id}/minis/{mini_id}".format(user_id=user_id,mini_id=mini_id,),
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
return _kwargs
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Union[Any, HttpValidationProblemDetails]]:
|
|
37
|
+
if response.status_code == 204:
|
|
38
|
+
response_204 = cast(Any, None)
|
|
39
|
+
return response_204
|
|
40
|
+
|
|
41
|
+
if response.status_code == 400:
|
|
42
|
+
response_400 = HttpValidationProblemDetails.from_dict(response.json())
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
return response_400
|
|
47
|
+
|
|
48
|
+
if response.status_code == 404:
|
|
49
|
+
response_404 = cast(Any, None)
|
|
50
|
+
return response_404
|
|
51
|
+
|
|
52
|
+
if client.raise_on_unexpected_status:
|
|
53
|
+
raise errors.UnexpectedStatus(response.status_code, response.content)
|
|
54
|
+
else:
|
|
55
|
+
return None
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[Union[Any, HttpValidationProblemDetails]]:
|
|
59
|
+
return Response(
|
|
60
|
+
status_code=HTTPStatus(response.status_code),
|
|
61
|
+
content=response.content,
|
|
62
|
+
headers=response.headers,
|
|
63
|
+
parsed=_parse_response(client=client, response=response),
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def sync_detailed(
|
|
68
|
+
user_id: str,
|
|
69
|
+
mini_id: int,
|
|
70
|
+
*,
|
|
71
|
+
client: Union[AuthenticatedClient, Client],
|
|
72
|
+
|
|
73
|
+
) -> Response[Union[Any, HttpValidationProblemDetails]]:
|
|
74
|
+
"""
|
|
75
|
+
Args:
|
|
76
|
+
user_id (str):
|
|
77
|
+
mini_id (int):
|
|
78
|
+
|
|
79
|
+
Raises:
|
|
80
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
|
81
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
|
82
|
+
|
|
83
|
+
Returns:
|
|
84
|
+
Response[Union[Any, HttpValidationProblemDetails]]
|
|
85
|
+
"""
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
kwargs = _get_kwargs(
|
|
89
|
+
user_id=user_id,
|
|
90
|
+
mini_id=mini_id,
|
|
91
|
+
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
response = client.get_httpx_client().request(
|
|
95
|
+
**kwargs,
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
return _build_response(client=client, response=response)
|
|
99
|
+
|
|
100
|
+
def sync(
|
|
101
|
+
user_id: str,
|
|
102
|
+
mini_id: int,
|
|
103
|
+
*,
|
|
104
|
+
client: Union[AuthenticatedClient, Client],
|
|
105
|
+
|
|
106
|
+
) -> Optional[Union[Any, HttpValidationProblemDetails]]:
|
|
107
|
+
"""
|
|
108
|
+
Args:
|
|
109
|
+
user_id (str):
|
|
110
|
+
mini_id (int):
|
|
111
|
+
|
|
112
|
+
Raises:
|
|
113
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
|
114
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
|
115
|
+
|
|
116
|
+
Returns:
|
|
117
|
+
Union[Any, HttpValidationProblemDetails]
|
|
118
|
+
"""
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
return sync_detailed(
|
|
122
|
+
user_id=user_id,
|
|
123
|
+
mini_id=mini_id,
|
|
124
|
+
client=client,
|
|
125
|
+
|
|
126
|
+
).parsed
|
|
127
|
+
|
|
128
|
+
async def asyncio_detailed(
|
|
129
|
+
user_id: str,
|
|
130
|
+
mini_id: int,
|
|
131
|
+
*,
|
|
132
|
+
client: Union[AuthenticatedClient, Client],
|
|
133
|
+
|
|
134
|
+
) -> Response[Union[Any, HttpValidationProblemDetails]]:
|
|
135
|
+
"""
|
|
136
|
+
Args:
|
|
137
|
+
user_id (str):
|
|
138
|
+
mini_id (int):
|
|
139
|
+
|
|
140
|
+
Raises:
|
|
141
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
|
142
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
|
143
|
+
|
|
144
|
+
Returns:
|
|
145
|
+
Response[Union[Any, HttpValidationProblemDetails]]
|
|
146
|
+
"""
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
kwargs = _get_kwargs(
|
|
150
|
+
user_id=user_id,
|
|
151
|
+
mini_id=mini_id,
|
|
152
|
+
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
response = await client.get_async_httpx_client().request(
|
|
156
|
+
**kwargs
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
return _build_response(client=client, response=response)
|
|
160
|
+
|
|
161
|
+
async def asyncio(
|
|
162
|
+
user_id: str,
|
|
163
|
+
mini_id: int,
|
|
164
|
+
*,
|
|
165
|
+
client: Union[AuthenticatedClient, Client],
|
|
166
|
+
|
|
167
|
+
) -> Optional[Union[Any, HttpValidationProblemDetails]]:
|
|
168
|
+
"""
|
|
169
|
+
Args:
|
|
170
|
+
user_id (str):
|
|
171
|
+
mini_id (int):
|
|
172
|
+
|
|
173
|
+
Raises:
|
|
174
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
|
175
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
|
176
|
+
|
|
177
|
+
Returns:
|
|
178
|
+
Union[Any, HttpValidationProblemDetails]
|
|
179
|
+
"""
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
return (await asyncio_detailed(
|
|
183
|
+
user_id=user_id,
|
|
184
|
+
mini_id=mini_id,
|
|
185
|
+
client=client,
|
|
186
|
+
|
|
187
|
+
)).parsed
|
minikai/client.py
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import ssl
|
|
2
|
+
from typing import Any, Union, Optional
|
|
3
|
+
|
|
4
|
+
from attrs import define, field, evolve
|
|
5
|
+
import httpx
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@define
|
|
12
|
+
class Client:
|
|
13
|
+
"""A class for keeping track of data related to the API
|
|
14
|
+
|
|
15
|
+
The following are accepted as keyword arguments and will be used to construct httpx Clients internally:
|
|
16
|
+
|
|
17
|
+
``base_url``: The base URL for the API, all requests are made to a relative path to this URL
|
|
18
|
+
|
|
19
|
+
``cookies``: A dictionary of cookies to be sent with every request
|
|
20
|
+
|
|
21
|
+
``headers``: A dictionary of headers to be sent with every request
|
|
22
|
+
|
|
23
|
+
``timeout``: The maximum amount of a time a request can take. API functions will raise
|
|
24
|
+
httpx.TimeoutException if this is exceeded.
|
|
25
|
+
|
|
26
|
+
``verify_ssl``: Whether or not to verify the SSL certificate of the API server. This should be True in production,
|
|
27
|
+
but can be set to False for testing purposes.
|
|
28
|
+
|
|
29
|
+
``follow_redirects``: Whether or not to follow redirects. Default value is False.
|
|
30
|
+
|
|
31
|
+
``httpx_args``: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor.
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
Attributes:
|
|
35
|
+
raise_on_unexpected_status: Whether or not to raise an errors.UnexpectedStatus if the API returns a
|
|
36
|
+
status code that was not documented in the source OpenAPI document. Can also be provided as a keyword
|
|
37
|
+
argument to the constructor.
|
|
38
|
+
"""
|
|
39
|
+
raise_on_unexpected_status: bool = field(default=False, kw_only=True)
|
|
40
|
+
_base_url: str = field(alias="base_url")
|
|
41
|
+
_cookies: dict[str, str] = field(factory=dict, kw_only=True, alias="cookies")
|
|
42
|
+
_headers: dict[str, str] = field(factory=dict, kw_only=True, alias="headers")
|
|
43
|
+
_timeout: Optional[httpx.Timeout] = field(default=None, kw_only=True, alias="timeout")
|
|
44
|
+
_verify_ssl: Union[str, bool, ssl.SSLContext] = field(default=True, kw_only=True, alias="verify_ssl")
|
|
45
|
+
_follow_redirects: bool = field(default=False, kw_only=True, alias="follow_redirects")
|
|
46
|
+
_httpx_args: dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args")
|
|
47
|
+
_client: Optional[httpx.Client] = field(default=None, init=False)
|
|
48
|
+
_async_client: Optional[httpx.AsyncClient] = field(default=None, init=False)
|
|
49
|
+
|
|
50
|
+
def with_headers(self, headers: dict[str, str]) -> "Client":
|
|
51
|
+
"""Get a new client matching this one with additional headers"""
|
|
52
|
+
if self._client is not None:
|
|
53
|
+
self._client.headers.update(headers)
|
|
54
|
+
if self._async_client is not None:
|
|
55
|
+
self._async_client.headers.update(headers)
|
|
56
|
+
return evolve(self, headers={**self._headers, **headers})
|
|
57
|
+
|
|
58
|
+
def with_cookies(self, cookies: dict[str, str]) -> "Client":
|
|
59
|
+
"""Get a new client matching this one with additional cookies"""
|
|
60
|
+
if self._client is not None:
|
|
61
|
+
self._client.cookies.update(cookies)
|
|
62
|
+
if self._async_client is not None:
|
|
63
|
+
self._async_client.cookies.update(cookies)
|
|
64
|
+
return evolve(self, cookies={**self._cookies, **cookies})
|
|
65
|
+
|
|
66
|
+
def with_timeout(self, timeout: httpx.Timeout) -> "Client":
|
|
67
|
+
"""Get a new client matching this one with a new timeout (in seconds)"""
|
|
68
|
+
if self._client is not None:
|
|
69
|
+
self._client.timeout = timeout
|
|
70
|
+
if self._async_client is not None:
|
|
71
|
+
self._async_client.timeout = timeout
|
|
72
|
+
return evolve(self, timeout=timeout)
|
|
73
|
+
|
|
74
|
+
def set_httpx_client(self, client: httpx.Client) -> "Client":
|
|
75
|
+
"""Manually set the underlying httpx.Client
|
|
76
|
+
|
|
77
|
+
**NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
|
|
78
|
+
"""
|
|
79
|
+
self._client = client
|
|
80
|
+
return self
|
|
81
|
+
|
|
82
|
+
def get_httpx_client(self) -> httpx.Client:
|
|
83
|
+
"""Get the underlying httpx.Client, constructing a new one if not previously set"""
|
|
84
|
+
if self._client is None:
|
|
85
|
+
self._client = httpx.Client(
|
|
86
|
+
base_url=self._base_url,
|
|
87
|
+
cookies=self._cookies,
|
|
88
|
+
headers=self._headers,
|
|
89
|
+
timeout=self._timeout,
|
|
90
|
+
verify=self._verify_ssl,
|
|
91
|
+
follow_redirects=self._follow_redirects,
|
|
92
|
+
**self._httpx_args,
|
|
93
|
+
)
|
|
94
|
+
return self._client
|
|
95
|
+
|
|
96
|
+
def __enter__(self) -> "Client":
|
|
97
|
+
"""Enter a context manager for self.client—you cannot enter twice (see httpx docs)"""
|
|
98
|
+
self.get_httpx_client().__enter__()
|
|
99
|
+
return self
|
|
100
|
+
|
|
101
|
+
def __exit__(self, *args: Any, **kwargs: Any) -> None:
|
|
102
|
+
"""Exit a context manager for internal httpx.Client (see httpx docs)"""
|
|
103
|
+
self.get_httpx_client().__exit__(*args, **kwargs)
|
|
104
|
+
|
|
105
|
+
def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> "Client":
|
|
106
|
+
"""Manually the underlying httpx.AsyncClient
|
|
107
|
+
|
|
108
|
+
**NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
|
|
109
|
+
"""
|
|
110
|
+
self._async_client = async_client
|
|
111
|
+
return self
|
|
112
|
+
|
|
113
|
+
def get_async_httpx_client(self) -> httpx.AsyncClient:
|
|
114
|
+
"""Get the underlying httpx.AsyncClient, constructing a new one if not previously set"""
|
|
115
|
+
if self._async_client is None:
|
|
116
|
+
self._async_client = httpx.AsyncClient(
|
|
117
|
+
base_url=self._base_url,
|
|
118
|
+
cookies=self._cookies,
|
|
119
|
+
headers=self._headers,
|
|
120
|
+
timeout=self._timeout,
|
|
121
|
+
verify=self._verify_ssl,
|
|
122
|
+
follow_redirects=self._follow_redirects,
|
|
123
|
+
**self._httpx_args,
|
|
124
|
+
)
|
|
125
|
+
return self._async_client
|
|
126
|
+
|
|
127
|
+
async def __aenter__(self) -> "Client":
|
|
128
|
+
"""Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)"""
|
|
129
|
+
await self.get_async_httpx_client().__aenter__()
|
|
130
|
+
return self
|
|
131
|
+
|
|
132
|
+
async def __aexit__(self, *args: Any, **kwargs: Any) -> None:
|
|
133
|
+
"""Exit a context manager for underlying httpx.AsyncClient (see httpx docs)"""
|
|
134
|
+
await self.get_async_httpx_client().__aexit__(*args, **kwargs)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
@define
|
|
138
|
+
class AuthenticatedClient:
|
|
139
|
+
"""A Client which has been authenticated for use on secured endpoints
|
|
140
|
+
|
|
141
|
+
The following are accepted as keyword arguments and will be used to construct httpx Clients internally:
|
|
142
|
+
|
|
143
|
+
``base_url``: The base URL for the API, all requests are made to a relative path to this URL
|
|
144
|
+
|
|
145
|
+
``cookies``: A dictionary of cookies to be sent with every request
|
|
146
|
+
|
|
147
|
+
``headers``: A dictionary of headers to be sent with every request
|
|
148
|
+
|
|
149
|
+
``timeout``: The maximum amount of a time a request can take. API functions will raise
|
|
150
|
+
httpx.TimeoutException if this is exceeded.
|
|
151
|
+
|
|
152
|
+
``verify_ssl``: Whether or not to verify the SSL certificate of the API server. This should be True in production,
|
|
153
|
+
but can be set to False for testing purposes.
|
|
154
|
+
|
|
155
|
+
``follow_redirects``: Whether or not to follow redirects. Default value is False.
|
|
156
|
+
|
|
157
|
+
``httpx_args``: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor.
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
Attributes:
|
|
161
|
+
raise_on_unexpected_status: Whether or not to raise an errors.UnexpectedStatus if the API returns a
|
|
162
|
+
status code that was not documented in the source OpenAPI document. Can also be provided as a keyword
|
|
163
|
+
argument to the constructor.
|
|
164
|
+
token: The token to use for authentication
|
|
165
|
+
prefix: The prefix to use for the Authorization header
|
|
166
|
+
auth_header_name: The name of the Authorization header
|
|
167
|
+
"""
|
|
168
|
+
|
|
169
|
+
raise_on_unexpected_status: bool = field(default=False, kw_only=True)
|
|
170
|
+
_base_url: str = field(alias="base_url")
|
|
171
|
+
_cookies: dict[str, str] = field(factory=dict, kw_only=True, alias="cookies")
|
|
172
|
+
_headers: dict[str, str] = field(factory=dict, kw_only=True, alias="headers")
|
|
173
|
+
_timeout: Optional[httpx.Timeout] = field(default=None, kw_only=True, alias="timeout")
|
|
174
|
+
_verify_ssl: Union[str, bool, ssl.SSLContext] = field(default=True, kw_only=True, alias="verify_ssl")
|
|
175
|
+
_follow_redirects: bool = field(default=False, kw_only=True, alias="follow_redirects")
|
|
176
|
+
_httpx_args: dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args")
|
|
177
|
+
_client: Optional[httpx.Client] = field(default=None, init=False)
|
|
178
|
+
_async_client: Optional[httpx.AsyncClient] = field(default=None, init=False)
|
|
179
|
+
|
|
180
|
+
token: str
|
|
181
|
+
prefix: str = "Bearer"
|
|
182
|
+
auth_header_name: str = "Authorization"
|
|
183
|
+
|
|
184
|
+
def with_headers(self, headers: dict[str, str]) -> "AuthenticatedClient":
|
|
185
|
+
"""Get a new client matching this one with additional headers"""
|
|
186
|
+
if self._client is not None:
|
|
187
|
+
self._client.headers.update(headers)
|
|
188
|
+
if self._async_client is not None:
|
|
189
|
+
self._async_client.headers.update(headers)
|
|
190
|
+
return evolve(self, headers={**self._headers, **headers})
|
|
191
|
+
|
|
192
|
+
def with_cookies(self, cookies: dict[str, str]) -> "AuthenticatedClient":
|
|
193
|
+
"""Get a new client matching this one with additional cookies"""
|
|
194
|
+
if self._client is not None:
|
|
195
|
+
self._client.cookies.update(cookies)
|
|
196
|
+
if self._async_client is not None:
|
|
197
|
+
self._async_client.cookies.update(cookies)
|
|
198
|
+
return evolve(self, cookies={**self._cookies, **cookies})
|
|
199
|
+
|
|
200
|
+
def with_timeout(self, timeout: httpx.Timeout) -> "AuthenticatedClient":
|
|
201
|
+
"""Get a new client matching this one with a new timeout (in seconds)"""
|
|
202
|
+
if self._client is not None:
|
|
203
|
+
self._client.timeout = timeout
|
|
204
|
+
if self._async_client is not None:
|
|
205
|
+
self._async_client.timeout = timeout
|
|
206
|
+
return evolve(self, timeout=timeout)
|
|
207
|
+
|
|
208
|
+
def set_httpx_client(self, client: httpx.Client) -> "AuthenticatedClient":
|
|
209
|
+
"""Manually set the underlying httpx.Client
|
|
210
|
+
|
|
211
|
+
**NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
|
|
212
|
+
"""
|
|
213
|
+
self._client = client
|
|
214
|
+
return self
|
|
215
|
+
|
|
216
|
+
def get_httpx_client(self) -> httpx.Client:
|
|
217
|
+
"""Get the underlying httpx.Client, constructing a new one if not previously set"""
|
|
218
|
+
if self._client is None:
|
|
219
|
+
self._headers[self.auth_header_name] = f"{self.prefix} {self.token}" if self.prefix else self.token
|
|
220
|
+
self._client = httpx.Client(
|
|
221
|
+
base_url=self._base_url,
|
|
222
|
+
cookies=self._cookies,
|
|
223
|
+
headers=self._headers,
|
|
224
|
+
timeout=self._timeout,
|
|
225
|
+
verify=self._verify_ssl,
|
|
226
|
+
follow_redirects=self._follow_redirects,
|
|
227
|
+
**self._httpx_args,
|
|
228
|
+
)
|
|
229
|
+
return self._client
|
|
230
|
+
|
|
231
|
+
def __enter__(self) -> "AuthenticatedClient":
|
|
232
|
+
"""Enter a context manager for self.client—you cannot enter twice (see httpx docs)"""
|
|
233
|
+
self.get_httpx_client().__enter__()
|
|
234
|
+
return self
|
|
235
|
+
|
|
236
|
+
def __exit__(self, *args: Any, **kwargs: Any) -> None:
|
|
237
|
+
"""Exit a context manager for internal httpx.Client (see httpx docs)"""
|
|
238
|
+
self.get_httpx_client().__exit__(*args, **kwargs)
|
|
239
|
+
|
|
240
|
+
def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> "AuthenticatedClient":
|
|
241
|
+
"""Manually the underlying httpx.AsyncClient
|
|
242
|
+
|
|
243
|
+
**NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
|
|
244
|
+
"""
|
|
245
|
+
self._async_client = async_client
|
|
246
|
+
return self
|
|
247
|
+
|
|
248
|
+
def get_async_httpx_client(self) -> httpx.AsyncClient:
|
|
249
|
+
"""Get the underlying httpx.AsyncClient, constructing a new one if not previously set"""
|
|
250
|
+
if self._async_client is None:
|
|
251
|
+
self._headers[self.auth_header_name] = f"{self.prefix} {self.token}" if self.prefix else self.token
|
|
252
|
+
self._async_client = httpx.AsyncClient(
|
|
253
|
+
base_url=self._base_url,
|
|
254
|
+
cookies=self._cookies,
|
|
255
|
+
headers=self._headers,
|
|
256
|
+
timeout=self._timeout,
|
|
257
|
+
verify=self._verify_ssl,
|
|
258
|
+
follow_redirects=self._follow_redirects,
|
|
259
|
+
**self._httpx_args,
|
|
260
|
+
)
|
|
261
|
+
return self._async_client
|
|
262
|
+
|
|
263
|
+
async def __aenter__(self) -> "AuthenticatedClient":
|
|
264
|
+
"""Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)"""
|
|
265
|
+
await self.get_async_httpx_client().__aenter__()
|
|
266
|
+
return self
|
|
267
|
+
|
|
268
|
+
async def __aexit__(self, *args: Any, **kwargs: Any) -> None:
|
|
269
|
+
"""Exit a context manager for underlying httpx.AsyncClient (see httpx docs)"""
|
|
270
|
+
await self.get_async_httpx_client().__aexit__(*args, **kwargs)
|
|
271
|
+
|
minikai/errors.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
""" Contains shared errors types that can be raised from API functions """
|
|
2
|
+
|
|
3
|
+
class UnexpectedStatus(Exception):
|
|
4
|
+
"""Raised by api functions when the response status an undocumented status and Client.raise_on_unexpected_status is True"""
|
|
5
|
+
|
|
6
|
+
def __init__(self, status_code: int, content: bytes):
|
|
7
|
+
self.status_code = status_code
|
|
8
|
+
self.content = content
|
|
9
|
+
|
|
10
|
+
super().__init__(
|
|
11
|
+
f"Unexpected status code: {status_code}\n\nResponse content:\n{content.decode(errors='ignore')}"
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
__all__ = ["UnexpectedStatus"]
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
""" Contains all the data models used in inputs/outputs """
|
|
2
|
+
|
|
3
|
+
from .add_attachments_body import AddAttachmentsBody
|
|
4
|
+
from .batch_upsert_result import BatchUpsertResult
|
|
5
|
+
from .create_group_command import CreateGroupCommand
|
|
6
|
+
from .create_mini_command import CreateMiniCommand
|
|
7
|
+
from .create_record_command import CreateRecordCommand
|
|
8
|
+
from .create_record_command_tags import CreateRecordCommandTags
|
|
9
|
+
from .cursor_paginated_list_of_record_dto import CursorPaginatedListOfRecordDto
|
|
10
|
+
from .document_file_dto import DocumentFileDto
|
|
11
|
+
from .document_file_metadata_dto import DocumentFileMetadataDto
|
|
12
|
+
from .failed_upsert_item import FailedUpsertItem
|
|
13
|
+
from .form_field import FormField
|
|
14
|
+
from .form_field_dto import FormFieldDto
|
|
15
|
+
from .form_field_type import FormFieldType
|
|
16
|
+
from .group_dto import GroupDto
|
|
17
|
+
from .http_validation_problem_details import HttpValidationProblemDetails
|
|
18
|
+
from .http_validation_problem_details_errors import HttpValidationProblemDetailsErrors
|
|
19
|
+
from .mini_dto import MiniDto
|
|
20
|
+
from .mini_template_dto import MiniTemplateDto
|
|
21
|
+
from .paginated_list_of_record_dto import PaginatedListOfRecordDto
|
|
22
|
+
from .patch_mini_command import PatchMiniCommand
|
|
23
|
+
from .problem_details import ProblemDetails
|
|
24
|
+
from .record import Record
|
|
25
|
+
from .record_attachment import RecordAttachment
|
|
26
|
+
from .record_attachment_dto import RecordAttachmentDto
|
|
27
|
+
from .record_attachment_dto_metadata_type_0 import RecordAttachmentDtoMetadataType0
|
|
28
|
+
from .record_attachment_metadata_type_0 import RecordAttachmentMetadataType0
|
|
29
|
+
from .record_authorization import RecordAuthorization
|
|
30
|
+
from .record_authorization_dto import RecordAuthorizationDto
|
|
31
|
+
from .record_dto import RecordDto
|
|
32
|
+
from .record_dto_tags import RecordDtoTags
|
|
33
|
+
from .record_relation import RecordRelation
|
|
34
|
+
from .record_relation_dto import RecordRelationDto
|
|
35
|
+
from .record_state import RecordState
|
|
36
|
+
from .record_tag import RecordTag
|
|
37
|
+
from .record_tag_dto import RecordTagDto
|
|
38
|
+
from .slim_mini_dto import SlimMiniDto
|
|
39
|
+
from .tool_dto import ToolDto
|
|
40
|
+
from .update_attachments_body import UpdateAttachmentsBody
|
|
41
|
+
from .update_group_command import UpdateGroupCommand
|
|
42
|
+
from .update_mini_command import UpdateMiniCommand
|
|
43
|
+
from .update_mini_template_workspaces_command import UpdateMiniTemplateWorkspacesCommand
|
|
44
|
+
from .update_record_command import UpdateRecordCommand
|
|
45
|
+
from .update_record_command_tags import UpdateRecordCommandTags
|
|
46
|
+
from .upsert_record_dto import UpsertRecordDto
|
|
47
|
+
from .upsert_record_dto_tags import UpsertRecordDtoTags
|
|
48
|
+
from .upsert_records_by_external_uri_command import UpsertRecordsByExternalUriCommand
|
|
49
|
+
from .user_dto import UserDto
|
|
50
|
+
from .user_to_mini_dto import UserToMiniDto
|
|
51
|
+
from .workspace_dto import WorkspaceDto
|
|
52
|
+
|
|
53
|
+
__all__ = (
|
|
54
|
+
"AddAttachmentsBody",
|
|
55
|
+
"BatchUpsertResult",
|
|
56
|
+
"CreateGroupCommand",
|
|
57
|
+
"CreateMiniCommand",
|
|
58
|
+
"CreateRecordCommand",
|
|
59
|
+
"CreateRecordCommandTags",
|
|
60
|
+
"CursorPaginatedListOfRecordDto",
|
|
61
|
+
"DocumentFileDto",
|
|
62
|
+
"DocumentFileMetadataDto",
|
|
63
|
+
"FailedUpsertItem",
|
|
64
|
+
"FormField",
|
|
65
|
+
"FormFieldDto",
|
|
66
|
+
"FormFieldType",
|
|
67
|
+
"GroupDto",
|
|
68
|
+
"HttpValidationProblemDetails",
|
|
69
|
+
"HttpValidationProblemDetailsErrors",
|
|
70
|
+
"MiniDto",
|
|
71
|
+
"MiniTemplateDto",
|
|
72
|
+
"PaginatedListOfRecordDto",
|
|
73
|
+
"PatchMiniCommand",
|
|
74
|
+
"ProblemDetails",
|
|
75
|
+
"Record",
|
|
76
|
+
"RecordAttachment",
|
|
77
|
+
"RecordAttachmentDto",
|
|
78
|
+
"RecordAttachmentDtoMetadataType0",
|
|
79
|
+
"RecordAttachmentMetadataType0",
|
|
80
|
+
"RecordAuthorization",
|
|
81
|
+
"RecordAuthorizationDto",
|
|
82
|
+
"RecordDto",
|
|
83
|
+
"RecordDtoTags",
|
|
84
|
+
"RecordRelation",
|
|
85
|
+
"RecordRelationDto",
|
|
86
|
+
"RecordState",
|
|
87
|
+
"RecordTag",
|
|
88
|
+
"RecordTagDto",
|
|
89
|
+
"SlimMiniDto",
|
|
90
|
+
"ToolDto",
|
|
91
|
+
"UpdateAttachmentsBody",
|
|
92
|
+
"UpdateGroupCommand",
|
|
93
|
+
"UpdateMiniCommand",
|
|
94
|
+
"UpdateMiniTemplateWorkspacesCommand",
|
|
95
|
+
"UpdateRecordCommand",
|
|
96
|
+
"UpdateRecordCommandTags",
|
|
97
|
+
"UpsertRecordDto",
|
|
98
|
+
"UpsertRecordDtoTags",
|
|
99
|
+
"UpsertRecordsByExternalUriCommand",
|
|
100
|
+
"UserDto",
|
|
101
|
+
"UserToMiniDto",
|
|
102
|
+
"WorkspaceDto",
|
|
103
|
+
)
|