Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.1.0"
".": "0.2.0"
}
8 changes: 4 additions & 4 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 30
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/replicate%2Freplicate-client-2088d647e7b0fd37dcf58ef48b8f01ed1a82ff797b9697ad10a7b6a5105e9e0f.yml
openapi_spec_hash: 718f540e7c44501e1a8c7156ee45d595
config_hash: 927b6ebc00ee115763ad69483bbf5566
configured_endpoints: 35
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/replicate%2Freplicate-client-efbc8cc2d74644b213e161d3e11e0589d1cef181fb318ea02c8eb6b00f245713.yml
openapi_spec_hash: 13da0c06c900b61cd98ab678e024987a
config_hash: 8ef6787524fd12bfeb27f8c6acef3dca
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## 0.2.0 (2025-05-07)

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

### Features

* **api:** add Files API methods ([3173e5f](https://github.com/replicate/replicate-python-stainless/commit/3173e5f61edd89ffe0b64b53fc8e8e9905e145e4))
* **api:** fix bearer token which also regressed when guessing with AI ([13162be](https://github.com/replicate/replicate-python-stainless/commit/13162be9d367de29d222b86506fa921a10800665))


### Bug Fixes

* **api:** fix client_settings.opts.api_key.read_env ([5a9b95c](https://github.com/replicate/replicate-python-stainless/commit/5a9b95ce89e536b539eefe0864a47784fdb0ec08))

## 0.1.0 (2025-05-07)

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)
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,24 @@ for prediction in first_page.results:
# Remove `await` for non-async usage.
```

## File uploads

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)`.

```python
from pathlib import Path
from replicate import Replicate

client = Replicate()

client.files.create(
content=Path("/path/to/file"),
filename="filename",
)
```

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.

## Handling errors

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.
Expand Down
8 changes: 8 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,11 @@ from replicate.types.webhooks.default import SecretGetResponse
Methods:

- <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>

# Files

Types:

```python
from replicate.types import FileCreateResponse, FileListResponse, FileGetResponse
```
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "replicate-stainless"
version = "0.1.0"
version = "0.2.0"
description = "The official Python library for the replicate API"
dynamic = ["readme"]
license = "Apache-2.0"
Expand Down
1 change: 1 addition & 0 deletions src/replicate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ def _reset_client() -> None: # type: ignore[reportUnusedFunction]


from ._module_client import (
files as files,
models as models,
account as account,
hardware as hardware,
Expand Down
39 changes: 38 additions & 1 deletion src/replicate/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
)

if TYPE_CHECKING:
from .resources import models, account, hardware, webhooks, trainings, collections, deployments, predictions
from .resources import files, models, account, hardware, webhooks, trainings, collections, deployments, predictions
from .resources.files import FilesResource, AsyncFilesResource
from .resources.account import AccountResource, AsyncAccountResource
from .resources.hardware import HardwareResource, AsyncHardwareResource
from .resources.trainings import TrainingsResource, AsyncTrainingsResource
Expand Down Expand Up @@ -156,6 +157,12 @@ def webhooks(self) -> WebhooksResource:

return WebhooksResource(self)

@cached_property
def files(self) -> FilesResource:
from .resources.files import FilesResource

return FilesResource(self)

@cached_property
def with_raw_response(self) -> ReplicateWithRawResponse:
return ReplicateWithRawResponse(self)
Expand Down Expand Up @@ -372,6 +379,12 @@ def webhooks(self) -> AsyncWebhooksResource:

return AsyncWebhooksResource(self)

@cached_property
def files(self) -> AsyncFilesResource:
from .resources.files import AsyncFilesResource

return AsyncFilesResource(self)

@cached_property
def with_raw_response(self) -> AsyncReplicateWithRawResponse:
return AsyncReplicateWithRawResponse(self)
Expand Down Expand Up @@ -539,6 +552,12 @@ def webhooks(self) -> webhooks.WebhooksResourceWithRawResponse:

return WebhooksResourceWithRawResponse(self._client.webhooks)

@cached_property
def files(self) -> files.FilesResourceWithRawResponse:
from .resources.files import FilesResourceWithRawResponse

return FilesResourceWithRawResponse(self._client.files)


class AsyncReplicateWithRawResponse:
_client: AsyncReplicate
Expand Down Expand Up @@ -594,6 +613,12 @@ def webhooks(self) -> webhooks.AsyncWebhooksResourceWithRawResponse:

return AsyncWebhooksResourceWithRawResponse(self._client.webhooks)

@cached_property
def files(self) -> files.AsyncFilesResourceWithRawResponse:
from .resources.files import AsyncFilesResourceWithRawResponse

return AsyncFilesResourceWithRawResponse(self._client.files)


class ReplicateWithStreamedResponse:
_client: Replicate
Expand Down Expand Up @@ -649,6 +674,12 @@ def webhooks(self) -> webhooks.WebhooksResourceWithStreamingResponse:

return WebhooksResourceWithStreamingResponse(self._client.webhooks)

@cached_property
def files(self) -> files.FilesResourceWithStreamingResponse:
from .resources.files import FilesResourceWithStreamingResponse

return FilesResourceWithStreamingResponse(self._client.files)


class AsyncReplicateWithStreamedResponse:
_client: AsyncReplicate
Expand Down Expand Up @@ -704,6 +735,12 @@ def webhooks(self) -> webhooks.AsyncWebhooksResourceWithStreamingResponse:

return AsyncWebhooksResourceWithStreamingResponse(self._client.webhooks)

@cached_property
def files(self) -> files.AsyncFilesResourceWithStreamingResponse:
from .resources.files import AsyncFilesResourceWithStreamingResponse

return AsyncFilesResourceWithStreamingResponse(self._client.files)


Client = Replicate

Expand Down
2 changes: 1 addition & 1 deletion src/replicate/_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def assert_is_file_content(obj: object, *, key: str | None = None) -> None:
if not is_file_content(obj):
prefix = f"Expected entry at `{key}`" if key is not None else f"Expected file input `{obj!r}`"
raise RuntimeError(
f"{prefix} to be bytes, an io.IOBase instance, PathLike or a tuple but received {type(obj)} instead."
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"
) from None


Expand Down
8 changes: 8 additions & 0 deletions src/replicate/_module_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing_extensions import override

if TYPE_CHECKING:
from .resources.files import FilesResource
from .resources.account import AccountResource
from .resources.hardware import HardwareResource
from .resources.trainings import TrainingsResource
Expand All @@ -19,6 +20,12 @@
from ._utils import LazyProxy


class FilesResourceProxy(LazyProxy["FilesResource"]):
@override
def __load__(self) -> FilesResource:
return _load_client().files


class ModelsResourceProxy(LazyProxy["ModelsResource"]):
@override
def __load__(self) -> ModelsResource:
Expand Down Expand Up @@ -67,6 +74,7 @@ def __load__(self) -> PredictionsResource:
return _load_client().predictions


files: FilesResource = FilesResourceProxy().__as_proxied__()
models: ModelsResource = ModelsResourceProxy().__as_proxied__()
account: AccountResource = AccountResourceProxy().__as_proxied__()
hardware: HardwareResource = HardwareResourceProxy().__as_proxied__()
Expand Down
2 changes: 1 addition & 1 deletion src/replicate/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

__title__ = "replicate"
__version__ = "0.1.0" # x-release-please-version
__version__ = "0.2.0" # x-release-please-version
14 changes: 14 additions & 0 deletions src/replicate/resources/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from .files import (
FilesResource,
AsyncFilesResource,
FilesResourceWithRawResponse,
AsyncFilesResourceWithRawResponse,
FilesResourceWithStreamingResponse,
AsyncFilesResourceWithStreamingResponse,
)
from .models import (
ModelsResource,
AsyncModelsResource,
Expand Down Expand Up @@ -114,4 +122,10 @@
"AsyncWebhooksResourceWithRawResponse",
"WebhooksResourceWithStreamingResponse",
"AsyncWebhooksResourceWithStreamingResponse",
"FilesResource",
"AsyncFilesResource",
"FilesResourceWithRawResponse",
"AsyncFilesResourceWithRawResponse",
"FilesResourceWithStreamingResponse",
"AsyncFilesResourceWithStreamingResponse",
]
Loading