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 @@
{
".": "2.0.0-alpha.4"
".": "2.0.0-alpha.5"
}
4 changes: 2 additions & 2 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 35
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/replicate%2Freplicate-client-12e7ef40109b6b34f1471a638d09b79f005c8dbf7e1a8aeca9db7e37a334e8eb.yml
openapi_spec_hash: 10b0fc9094dac5d51f46bbdd5fe3de32
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/replicate%2Freplicate-client-f5aff38eef8d7b245a7af062bf02920ae75e5b9b3dc822416aeb48966c2c6874.yml
openapi_spec_hash: c0a966beaf5ae95c6bdddd4a933bd4aa
config_hash: 12536d2bf978a995771d076a4647c17d
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# Changelog

## 2.0.0-alpha.5 (2025-06-25)

Full Changelog: [v2.0.0-alpha.4...v2.0.0-alpha.5](https://github.com/replicate/replicate-python-stainless/compare/v2.0.0-alpha.4...v2.0.0-alpha.5)

### Features

* **api:** api update ([6e667da](https://github.com/replicate/replicate-python-stainless/commit/6e667da6c2e80add847e612bbd08db1c865793d7))
* **api:** api update ([0a187a9](https://github.com/replicate/replicate-python-stainless/commit/0a187a9ba906c0bc5c4e658883266276fc357665))
* **api:** api update ([edb14b6](https://github.com/replicate/replicate-python-stainless/commit/edb14b65c61203c2e42a1accd384e7b456e33448))
* **client:** add support for aiohttp ([c802a30](https://github.com/replicate/replicate-python-stainless/commit/c802a30a0569cb25eb700ff5501c5a87291ef4b0))


### Chores

* **tests:** skip some failing tests on the latest python versions ([d331b72](https://github.com/replicate/replicate-python-stainless/commit/d331b72364eaed6f935f9b23fdc776303ebf57a6))


### Documentation

* **client:** fix httpx.Timeout documentation reference ([d17c345](https://github.com/replicate/replicate-python-stainless/commit/d17c3454afaa0ae0b022f468515e8478e5ba6568))

## 2.0.0-alpha.4 (2025-06-18)

Full Changelog: [v2.0.0-alpha.3...v2.0.0-alpha.4](https://github.com/replicate/replicate-python-stainless/compare/v2.0.0-alpha.3...v2.0.0-alpha.4)
Expand Down
38 changes: 37 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,42 @@ asyncio.run(main())

Functionality between the synchronous and asynchronous clients is otherwise identical.

### With aiohttp

By default, the async client uses `httpx` for HTTP requests. However, for improved concurrency performance you may also use `aiohttp` as the HTTP backend.

You can enable this by installing `aiohttp`:

```sh
# install from PyPI
pip install --pre replicate[aiohttp]
```

Then you can enable it by instantiating the client with `http_client=DefaultAioHttpClient()`:

```python
import os
import asyncio
from replicate import DefaultAioHttpClient
from replicate import AsyncReplicate


async def main() -> None:
async with AsyncReplicate(
bearer_token=os.environ.get(
"REPLICATE_API_TOKEN"
), # This is the default and can be omitted
http_client=DefaultAioHttpClient(),
) as replicate:
prediction = await replicate.predictions.get(
prediction_id="gm3qorzdhgbfurvjtvhg6dckhu",
)
print(prediction.id)


asyncio.run(main())
```

## Using types

Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typing.html#typing.TypedDict). Responses are [Pydantic models](https://docs.pydantic.dev) which also provide helper methods for things like:
Expand Down Expand Up @@ -228,7 +264,7 @@ replicate.with_options(max_retries=5).predictions.create(
### Timeouts

By default requests time out after 1 minute. You can configure this with a `timeout` option,
which accepts a float or an [`httpx.Timeout`](https://www.python-httpx.org/advanced/#fine-tuning-the-configuration) object:
which accepts a float or an [`httpx.Timeout`](https://www.python-httpx.org/advanced/timeouts/#fine-tuning-the-configuration) object:

```python
from replicate import Replicate
Expand Down
6 changes: 3 additions & 3 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ Methods:
Types:

```python
from replicate.types import ModelListResponse
from replicate.types import ModelListResponse, ModelGetResponse, ModelSearchResponse
```

Methods:

- <code title="post /models">replicate.models.<a href="./src/replicate/resources/models/models.py">create</a>(\*\*<a href="src/replicate/types/model_create_params.py">params</a>) -> None</code>
- <code title="get /models">replicate.models.<a href="./src/replicate/resources/models/models.py">list</a>() -> <a href="./src/replicate/types/model_list_response.py">SyncCursorURLPage[ModelListResponse]</a></code>
- <code title="delete /models/{model_owner}/{model_name}">replicate.models.<a href="./src/replicate/resources/models/models.py">delete</a>(\*, model_owner, model_name) -> None</code>
- <code title="get /models/{model_owner}/{model_name}">replicate.models.<a href="./src/replicate/resources/models/models.py">get</a>(\*, model_owner, model_name) -> None</code>
- <code title="query /models">replicate.models.<a href="./src/replicate/resources/models/models.py">search</a>(\*\*<a href="src/replicate/types/model_search_params.py">params</a>) -> None</code>
- <code title="get /models/{model_owner}/{model_name}">replicate.models.<a href="./src/replicate/resources/models/models.py">get</a>(\*, model_owner, model_name) -> <a href="./src/replicate/types/model_get_response.py">ModelGetResponse</a></code>
- <code title="query /models">replicate.models.<a href="./src/replicate/resources/models/models.py">search</a>(\*\*<a href="src/replicate/types/model_search_params.py">params</a>) -> <a href="./src/replicate/types/model_search_response.py">SyncCursorURLPage[ModelSearchResponse]</a></code>

## Examples

Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "replicate"
version = "2.0.0-alpha.4"
version = "2.0.0-alpha.5"
description = "The official Python library for the replicate API"
dynamic = ["readme"]
license = "Apache-2.0"
Expand Down Expand Up @@ -37,6 +37,8 @@ classifiers = [
Homepage = "https://github.com/replicate/replicate-python-stainless"
Repository = "https://github.com/replicate/replicate-python-stainless"

[project.optional-dependencies]
aiohttp = ["aiohttp", "httpx_aiohttp>=0.1.6"]

[tool.rye]
managed = true
Expand Down
27 changes: 27 additions & 0 deletions requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,24 @@
# universal: false

-e file:.
aiohappyeyeballs==2.6.1
# via aiohttp
aiohttp==3.12.8
# via httpx-aiohttp
# via replicate
aiosignal==1.3.2
# via aiohttp
annotated-types==0.6.0
# via pydantic
anyio==4.4.0
# via httpx
# via replicate
argcomplete==3.1.2
# via nox
async-timeout==5.0.1
# via aiohttp
attrs==25.3.0
# via aiohttp
certifi==2023.7.22
# via httpcore
# via httpx
Expand All @@ -34,23 +45,33 @@ execnet==2.1.1
# via pytest-xdist
filelock==3.12.4
# via virtualenv
frozenlist==1.6.2
# via aiohttp
# via aiosignal
h11==0.14.0
# via httpcore
httpcore==1.0.2
# via httpx
httpx==0.28.1
# via httpx-aiohttp
# via replicate
# via respx
httpx-aiohttp==0.1.6
# via replicate
idna==3.4
# via anyio
# via httpx
# via yarl
importlib-metadata==7.0.0
iniconfig==2.0.0
# via pytest
markdown-it-py==3.0.0
# via rich
mdurl==0.1.2
# via markdown-it-py
multidict==6.4.4
# via aiohttp
# via yarl
mypy==1.14.1
mypy-extensions==1.0.0
# via mypy
Expand All @@ -65,6 +86,9 @@ platformdirs==3.11.0
# via virtualenv
pluggy==1.5.0
# via pytest
propcache==0.3.1
# via aiohttp
# via yarl
pydantic==2.10.3
# via replicate
pydantic-core==2.27.1
Expand Down Expand Up @@ -97,12 +121,15 @@ tomli==2.0.2
# via pytest
typing-extensions==4.12.2
# via anyio
# via multidict
# via mypy
# via pydantic
# via pydantic-core
# via pyright
# via replicate
virtualenv==20.24.5
# via nox
yarl==1.20.0
# via aiohttp
zipp==3.17.0
# via importlib-metadata
27 changes: 27 additions & 0 deletions requirements.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,51 @@
# universal: false

-e file:.
aiohappyeyeballs==2.6.1
# via aiohttp
aiohttp==3.12.8
# via httpx-aiohttp
# via replicate
aiosignal==1.3.2
# via aiohttp
annotated-types==0.6.0
# via pydantic
anyio==4.4.0
# via httpx
# via replicate
async-timeout==5.0.1
# via aiohttp
attrs==25.3.0
# via aiohttp
certifi==2023.7.22
# via httpcore
# via httpx
distro==1.8.0
# via replicate
exceptiongroup==1.2.2
# via anyio
frozenlist==1.6.2
# via aiohttp
# via aiosignal
h11==0.14.0
# via httpcore
httpcore==1.0.2
# via httpx
httpx==0.28.1
# via httpx-aiohttp
# via replicate
httpx-aiohttp==0.1.6
# via replicate
idna==3.4
# via anyio
# via httpx
# via yarl
multidict==6.4.4
# via aiohttp
# via yarl
propcache==0.3.1
# via aiohttp
# via yarl
pydantic==2.10.3
# via replicate
pydantic-core==2.27.1
Expand All @@ -40,6 +64,9 @@ sniffio==1.3.0
# via replicate
typing-extensions==4.12.2
# via anyio
# via multidict
# via pydantic
# via pydantic-core
# via replicate
yarl==1.20.0
# via aiohttp
3 changes: 2 additions & 1 deletion src/replicate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
APIResponseValidationError,
)
from .lib._models import Model as Model, Version as Version, ModelVersionIdentifier as ModelVersionIdentifier
from ._base_client import DefaultHttpxClient, DefaultAsyncHttpxClient
from ._base_client import DefaultHttpxClient, DefaultAioHttpClient, DefaultAsyncHttpxClient
from ._utils._logs import setup_logging as _setup_logging

__all__ = [
Expand Down Expand Up @@ -83,6 +83,7 @@
"DEFAULT_CONNECTION_LIMITS",
"DefaultHttpxClient",
"DefaultAsyncHttpxClient",
"DefaultAioHttpClient",
"FileOutput",
"AsyncFileOutput",
"Model",
Expand Down
22 changes: 22 additions & 0 deletions src/replicate/_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1303,6 +1303,24 @@ def __init__(self, **kwargs: Any) -> None:
super().__init__(**kwargs)


try:
import httpx_aiohttp
except ImportError:

class _DefaultAioHttpClient(httpx.AsyncClient):
def __init__(self, **_kwargs: Any) -> None:
raise RuntimeError("To use the aiohttp client you must have installed the package with the `aiohttp` extra")
else:

class _DefaultAioHttpClient(httpx_aiohttp.HttpxAiohttpClient): # type: ignore
def __init__(self, **kwargs: Any) -> None:
kwargs.setdefault("timeout", DEFAULT_TIMEOUT)
kwargs.setdefault("limits", DEFAULT_CONNECTION_LIMITS)
kwargs.setdefault("follow_redirects", True)

super().__init__(**kwargs)


if TYPE_CHECKING:
DefaultAsyncHttpxClient = httpx.AsyncClient
"""An alias to `httpx.AsyncClient` that provides the same defaults that this SDK
Expand All @@ -1311,8 +1329,12 @@ def __init__(self, **kwargs: Any) -> None:
This is useful because overriding the `http_client` with your own instance of
`httpx.AsyncClient` will result in httpx's defaults being used, not ours.
"""

DefaultAioHttpClient = httpx.AsyncClient
"""An alias to `httpx.AsyncClient` that changes the default HTTP transport to `aiohttp`."""
else:
DefaultAsyncHttpxClient = _DefaultAsyncHttpxClient
DefaultAioHttpClient = _DefaultAioHttpClient


class AsyncHttpxClientWrapper(DefaultAsyncHttpxClient):
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__ = "2.0.0-alpha.4" # x-release-please-version
__version__ = "2.0.0-alpha.5" # x-release-please-version
Loading