Skip to content

Commit ed55fef

Browse files
Release 0.1.2
1 parent d0785ed commit ed55fef

File tree

157 files changed

+5662
-1614
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

157 files changed

+5662
-1614
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
- name: Set up python
1111
uses: actions/setup-python@v4
1212
with:
13-
python-version: 3.7
13+
python-version: 3.8
1414
- name: Bootstrap poetry
1515
run: |
1616
curl -sSL https://install.python-poetry.org | python - -y --version 1.5.1
@@ -26,7 +26,7 @@ jobs:
2626
- name: Set up python
2727
uses: actions/setup-python@v4
2828
with:
29-
python-version: 3.7
29+
python-version: 3.8
3030
- name: Bootstrap poetry
3131
run: |
3232
curl -sSL https://install.python-poetry.org | python - -y --version 1.5.1
@@ -45,7 +45,7 @@ jobs:
4545
- name: Set up python
4646
uses: actions/setup-python@v4
4747
with:
48-
python-version: 3.7
48+
python-version: 3.8
4949
- name: Bootstrap poetry
5050
run: |
5151
curl -sSL https://install.python-poetry.org | python - -y --version 1.5.1

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ client = AsyncPolytomic(
4040
```
4141
<!-- End Async Usage -->
4242

43+
<!-- Begin Status, generated by Fern -->
44+
# Beta Status
45+
46+
This SDK is in beta, and there may be breaking changes between versions without a major
47+
version update. Therefore, we recommend pinning the package version to a specific version.
48+
This way, you can install the same version each time without breaking changes.
49+
<!-- End Status -->
50+
4351
<!-- Begin Contributing, generated by Fern -->
4452
# Contributing
4553

poetry.lock

Lines changed: 199 additions & 270 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "polytomic"
3-
version = "0.1.1"
3+
version = "0.1.2"
44
description = ""
55
readme = "README.md"
66
authors = []
@@ -9,13 +9,24 @@ packages = [
99
]
1010

1111
[tool.poetry.dependencies]
12-
python = "^3.7"
12+
python = "^3.8"
1313
httpx = ">=0.21.2"
14-
pydantic = ">= 1.9.2, < 2.5.0"
14+
pydantic = ">= 1.9.2"
15+
typing_extensions = ">= 4.0.0"
1516

1617
[tool.poetry.dev-dependencies]
17-
mypy = "0.971"
18+
mypy = "^1.8.0"
1819
pytest = "^7.4.0"
20+
pytest-asyncio = "^0.23.5"
21+
python-dateutil = "^2.9.0"
22+
23+
[tool.pytest.ini_options]
24+
testpaths = [ "tests" ]
25+
asyncio_mode = "auto"
26+
27+
[tool.mypy]
28+
plugins = ["pydantic.mypy"]
29+
1930

2031
[build-system]
2132
requires = ["poetry-core"]

src/polytomic/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
webhooks,
142142
)
143143
from .environment import PolytomicEnvironment
144+
from .version import __version__
144145

145146
__all__ = [
146147
"ActivateSyncEnvelope",
@@ -269,6 +270,7 @@
269270
"WebhookEnvelope",
270271
"WebhookListEnvelope",
271272
"WorkTaskStatus",
273+
"__version__",
272274
"bulk_sync",
273275
"connections",
274276
"events",

src/polytomic/client.py

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
# This file was auto-generated by Fern from our API Definition.
1+
# This file was auto-generated from our API Definition.
22

33
import typing
44

55
import httpx
6-
import typing_extensions
76

87
from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
98
from .environment import PolytomicEnvironment
@@ -21,21 +20,49 @@
2120

2221

2322
class Polytomic:
23+
"""
24+
Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propogate to these functions.
25+
26+
Parameters:
27+
- base_url: typing.Optional[str]. The base url to use for requests from the client.
28+
29+
- environment: PolytomicEnvironment. The environment to use for requests from the client. from .environment import PolytomicEnvironment
30+
31+
Defaults to PolytomicEnvironment.DEFAULT
32+
33+
- x_polytomic_version: typing.Optional[typing.Literal["2023-04-25"]].
34+
35+
- token: typing.Optional[typing.Union[str, typing.Callable[[], str]]].
36+
37+
- timeout: typing.Optional[float]. The timeout to be used, in seconds, for requests by default the timeout is 60 seconds, unless a custom httpx client is used, in which case a default is not set.
38+
39+
- httpx_client: typing.Optional[httpx.Client]. The httpx client to use for making requests, a preconfigured client is used by default, however this is useful should you want to pass in any custom httpx configuration.
40+
---
41+
from polytomic.client import Polytomic
42+
43+
client = Polytomic(
44+
x_polytomic_version="YOUR_X_POLYTOMIC_VERSION",
45+
token="YOUR_TOKEN",
46+
)
47+
"""
48+
2449
def __init__(
2550
self,
2651
*,
2752
base_url: typing.Optional[str] = None,
2853
environment: PolytomicEnvironment = PolytomicEnvironment.DEFAULT,
29-
x_polytomic_version: typing.Optional[typing_extensions.Literal["2023-04-25"]] = None,
54+
x_polytomic_version: typing.Optional[typing.Literal["2023-04-25"]] = None,
3055
token: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
31-
timeout: typing.Optional[float] = 60,
56+
timeout: typing.Optional[float] = None,
3257
httpx_client: typing.Optional[httpx.Client] = None
3358
):
59+
_defaulted_timeout = timeout if timeout is not None else 60 if httpx_client is None else None
3460
self._client_wrapper = SyncClientWrapper(
3561
base_url=_get_base_url(base_url=base_url, environment=environment),
3662
x_polytomic_version=x_polytomic_version,
3763
token=token,
38-
httpx_client=httpx.Client(timeout=timeout) if httpx_client is None else httpx_client,
64+
httpx_client=httpx.Client(timeout=_defaulted_timeout) if httpx_client is None else httpx_client,
65+
timeout=_defaulted_timeout,
3966
)
4067
self.bulk_sync = BulkSyncClient(client_wrapper=self._client_wrapper)
4168
self.connections = ConnectionsClient(client_wrapper=self._client_wrapper)
@@ -51,21 +78,49 @@ def __init__(
5178

5279

5380
class AsyncPolytomic:
81+
"""
82+
Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propogate to these functions.
83+
84+
Parameters:
85+
- base_url: typing.Optional[str]. The base url to use for requests from the client.
86+
87+
- environment: PolytomicEnvironment. The environment to use for requests from the client. from .environment import PolytomicEnvironment
88+
89+
Defaults to PolytomicEnvironment.DEFAULT
90+
91+
- x_polytomic_version: typing.Optional[typing.Literal["2023-04-25"]].
92+
93+
- token: typing.Optional[typing.Union[str, typing.Callable[[], str]]].
94+
95+
- timeout: typing.Optional[float]. The timeout to be used, in seconds, for requests by default the timeout is 60 seconds, unless a custom httpx client is used, in which case a default is not set.
96+
97+
- httpx_client: typing.Optional[httpx.AsyncClient]. The httpx client to use for making requests, a preconfigured client is used by default, however this is useful should you want to pass in any custom httpx configuration.
98+
---
99+
from polytomic.client import AsyncPolytomic
100+
101+
client = AsyncPolytomic(
102+
x_polytomic_version="YOUR_X_POLYTOMIC_VERSION",
103+
token="YOUR_TOKEN",
104+
)
105+
"""
106+
54107
def __init__(
55108
self,
56109
*,
57110
base_url: typing.Optional[str] = None,
58111
environment: PolytomicEnvironment = PolytomicEnvironment.DEFAULT,
59-
x_polytomic_version: typing.Optional[typing_extensions.Literal["2023-04-25"]] = None,
112+
x_polytomic_version: typing.Optional[typing.Literal["2023-04-25"]] = None,
60113
token: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
61-
timeout: typing.Optional[float] = 60,
114+
timeout: typing.Optional[float] = None,
62115
httpx_client: typing.Optional[httpx.AsyncClient] = None
63116
):
117+
_defaulted_timeout = timeout if timeout is not None else 60 if httpx_client is None else None
64118
self._client_wrapper = AsyncClientWrapper(
65119
base_url=_get_base_url(base_url=base_url, environment=environment),
66120
x_polytomic_version=x_polytomic_version,
67121
token=token,
68-
httpx_client=httpx.AsyncClient(timeout=timeout) if httpx_client is None else httpx_client,
122+
httpx_client=httpx.AsyncClient(timeout=_defaulted_timeout) if httpx_client is None else httpx_client,
123+
timeout=_defaulted_timeout,
69124
)
70125
self.bulk_sync = AsyncBulkSyncClient(client_wrapper=self._client_wrapper)
71126
self.connections = AsyncConnectionsClient(client_wrapper=self._client_wrapper)

src/polytomic/core/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,22 @@
33
from .api_error import ApiError
44
from .client_wrapper import AsyncClientWrapper, BaseClientWrapper, SyncClientWrapper
55
from .datetime_utils import serialize_datetime
6+
from .file import File, convert_file_dict_to_httpx_tuples
7+
from .http_client import AsyncHttpClient, HttpClient
68
from .jsonable_encoder import jsonable_encoder
79
from .remove_none_from_dict import remove_none_from_dict
10+
from .request_options import RequestOptions
811

912
__all__ = [
1013
"ApiError",
1114
"AsyncClientWrapper",
15+
"AsyncHttpClient",
1216
"BaseClientWrapper",
17+
"File",
18+
"HttpClient",
19+
"RequestOptions",
1320
"SyncClientWrapper",
21+
"convert_file_dict_to_httpx_tuples",
1422
"jsonable_encoder",
1523
"remove_none_from_dict",
1624
"serialize_datetime",
Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
1-
# This file was auto-generated by Fern from our API Definition.
1+
# This file was auto-generated from our API Definition.
22

33
import typing
44

55
import httpx
6-
import typing_extensions
6+
7+
from .http_client import AsyncHttpClient, HttpClient
78

89

910
class BaseClientWrapper:
1011
def __init__(
1112
self,
1213
*,
13-
x_polytomic_version: typing.Optional[typing_extensions.Literal["2023-04-25"]] = None,
14+
x_polytomic_version: typing.Optional[typing.Literal["2023-04-25"]] = None,
1415
token: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
1516
base_url: str,
17+
timeout: typing.Optional[float] = None,
1618
):
1719
self._x_polytomic_version = x_polytomic_version
1820
self._token = token
1921
self._base_url = base_url
22+
self._timeout = timeout
2023

2124
def get_headers(self) -> typing.Dict[str, str]:
2225
headers: typing.Dict[str, str] = {
2326
"X-Fern-Language": "Python",
2427
"X-Fern-SDK-Name": "polytomic",
25-
"X-Fern-SDK-Version": "0.1.1",
28+
"X-Fern-SDK-Version": "0.1.2",
2629
}
2730
if self._x_polytomic_version is not None:
2831
headers["X-Polytomic-Version"] = self._x_polytomic_version
@@ -40,28 +43,33 @@ def _get_token(self) -> typing.Optional[str]:
4043
def get_base_url(self) -> str:
4144
return self._base_url
4245

46+
def get_timeout(self) -> typing.Optional[float]:
47+
return self._timeout
48+
4349

4450
class SyncClientWrapper(BaseClientWrapper):
4551
def __init__(
4652
self,
4753
*,
48-
x_polytomic_version: typing.Optional[typing_extensions.Literal["2023-04-25"]] = None,
54+
x_polytomic_version: typing.Optional[typing.Literal["2023-04-25"]] = None,
4955
token: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
5056
base_url: str,
57+
timeout: typing.Optional[float] = None,
5158
httpx_client: httpx.Client,
5259
):
53-
super().__init__(x_polytomic_version=x_polytomic_version, token=token, base_url=base_url)
54-
self.httpx_client = httpx_client
60+
super().__init__(x_polytomic_version=x_polytomic_version, token=token, base_url=base_url, timeout=timeout)
61+
self.httpx_client = HttpClient(httpx_client=httpx_client)
5562

5663

5764
class AsyncClientWrapper(BaseClientWrapper):
5865
def __init__(
5966
self,
6067
*,
61-
x_polytomic_version: typing.Optional[typing_extensions.Literal["2023-04-25"]] = None,
68+
x_polytomic_version: typing.Optional[typing.Literal["2023-04-25"]] = None,
6269
token: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
6370
base_url: str,
71+
timeout: typing.Optional[float] = None,
6472
httpx_client: httpx.AsyncClient,
6573
):
66-
super().__init__(x_polytomic_version=x_polytomic_version, token=token, base_url=base_url)
67-
self.httpx_client = httpx_client
74+
super().__init__(x_polytomic_version=x_polytomic_version, token=token, base_url=base_url, timeout=timeout)
75+
self.httpx_client = AsyncHttpClient(httpx_client=httpx_client)

src/polytomic/core/file.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# This file was auto-generated by Fern from our API Definition.
2+
3+
import typing
4+
5+
# File typing inspired by the flexibility of types within the httpx library
6+
# https://github.com/encode/httpx/blob/master/httpx/_types.py
7+
FileContent = typing.Union[typing.IO[bytes], bytes, str]
8+
File = typing.Union[
9+
# file (or bytes)
10+
FileContent,
11+
# (filename, file (or bytes))
12+
typing.Tuple[typing.Optional[str], FileContent],
13+
# (filename, file (or bytes), content_type)
14+
typing.Tuple[typing.Optional[str], FileContent, typing.Optional[str]],
15+
# (filename, file (or bytes), content_type, headers)
16+
typing.Tuple[typing.Optional[str], FileContent, typing.Optional[str], typing.Mapping[str, str]],
17+
]
18+
19+
20+
def convert_file_dict_to_httpx_tuples(
21+
d: typing.Dict[str, typing.Union[File, typing.List[File]]]
22+
) -> typing.List[typing.Tuple[str, File]]:
23+
"""
24+
The format we use is a list of tuples, where the first element is the
25+
name of the file and the second is the file object. Typically HTTPX wants
26+
a dict, but to be able to send lists of files, you have to use the list
27+
approach (which also works for non-lists)
28+
https://github.com/encode/httpx/pull/1032
29+
"""
30+
31+
httpx_tuples = []
32+
for key, file_like in d.items():
33+
if isinstance(file_like, list):
34+
for file_like_item in file_like:
35+
httpx_tuples.append((key, file_like_item))
36+
else:
37+
httpx_tuples.append((key, file_like))
38+
return httpx_tuples

0 commit comments

Comments
 (0)