Skip to content

Commit 442fe71

Browse files
authored
Merge pull request #2 from replicate/release-please--branches--main--changes--next
release: 0.1.0-alpha.1
2 parents 05cc653 + 2d612eb commit 442fe71

File tree

12 files changed

+394
-10
lines changed

12 files changed

+394
-10
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ jobs:
1212
lint:
1313
name: lint
1414
runs-on: ubuntu-latest
15-
1615
steps:
1716
- uses: actions/checkout@v4
1817

@@ -33,7 +32,6 @@ jobs:
3332
test:
3433
name: test
3534
runs-on: ubuntu-latest
36-
3735
steps:
3836
- uses: actions/checkout@v4
3937

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Full Changelog: [v0.0.1-alpha.0...v0.1.0-alpha.1](https://github.com/replicate/r
1212
* **api:** manual updates ([#22](https://github.com/replicate/replicate-python-stainless/issues/22)) ([573bbb3](https://github.com/replicate/replicate-python-stainless/commit/573bbb3fa46346d1703d076daa85541b947c27a2))
1313
* **api:** manual updates ([#23](https://github.com/replicate/replicate-python-stainless/issues/23)) ([7962ea7](https://github.com/replicate/replicate-python-stainless/commit/7962ea7f5c5e3c8f253f66b8f13eadc9927fae7d))
1414
* **api:** manual updates ([#24](https://github.com/replicate/replicate-python-stainless/issues/24)) ([d31ada3](https://github.com/replicate/replicate-python-stainless/commit/d31ada3ab8d19413c1ca55535f1788ae9b5d443d))
15+
* **api:** re-enable module client ([4f83487](https://github.com/replicate/replicate-python-stainless/commit/4f8348757c683395344c8dea1adb75af941f67e1))
1516
* **api:** update pagination configs ([#25](https://github.com/replicate/replicate-python-stainless/issues/25)) ([8a2cc9f](https://github.com/replicate/replicate-python-stainless/commit/8a2cc9f87cf6edb18ad906bbb0b82372b4b82099))
1617
* **api:** update via SDK Studio ([3bf3415](https://github.com/replicate/replicate-python-stainless/commit/3bf3415ce21bb9fc55f80809239e58d64f34fb61))
1718
* **api:** update via SDK Studio ([aafbabf](https://github.com/replicate/replicate-python-stainless/commit/aafbabfdbac1c43a547f277769c82585c616a3b4))
@@ -27,16 +28,27 @@ Full Changelog: [v0.0.1-alpha.0...v0.1.0-alpha.1](https://github.com/replicate/r
2728

2829
* **ci:** ensure pip is always available ([#14](https://github.com/replicate/replicate-python-stainless/issues/14)) ([d4f8f18](https://github.com/replicate/replicate-python-stainless/commit/d4f8f18d0d369dedc9e09551e87483f8f1787fd7))
2930
* **ci:** remove publishing patch ([#15](https://github.com/replicate/replicate-python-stainless/issues/15)) ([002b758](https://github.com/replicate/replicate-python-stainless/commit/002b7581debae5b5bc97ec24cc0cea129100dfde))
31+
* **perf:** optimize some hot paths ([d14ecac](https://github.com/replicate/replicate-python-stainless/commit/d14ecaca89424e6aac85827ae0efd5e6da7d8c03))
32+
* **perf:** skip traversing types for NotGiven values ([35ce48c](https://github.com/replicate/replicate-python-stainless/commit/35ce48c5e3e93605a70f90270487e02e121561b5))
33+
* pluralize `list` response variables ([#26](https://github.com/replicate/replicate-python-stainless/issues/26)) ([19f7bd9](https://github.com/replicate/replicate-python-stainless/commit/19f7bd9fe7d8422ae7abe6d5070e29f4a572a1d7))
3034
* **types:** handle more discriminated union shapes ([#13](https://github.com/replicate/replicate-python-stainless/issues/13)) ([4ca1ca8](https://github.com/replicate/replicate-python-stainless/commit/4ca1ca8606fef7bc40144c1ae6246784ed754687))
3135

3236

3337
### Chores
3438

39+
* **client:** minor internal fixes ([21d9c7b](https://github.com/replicate/replicate-python-stainless/commit/21d9c7be7c1c5cb93466b6f6d16804a7d38701b2))
3540
* fix typos ([#18](https://github.com/replicate/replicate-python-stainless/issues/18)) ([54d4e6d](https://github.com/replicate/replicate-python-stainless/commit/54d4e6da6a757ad6e5c899b79018ca39eed2a124))
3641
* go live ([#1](https://github.com/replicate/replicate-python-stainless/issues/1)) ([bd9a84a](https://github.com/replicate/replicate-python-stainless/commit/bd9a84ae91a2c72fa49182f9ff8ea0b78e7cc343))
3742
* **internal:** bump rye to 0.44.0 ([#12](https://github.com/replicate/replicate-python-stainless/issues/12)) ([c9d2593](https://github.com/replicate/replicate-python-stainless/commit/c9d2593f4e9d324c12e2ca323563a317d0ea1751))
3843
* **internal:** codegen related update ([#11](https://github.com/replicate/replicate-python-stainless/issues/11)) ([41c787d](https://github.com/replicate/replicate-python-stainless/commit/41c787d2c196d59c48ec3056d93dd48bf530de72))
44+
* **internal:** expand CI branch coverage ([183a5dc](https://github.com/replicate/replicate-python-stainless/commit/183a5dc798f30ff70e7e96ecb3b5c8ade704af6a))
45+
* **internal:** fix module client tests ([fc9ac15](https://github.com/replicate/replicate-python-stainless/commit/fc9ac15ad5580b72719da024d95e067316f04ef2))
46+
* **internal:** reduce CI branch coverage ([2c61820](https://github.com/replicate/replicate-python-stainless/commit/2c6182009bbee43f3995be0844983c18e4b147fb))
3947
* **internal:** remove extra empty newlines ([#10](https://github.com/replicate/replicate-python-stainless/issues/10)) ([1c63514](https://github.com/replicate/replicate-python-stainless/commit/1c635145a8a70f3cb0ea432387f72eafa64ca5f6))
48+
* **internal:** remove trailing character ([#27](https://github.com/replicate/replicate-python-stainless/issues/27)) ([0a6e3f2](https://github.com/replicate/replicate-python-stainless/commit/0a6e3f29ddeecd0267c57536cf0fa07218c18d03))
49+
* **internal:** slight transform perf improvement ([#28](https://github.com/replicate/replicate-python-stainless/issues/28)) ([da30360](https://github.com/replicate/replicate-python-stainless/commit/da303609abb6a7d069b4e35036f68bae7b009cb2))
50+
* **internal:** update pyright settings ([65494e5](https://github.com/replicate/replicate-python-stainless/commit/65494e5b623b3d2cf248b6da88c7f3e50160dc94))
4051
* **internal:** updates ([b7424d7](https://github.com/replicate/replicate-python-stainless/commit/b7424d7cc1c9fa440b58fa9e51331f3c77fbd83d))
4152
* remove custom code ([31aa7ed](https://github.com/replicate/replicate-python-stainless/commit/31aa7edc04d5c9f408c06e4051c0ba343b9761ac))
53+
* sync repo ([9a71c71](https://github.com/replicate/replicate-python-stainless/commit/9a71c71fd94f1e216398c616dc6c24e0eff10c89))
4254
* update SDK settings ([#3](https://github.com/replicate/replicate-python-stainless/issues/3)) ([27b5f18](https://github.com/replicate/replicate-python-stainless/commit/27b5f1897b823349b29dbc82b1f6742d5d704c9e))

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ client = ReplicateClient(
3333
), # This is the default and can be omitted
3434
)
3535

36-
account = client.accounts.list()
37-
print(account.type)
36+
accounts = client.accounts.list()
37+
print(accounts.type)
3838
```
3939

4040
While you can provide a `bearer_token` keyword argument,
@@ -59,8 +59,8 @@ client = AsyncReplicateClient(
5959

6060

6161
async def main() -> None:
62-
account = await client.accounts.list()
63-
print(account.type)
62+
accounts = await client.accounts.list()
63+
print(accounts.type)
6464

6565

6666
asyncio.run(main())

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ exclude = [
147147
]
148148

149149
reportImplicitOverride = true
150+
reportOverlappingOverload = false
150151

151152
reportImportCycles = false
152153
reportPrivateUsage = false

src/replicate/__init__.py

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

3+
from __future__ import annotations
4+
5+
from typing_extensions import override
6+
37
from . import types
48
from ._types import NOT_GIVEN, Omit, NoneType, NotGiven, Transport, ProxiesTypes
59
from ._utils import file_from_path
@@ -92,3 +96,146 @@
9296
except (TypeError, AttributeError):
9397
# Some of our exported symbols are builtins which we can't set attributes for.
9498
pass
99+
100+
# ------ Module level client ------
101+
import typing as _t
102+
103+
import httpx as _httpx
104+
105+
from ._base_client import DEFAULT_TIMEOUT, DEFAULT_MAX_RETRIES
106+
107+
bearer_token: str | None = None
108+
109+
base_url: str | _httpx.URL | None = None
110+
111+
timeout: float | Timeout | None = DEFAULT_TIMEOUT
112+
113+
max_retries: int = DEFAULT_MAX_RETRIES
114+
115+
default_headers: _t.Mapping[str, str] | None = None
116+
117+
default_query: _t.Mapping[str, object] | None = None
118+
119+
http_client: _httpx.Client | None = None
120+
121+
122+
class _ModuleClient(ReplicateClient):
123+
# Note: we have to use type: ignores here as overriding class members
124+
# with properties is technically unsafe but it is fine for our use case
125+
126+
@property # type: ignore
127+
@override
128+
def bearer_token(self) -> str | None:
129+
return bearer_token
130+
131+
@bearer_token.setter # type: ignore
132+
def bearer_token(self, value: str | None) -> None: # type: ignore
133+
global bearer_token
134+
135+
bearer_token = value
136+
137+
@property
138+
@override
139+
def base_url(self) -> _httpx.URL:
140+
if base_url is not None:
141+
return _httpx.URL(base_url)
142+
143+
return super().base_url
144+
145+
@base_url.setter
146+
def base_url(self, url: _httpx.URL | str) -> None:
147+
super().base_url = url # type: ignore[misc]
148+
149+
@property # type: ignore
150+
@override
151+
def timeout(self) -> float | Timeout | None:
152+
return timeout
153+
154+
@timeout.setter # type: ignore
155+
def timeout(self, value: float | Timeout | None) -> None: # type: ignore
156+
global timeout
157+
158+
timeout = value
159+
160+
@property # type: ignore
161+
@override
162+
def max_retries(self) -> int:
163+
return max_retries
164+
165+
@max_retries.setter # type: ignore
166+
def max_retries(self, value: int) -> None: # type: ignore
167+
global max_retries
168+
169+
max_retries = value
170+
171+
@property # type: ignore
172+
@override
173+
def _custom_headers(self) -> _t.Mapping[str, str] | None:
174+
return default_headers
175+
176+
@_custom_headers.setter # type: ignore
177+
def _custom_headers(self, value: _t.Mapping[str, str] | None) -> None: # type: ignore
178+
global default_headers
179+
180+
default_headers = value
181+
182+
@property # type: ignore
183+
@override
184+
def _custom_query(self) -> _t.Mapping[str, object] | None:
185+
return default_query
186+
187+
@_custom_query.setter # type: ignore
188+
def _custom_query(self, value: _t.Mapping[str, object] | None) -> None: # type: ignore
189+
global default_query
190+
191+
default_query = value
192+
193+
@property # type: ignore
194+
@override
195+
def _client(self) -> _httpx.Client:
196+
return http_client or super()._client
197+
198+
@_client.setter # type: ignore
199+
def _client(self, value: _httpx.Client) -> None: # type: ignore
200+
global http_client
201+
202+
http_client = value
203+
204+
205+
_client: ReplicateClient | None = None
206+
207+
208+
def _load_client() -> ReplicateClient: # type: ignore[reportUnusedFunction]
209+
global _client
210+
211+
if _client is None:
212+
_client = _ModuleClient(
213+
bearer_token=bearer_token,
214+
base_url=base_url,
215+
timeout=timeout,
216+
max_retries=max_retries,
217+
default_headers=default_headers,
218+
default_query=default_query,
219+
http_client=http_client,
220+
)
221+
return _client
222+
223+
return _client
224+
225+
226+
def _reset_client() -> None: # type: ignore[reportUnusedFunction]
227+
global _client
228+
229+
_client = None
230+
231+
232+
from ._module_client import (
233+
models as models,
234+
accounts as accounts,
235+
hardware as hardware,
236+
webhooks as webhooks,
237+
trainings as trainings,
238+
collections as collections,
239+
deployments as deployments,
240+
predictions as predictions,
241+
)

src/replicate/_base_client.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,8 @@ def _build_headers(self, options: FinalRequestOptions, *, retries_taken: int = 0
409409

410410
idempotency_header = self._idempotency_header
411411
if idempotency_header and options.method.lower() != "get" and idempotency_header not in headers:
412-
headers[idempotency_header] = options.idempotency_key or self._idempotency_key()
412+
options.idempotency_key = options.idempotency_key or self._idempotency_key()
413+
headers[idempotency_header] = options.idempotency_key
413414

414415
# Don't set these headers if they were already set or removed by the caller. We check
415416
# `custom_headers`, which can contain `Omit()`, instead of `headers` to account for the removal case.
@@ -943,6 +944,10 @@ def _request(
943944
request = self._build_request(options, retries_taken=retries_taken)
944945
self._prepare_request(request)
945946

947+
if options.idempotency_key:
948+
# ensure the idempotency key is reused between requests
949+
input_options.idempotency_key = options.idempotency_key
950+
946951
kwargs: HttpxSendArgs = {}
947952
if self.custom_auth is not None:
948953
kwargs["auth"] = self.custom_auth
@@ -1475,6 +1480,10 @@ async def _request(
14751480
request = self._build_request(options, retries_taken=retries_taken)
14761481
await self._prepare_request(request)
14771482

1483+
if options.idempotency_key:
1484+
# ensure the idempotency key is reused between requests
1485+
input_options.idempotency_key = options.idempotency_key
1486+
14781487
kwargs: HttpxSendArgs = {}
14791488
if self.custom_auth is not None:
14801489
kwargs["auth"] = self.custom_auth

src/replicate/_module_client.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from typing_extensions import override
4+
5+
from . import resources, _load_client
6+
from ._utils import LazyProxy
7+
8+
9+
class ModelsResourceProxy(LazyProxy[resources.ModelsResource]):
10+
@override
11+
def __load__(self) -> resources.ModelsResource:
12+
return _load_client().models
13+
14+
15+
class HardwareResourceProxy(LazyProxy[resources.HardwareResource]):
16+
@override
17+
def __load__(self) -> resources.HardwareResource:
18+
return _load_client().hardware
19+
20+
21+
class AccountsResourceProxy(LazyProxy[resources.AccountsResource]):
22+
@override
23+
def __load__(self) -> resources.AccountsResource:
24+
return _load_client().accounts
25+
26+
27+
class WebhooksResourceProxy(LazyProxy[resources.WebhooksResource]):
28+
@override
29+
def __load__(self) -> resources.WebhooksResource:
30+
return _load_client().webhooks
31+
32+
33+
class TrainingsResourceProxy(LazyProxy[resources.TrainingsResource]):
34+
@override
35+
def __load__(self) -> resources.TrainingsResource:
36+
return _load_client().trainings
37+
38+
39+
class CollectionsResourceProxy(LazyProxy[resources.CollectionsResource]):
40+
@override
41+
def __load__(self) -> resources.CollectionsResource:
42+
return _load_client().collections
43+
44+
45+
class DeploymentsResourceProxy(LazyProxy[resources.DeploymentsResource]):
46+
@override
47+
def __load__(self) -> resources.DeploymentsResource:
48+
return _load_client().deployments
49+
50+
51+
class PredictionsResourceProxy(LazyProxy[resources.PredictionsResource]):
52+
@override
53+
def __load__(self) -> resources.PredictionsResource:
54+
return _load_client().predictions
55+
56+
57+
models: resources.ModelsResource = ModelsResourceProxy().__as_proxied__()
58+
hardware: resources.HardwareResource = HardwareResourceProxy().__as_proxied__()
59+
accounts: resources.AccountsResource = AccountsResourceProxy().__as_proxied__()
60+
webhooks: resources.WebhooksResource = WebhooksResourceProxy().__as_proxied__()
61+
trainings: resources.TrainingsResource = TrainingsResourceProxy().__as_proxied__()
62+
collections: resources.CollectionsResource = CollectionsResourceProxy().__as_proxied__()
63+
deployments: resources.DeploymentsResource = DeploymentsResourceProxy().__as_proxied__()
64+
predictions: resources.PredictionsResource = PredictionsResourceProxy().__as_proxied__()

0 commit comments

Comments
 (0)