isaacus 0.1.0a1__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.
- isaacus/__init__.py +84 -0
- isaacus/_base_client.py +1969 -0
- isaacus/_client.py +397 -0
- isaacus/_compat.py +219 -0
- isaacus/_constants.py +14 -0
- isaacus/_exceptions.py +108 -0
- isaacus/_files.py +123 -0
- isaacus/_models.py +801 -0
- isaacus/_qs.py +150 -0
- isaacus/_resource.py +43 -0
- isaacus/_response.py +830 -0
- isaacus/_streaming.py +333 -0
- isaacus/_types.py +217 -0
- isaacus/_utils/__init__.py +57 -0
- isaacus/_utils/_logs.py +25 -0
- isaacus/_utils/_proxy.py +62 -0
- isaacus/_utils/_reflection.py +42 -0
- isaacus/_utils/_streams.py +12 -0
- isaacus/_utils/_sync.py +86 -0
- isaacus/_utils/_transform.py +402 -0
- isaacus/_utils/_typing.py +149 -0
- isaacus/_utils/_utils.py +414 -0
- isaacus/_version.py +4 -0
- isaacus/lib/.keep +4 -0
- isaacus/py.typed +0 -0
- isaacus/resources/__init__.py +19 -0
- isaacus/resources/classifications/__init__.py +33 -0
- isaacus/resources/classifications/classifications.py +102 -0
- isaacus/resources/classifications/universal.py +263 -0
- isaacus/types/__init__.py +3 -0
- isaacus/types/classifications/__init__.py +6 -0
- isaacus/types/classifications/universal_classification.py +55 -0
- isaacus/types/classifications/universal_create_params.py +64 -0
- isaacus-0.1.0a1.dist-info/METADATA +391 -0
- isaacus-0.1.0a1.dist-info/RECORD +37 -0
- isaacus-0.1.0a1.dist-info/WHEEL +4 -0
- isaacus-0.1.0a1.dist-info/licenses/LICENSE +201 -0
isaacus/_qs.py
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
3
|
+
from typing import Any, List, Tuple, Union, Mapping, TypeVar
|
4
|
+
from urllib.parse import parse_qs, urlencode
|
5
|
+
from typing_extensions import Literal, get_args
|
6
|
+
|
7
|
+
from ._types import NOT_GIVEN, NotGiven, NotGivenOr
|
8
|
+
from ._utils import flatten
|
9
|
+
|
10
|
+
_T = TypeVar("_T")
|
11
|
+
|
12
|
+
|
13
|
+
ArrayFormat = Literal["comma", "repeat", "indices", "brackets"]
|
14
|
+
NestedFormat = Literal["dots", "brackets"]
|
15
|
+
|
16
|
+
PrimitiveData = Union[str, int, float, bool, None]
|
17
|
+
# this should be Data = Union[PrimitiveData, "List[Data]", "Tuple[Data]", "Mapping[str, Data]"]
|
18
|
+
# https://github.com/microsoft/pyright/issues/3555
|
19
|
+
Data = Union[PrimitiveData, List[Any], Tuple[Any], "Mapping[str, Any]"]
|
20
|
+
Params = Mapping[str, Data]
|
21
|
+
|
22
|
+
|
23
|
+
class Querystring:
|
24
|
+
array_format: ArrayFormat
|
25
|
+
nested_format: NestedFormat
|
26
|
+
|
27
|
+
def __init__(
|
28
|
+
self,
|
29
|
+
*,
|
30
|
+
array_format: ArrayFormat = "repeat",
|
31
|
+
nested_format: NestedFormat = "brackets",
|
32
|
+
) -> None:
|
33
|
+
self.array_format = array_format
|
34
|
+
self.nested_format = nested_format
|
35
|
+
|
36
|
+
def parse(self, query: str) -> Mapping[str, object]:
|
37
|
+
# Note: custom format syntax is not supported yet
|
38
|
+
return parse_qs(query)
|
39
|
+
|
40
|
+
def stringify(
|
41
|
+
self,
|
42
|
+
params: Params,
|
43
|
+
*,
|
44
|
+
array_format: NotGivenOr[ArrayFormat] = NOT_GIVEN,
|
45
|
+
nested_format: NotGivenOr[NestedFormat] = NOT_GIVEN,
|
46
|
+
) -> str:
|
47
|
+
return urlencode(
|
48
|
+
self.stringify_items(
|
49
|
+
params,
|
50
|
+
array_format=array_format,
|
51
|
+
nested_format=nested_format,
|
52
|
+
)
|
53
|
+
)
|
54
|
+
|
55
|
+
def stringify_items(
|
56
|
+
self,
|
57
|
+
params: Params,
|
58
|
+
*,
|
59
|
+
array_format: NotGivenOr[ArrayFormat] = NOT_GIVEN,
|
60
|
+
nested_format: NotGivenOr[NestedFormat] = NOT_GIVEN,
|
61
|
+
) -> list[tuple[str, str]]:
|
62
|
+
opts = Options(
|
63
|
+
qs=self,
|
64
|
+
array_format=array_format,
|
65
|
+
nested_format=nested_format,
|
66
|
+
)
|
67
|
+
return flatten([self._stringify_item(key, value, opts) for key, value in params.items()])
|
68
|
+
|
69
|
+
def _stringify_item(
|
70
|
+
self,
|
71
|
+
key: str,
|
72
|
+
value: Data,
|
73
|
+
opts: Options,
|
74
|
+
) -> list[tuple[str, str]]:
|
75
|
+
if isinstance(value, Mapping):
|
76
|
+
items: list[tuple[str, str]] = []
|
77
|
+
nested_format = opts.nested_format
|
78
|
+
for subkey, subvalue in value.items():
|
79
|
+
items.extend(
|
80
|
+
self._stringify_item(
|
81
|
+
# TODO: error if unknown format
|
82
|
+
f"{key}.{subkey}" if nested_format == "dots" else f"{key}[{subkey}]",
|
83
|
+
subvalue,
|
84
|
+
opts,
|
85
|
+
)
|
86
|
+
)
|
87
|
+
return items
|
88
|
+
|
89
|
+
if isinstance(value, (list, tuple)):
|
90
|
+
array_format = opts.array_format
|
91
|
+
if array_format == "comma":
|
92
|
+
return [
|
93
|
+
(
|
94
|
+
key,
|
95
|
+
",".join(self._primitive_value_to_str(item) for item in value if item is not None),
|
96
|
+
),
|
97
|
+
]
|
98
|
+
elif array_format == "repeat":
|
99
|
+
items = []
|
100
|
+
for item in value:
|
101
|
+
items.extend(self._stringify_item(key, item, opts))
|
102
|
+
return items
|
103
|
+
elif array_format == "indices":
|
104
|
+
raise NotImplementedError("The array indices format is not supported yet")
|
105
|
+
elif array_format == "brackets":
|
106
|
+
items = []
|
107
|
+
key = key + "[]"
|
108
|
+
for item in value:
|
109
|
+
items.extend(self._stringify_item(key, item, opts))
|
110
|
+
return items
|
111
|
+
else:
|
112
|
+
raise NotImplementedError(
|
113
|
+
f"Unknown array_format value: {array_format}, choose from {', '.join(get_args(ArrayFormat))}"
|
114
|
+
)
|
115
|
+
|
116
|
+
serialised = self._primitive_value_to_str(value)
|
117
|
+
if not serialised:
|
118
|
+
return []
|
119
|
+
return [(key, serialised)]
|
120
|
+
|
121
|
+
def _primitive_value_to_str(self, value: PrimitiveData) -> str:
|
122
|
+
# copied from httpx
|
123
|
+
if value is True:
|
124
|
+
return "true"
|
125
|
+
elif value is False:
|
126
|
+
return "false"
|
127
|
+
elif value is None:
|
128
|
+
return ""
|
129
|
+
return str(value)
|
130
|
+
|
131
|
+
|
132
|
+
_qs = Querystring()
|
133
|
+
parse = _qs.parse
|
134
|
+
stringify = _qs.stringify
|
135
|
+
stringify_items = _qs.stringify_items
|
136
|
+
|
137
|
+
|
138
|
+
class Options:
|
139
|
+
array_format: ArrayFormat
|
140
|
+
nested_format: NestedFormat
|
141
|
+
|
142
|
+
def __init__(
|
143
|
+
self,
|
144
|
+
qs: Querystring = _qs,
|
145
|
+
*,
|
146
|
+
array_format: NotGivenOr[ArrayFormat] = NOT_GIVEN,
|
147
|
+
nested_format: NotGivenOr[NestedFormat] = NOT_GIVEN,
|
148
|
+
) -> None:
|
149
|
+
self.array_format = qs.array_format if isinstance(array_format, NotGiven) else array_format
|
150
|
+
self.nested_format = qs.nested_format if isinstance(nested_format, NotGiven) else nested_format
|
isaacus/_resource.py
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
2
|
+
|
3
|
+
from __future__ import annotations
|
4
|
+
|
5
|
+
import time
|
6
|
+
from typing import TYPE_CHECKING
|
7
|
+
|
8
|
+
import anyio
|
9
|
+
|
10
|
+
if TYPE_CHECKING:
|
11
|
+
from ._client import Isaacus, AsyncIsaacus
|
12
|
+
|
13
|
+
|
14
|
+
class SyncAPIResource:
|
15
|
+
_client: Isaacus
|
16
|
+
|
17
|
+
def __init__(self, client: Isaacus) -> None:
|
18
|
+
self._client = client
|
19
|
+
self._get = client.get
|
20
|
+
self._post = client.post
|
21
|
+
self._patch = client.patch
|
22
|
+
self._put = client.put
|
23
|
+
self._delete = client.delete
|
24
|
+
self._get_api_list = client.get_api_list
|
25
|
+
|
26
|
+
def _sleep(self, seconds: float) -> None:
|
27
|
+
time.sleep(seconds)
|
28
|
+
|
29
|
+
|
30
|
+
class AsyncAPIResource:
|
31
|
+
_client: AsyncIsaacus
|
32
|
+
|
33
|
+
def __init__(self, client: AsyncIsaacus) -> None:
|
34
|
+
self._client = client
|
35
|
+
self._get = client.get
|
36
|
+
self._post = client.post
|
37
|
+
self._patch = client.patch
|
38
|
+
self._put = client.put
|
39
|
+
self._delete = client.delete
|
40
|
+
self._get_api_list = client.get_api_list
|
41
|
+
|
42
|
+
async def _sleep(self, seconds: float) -> None:
|
43
|
+
await anyio.sleep(seconds)
|