Skip to content

Commit 3f6d237

Browse files
authored
Merge pull request #16 from replicate/release-please--branches--main--changes--next
release: 0.2.0
2 parents 84a6a42 + 94d17ee commit 3f6d237

20 files changed

+1457
-9
lines changed

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "0.1.0"
2+
".": "0.2.0"
33
}

.stats.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 30
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/replicate%2Freplicate-client-2088d647e7b0fd37dcf58ef48b8f01ed1a82ff797b9697ad10a7b6a5105e9e0f.yml
3-
openapi_spec_hash: 718f540e7c44501e1a8c7156ee45d595
4-
config_hash: 927b6ebc00ee115763ad69483bbf5566
1+
configured_endpoints: 35
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/replicate%2Freplicate-client-efbc8cc2d74644b213e161d3e11e0589d1cef181fb318ea02c8eb6b00f245713.yml
3+
openapi_spec_hash: 13da0c06c900b61cd98ab678e024987a
4+
config_hash: 8ef6787524fd12bfeb27f8c6acef3dca

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# Changelog
22

3+
## 0.2.0 (2025-05-07)
4+
5+
Full Changelog: [v0.1.0...v0.2.0](https://github.com/replicate/replicate-python-stainless/compare/v0.1.0...v0.2.0)
6+
7+
### Features
8+
9+
* **api:** add Files API methods ([3173e5f](https://github.com/replicate/replicate-python-stainless/commit/3173e5f61edd89ffe0b64b53fc8e8e9905e145e4))
10+
* **api:** fix bearer token which also regressed when guessing with AI ([13162be](https://github.com/replicate/replicate-python-stainless/commit/13162be9d367de29d222b86506fa921a10800665))
11+
12+
13+
### Bug Fixes
14+
15+
* **api:** fix client_settings.opts.api_key.read_env ([5a9b95c](https://github.com/replicate/replicate-python-stainless/commit/5a9b95ce89e536b539eefe0864a47784fdb0ec08))
16+
317
## 0.1.0 (2025-05-07)
418

519
Full Changelog: [v0.1.0-alpha.10...v0.1.0](https://github.com/replicate/replicate-python-stainless/compare/v0.1.0-alpha.10...v0.1.0)

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,24 @@ for prediction in first_page.results:
136136
# Remove `await` for non-async usage.
137137
```
138138

139+
## File uploads
140+
141+
Request parameters that correspond to file uploads can be passed as `bytes`, or a [`PathLike`](https://docs.python.org/3/library/os.html#os.PathLike) instance or a tuple of `(filename, contents, media type)`.
142+
143+
```python
144+
from pathlib import Path
145+
from replicate import Replicate
146+
147+
client = Replicate()
148+
149+
client.files.create(
150+
content=Path("/path/to/file"),
151+
filename="filename",
152+
)
153+
```
154+
155+
The async client uses the exact same interface. If you pass a [`PathLike`](https://docs.python.org/3/library/os.html#os.PathLike) instance, the file contents will be read asynchronously automatically.
156+
139157
## Handling errors
140158

141159
When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `replicate.APIConnectionError` is raised.

api.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,11 @@ from replicate.types.webhooks.default import SecretGetResponse
154154
Methods:
155155

156156
- <code title="get /webhooks/default/secret">client.webhooks.default.secret.<a href="./src/replicate/resources/webhooks/default/secret.py">get</a>() -> <a href="./src/replicate/types/webhooks/default/secret_get_response.py">SecretGetResponse</a></code>
157+
158+
# Files
159+
160+
Types:
161+
162+
```python
163+
from replicate.types import FileCreateResponse, FileListResponse, FileGetResponse
164+
```

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "replicate-stainless"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
description = "The official Python library for the replicate API"
55
dynamic = ["readme"]
66
license = "Apache-2.0"

src/replicate/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ def _reset_client() -> None: # type: ignore[reportUnusedFunction]
230230

231231

232232
from ._module_client import (
233+
files as files,
233234
models as models,
234235
account as account,
235236
hardware as hardware,

src/replicate/_client.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
)
3232

3333
if TYPE_CHECKING:
34-
from .resources import models, account, hardware, webhooks, trainings, collections, deployments, predictions
34+
from .resources import files, models, account, hardware, webhooks, trainings, collections, deployments, predictions
35+
from .resources.files import FilesResource, AsyncFilesResource
3536
from .resources.account import AccountResource, AsyncAccountResource
3637
from .resources.hardware import HardwareResource, AsyncHardwareResource
3738
from .resources.trainings import TrainingsResource, AsyncTrainingsResource
@@ -156,6 +157,12 @@ def webhooks(self) -> WebhooksResource:
156157

157158
return WebhooksResource(self)
158159

160+
@cached_property
161+
def files(self) -> FilesResource:
162+
from .resources.files import FilesResource
163+
164+
return FilesResource(self)
165+
159166
@cached_property
160167
def with_raw_response(self) -> ReplicateWithRawResponse:
161168
return ReplicateWithRawResponse(self)
@@ -372,6 +379,12 @@ def webhooks(self) -> AsyncWebhooksResource:
372379

373380
return AsyncWebhooksResource(self)
374381

382+
@cached_property
383+
def files(self) -> AsyncFilesResource:
384+
from .resources.files import AsyncFilesResource
385+
386+
return AsyncFilesResource(self)
387+
375388
@cached_property
376389
def with_raw_response(self) -> AsyncReplicateWithRawResponse:
377390
return AsyncReplicateWithRawResponse(self)
@@ -539,6 +552,12 @@ def webhooks(self) -> webhooks.WebhooksResourceWithRawResponse:
539552

540553
return WebhooksResourceWithRawResponse(self._client.webhooks)
541554

555+
@cached_property
556+
def files(self) -> files.FilesResourceWithRawResponse:
557+
from .resources.files import FilesResourceWithRawResponse
558+
559+
return FilesResourceWithRawResponse(self._client.files)
560+
542561

543562
class AsyncReplicateWithRawResponse:
544563
_client: AsyncReplicate
@@ -594,6 +613,12 @@ def webhooks(self) -> webhooks.AsyncWebhooksResourceWithRawResponse:
594613

595614
return AsyncWebhooksResourceWithRawResponse(self._client.webhooks)
596615

616+
@cached_property
617+
def files(self) -> files.AsyncFilesResourceWithRawResponse:
618+
from .resources.files import AsyncFilesResourceWithRawResponse
619+
620+
return AsyncFilesResourceWithRawResponse(self._client.files)
621+
597622

598623
class ReplicateWithStreamedResponse:
599624
_client: Replicate
@@ -649,6 +674,12 @@ def webhooks(self) -> webhooks.WebhooksResourceWithStreamingResponse:
649674

650675
return WebhooksResourceWithStreamingResponse(self._client.webhooks)
651676

677+
@cached_property
678+
def files(self) -> files.FilesResourceWithStreamingResponse:
679+
from .resources.files import FilesResourceWithStreamingResponse
680+
681+
return FilesResourceWithStreamingResponse(self._client.files)
682+
652683

653684
class AsyncReplicateWithStreamedResponse:
654685
_client: AsyncReplicate
@@ -704,6 +735,12 @@ def webhooks(self) -> webhooks.AsyncWebhooksResourceWithStreamingResponse:
704735

705736
return AsyncWebhooksResourceWithStreamingResponse(self._client.webhooks)
706737

738+
@cached_property
739+
def files(self) -> files.AsyncFilesResourceWithStreamingResponse:
740+
from .resources.files import AsyncFilesResourceWithStreamingResponse
741+
742+
return AsyncFilesResourceWithStreamingResponse(self._client.files)
743+
707744

708745
Client = Replicate
709746

src/replicate/_files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def assert_is_file_content(obj: object, *, key: str | None = None) -> None:
3434
if not is_file_content(obj):
3535
prefix = f"Expected entry at `{key}`" if key is not None else f"Expected file input `{obj!r}`"
3636
raise RuntimeError(
37-
f"{prefix} to be bytes, an io.IOBase instance, PathLike or a tuple but received {type(obj)} instead."
37+
f"{prefix} to be bytes, an io.IOBase instance, PathLike or a tuple but received {type(obj)} instead. See https://github.com/replicate/replicate-python-stainless/tree/main#file-uploads"
3838
) from None
3939

4040

src/replicate/_module_client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from typing_extensions import override
77

88
if TYPE_CHECKING:
9+
from .resources.files import FilesResource
910
from .resources.account import AccountResource
1011
from .resources.hardware import HardwareResource
1112
from .resources.trainings import TrainingsResource
@@ -19,6 +20,12 @@
1920
from ._utils import LazyProxy
2021

2122

23+
class FilesResourceProxy(LazyProxy["FilesResource"]):
24+
@override
25+
def __load__(self) -> FilesResource:
26+
return _load_client().files
27+
28+
2229
class ModelsResourceProxy(LazyProxy["ModelsResource"]):
2330
@override
2431
def __load__(self) -> ModelsResource:
@@ -67,6 +74,7 @@ def __load__(self) -> PredictionsResource:
6774
return _load_client().predictions
6875

6976

77+
files: FilesResource = FilesResourceProxy().__as_proxied__()
7078
models: ModelsResource = ModelsResourceProxy().__as_proxied__()
7179
account: AccountResource = AccountResourceProxy().__as_proxied__()
7280
hardware: HardwareResource = HardwareResourceProxy().__as_proxied__()

0 commit comments

Comments
 (0)