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.6.0"
".": "2.0.0-alpha.1"
}
2 changes: 1 addition & 1 deletion .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-37cd8ea847eb57706035f766ca549d5b4e2111053af0656a2df9a8150421428e.yml
openapi_spec_hash: a3e4d6fd9aff6de0e4b6d8ad28cbbe05
config_hash: 8e356248f15e5e54d2aecab141f45228
config_hash: da444f7a7ac6238fa0bdecaa01ffa4c3
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
# Changelog

## 2.0.0-alpha.1 (2025-06-10)

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

### ⚠ BREAKING CHANGES

* rename package to `replicate`

### Features

* **client:** add follow_redirects request option ([d606061](https://github.com/replicate/replicate-python-stainless/commit/d60606146abbdc778dc33573ccccdf7bedb524e4))


### Chores

* **docs:** remove reference to rye shell ([1dfaea4](https://github.com/replicate/replicate-python-stainless/commit/1dfaea4108bee6ea565c48c9f99ed503476fd58f))
* rename package to `replicate` ([42e30b7](https://github.com/replicate/replicate-python-stainless/commit/42e30b7b0e736fbb39e95ef7744299746a70d1b5))


### Documentation

* **internal:** add support for the client config option default_client_example_name to Python ([b320609](https://github.com/replicate/replicate-python-stainless/commit/b3206093c824676a300bfc68da307fab5a0f3718))

## 0.6.0 (2025-05-22)

Full Changelog: [v0.5.1...v0.6.0](https://github.com/replicate/replicate-python-stainless/compare/v0.5.1...v0.6.0)
Expand Down
3 changes: 1 addition & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ $ rye sync --all-features
You can then run scripts using `rye run python script.py` or by activating the virtual environment:

```sh
$ rye shell
# or manually activate - https://docs.python.org/3/library/venv.html#how-venvs-work
# Activate the virtual environment - https://docs.python.org/3/library/venv.html#how-venvs-work
$ source .venv/bin/activate

# now you can omit the `rye run` prefix
Expand Down
58 changes: 29 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Replicate Python API library

[![PyPI version](https://img.shields.io/pypi/v/replicate-stainless.svg)](https://pypi.org/project/replicate-stainless/)
[![PyPI version](https://img.shields.io/pypi/v/replicate.svg)](https://pypi.org/project/replicate/)

The Replicate Python library provides convenient access to the Replicate REST API from any Python 3.8+
application. The library includes type definitions for all request params and response fields,
Expand All @@ -16,7 +16,7 @@ The REST API documentation can be found on [replicate.com](https://replicate.com

```sh
# install from PyPI
pip install replicate-stainless
pip install --pre replicate
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the way Python/pip makes it explicit that you want a prerelease. 👍🏼

```

## Usage
Expand All @@ -27,11 +27,11 @@ The full API of this library can be found in [api.md](api.md).
import os
from replicate import Replicate

client = Replicate(
replicate = Replicate(
bearer_token=os.environ.get("REPLICATE_API_TOKEN"), # This is the default and can be omitted
)

prediction = client.predictions.get(
prediction = replicate.predictions.get(
prediction_id="gm3qorzdhgbfurvjtvhg6dckhu",
)
print(prediction.id)
Expand All @@ -51,13 +51,13 @@ import os
import asyncio
from replicate import AsyncReplicate

client = AsyncReplicate(
replicate = AsyncReplicate(
bearer_token=os.environ.get("REPLICATE_API_TOKEN"), # This is the default and can be omitted
)


async def main() -> None:
prediction = await client.predictions.get(
prediction = await replicate.predictions.get(
prediction_id="gm3qorzdhgbfurvjtvhg6dckhu",
)
print(prediction.id)
Expand Down Expand Up @@ -86,11 +86,11 @@ This library provides auto-paginating iterators with each list response, so you
```python
from replicate import Replicate

client = Replicate()
replicate = Replicate()

all_models = []
# Automatically fetches more pages as needed.
for model in client.models.list():
for model in replicate.models.list():
# Do something with model here
all_models.append(model)
print(all_models)
Expand All @@ -102,13 +102,13 @@ Or, asynchronously:
import asyncio
from replicate import AsyncReplicate

client = AsyncReplicate()
replicate = AsyncReplicate()


async def main() -> None:
all_models = []
# Iterate through items across all pages, issuing requests as needed.
async for model in client.models.list():
async for model in replicate.models.list():
all_models.append(model)
print(all_models)

Expand All @@ -119,7 +119,7 @@ asyncio.run(main())
Alternatively, you can use the `.has_next_page()`, `.next_page_info()`, or `.get_next_page()` methods for more granular control working with pages:

```python
first_page = await client.models.list()
first_page = await replicate.models.list()
if first_page.has_next_page():
print(f"will fetch next page using these details: {first_page.next_page_info()}")
next_page = await first_page.get_next_page()
Expand All @@ -131,7 +131,7 @@ if first_page.has_next_page():
Or just work directly with the returned data:

```python
first_page = await client.models.list()
first_page = await replicate.models.list()

print(f"next URL: {first_page.next}") # => "next URL: ..."
for model in first_page.results:
Expand All @@ -148,9 +148,9 @@ Request parameters that correspond to file uploads can be passed as `bytes`, or
from pathlib import Path
from replicate import Replicate

client = Replicate()
replicate = Replicate()

client.files.create(
replicate.files.create(
content=Path("/path/to/file"),
)
```
Expand All @@ -170,10 +170,10 @@ All errors inherit from `replicate.APIError`.
import replicate
from replicate import Replicate

client = Replicate()
replicate = Replicate()

try:
client.predictions.create(
replicate.predictions.create(
input={"text": "Alice"},
version="replicate/hello-world:5c7d5dc6dd8bf75c1acaa8565735e7986bc5b66206b55cca93cb72c9bf15ccaa",
)
Expand Down Expand Up @@ -213,13 +213,13 @@ You can use the `max_retries` option to configure or disable retry settings:
from replicate import Replicate

# Configure the default for all requests:
client = Replicate(
replicate = Replicate(
# default is 2
max_retries=0,
)

# Or, configure per-request:
client.with_options(max_retries=5).predictions.create(
replicate.with_options(max_retries=5).predictions.create(
input={"text": "Alice"},
version="replicate/hello-world:5c7d5dc6dd8bf75c1acaa8565735e7986bc5b66206b55cca93cb72c9bf15ccaa",
)
Expand All @@ -234,18 +234,18 @@ which accepts a float or an [`httpx.Timeout`](https://www.python-httpx.org/advan
from replicate import Replicate

# Configure the default for all requests:
client = Replicate(
replicate = Replicate(
# 20 seconds (default is 1 minute)
timeout=20.0,
)

# More granular control:
client = Replicate(
replicate = Replicate(
timeout=httpx.Timeout(60.0, read=5.0, write=10.0, connect=2.0),
)

# Override per-request:
client.with_options(timeout=5.0).predictions.create(
replicate.with_options(timeout=5.0).predictions.create(
input={"text": "Alice"},
version="replicate/hello-world:5c7d5dc6dd8bf75c1acaa8565735e7986bc5b66206b55cca93cb72c9bf15ccaa",
)
Expand Down Expand Up @@ -288,8 +288,8 @@ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to
```py
from replicate import Replicate

client = Replicate()
response = client.predictions.with_raw_response.create(
replicate = Replicate()
response = replicate.predictions.with_raw_response.create(
input={
"text": "Alice"
},
Expand All @@ -312,7 +312,7 @@ The above interface eagerly reads the full response body when you make the reque
To stream the response body, use `.with_streaming_response` instead, which requires a context manager and only reads the response body once you call `.read()`, `.text()`, `.json()`, `.iter_bytes()`, `.iter_text()`, `.iter_lines()` or `.parse()`. In the async client, these are async methods.

```python
with client.predictions.with_streaming_response.create(
with replicate.predictions.with_streaming_response.create(
input={"text": "Alice"},
version="replicate/hello-world:5c7d5dc6dd8bf75c1acaa8565735e7986bc5b66206b55cca93cb72c9bf15ccaa",
) as response:
Expand All @@ -332,13 +332,13 @@ If you need to access undocumented endpoints, params, or response properties, th

#### Undocumented endpoints

To make requests to undocumented endpoints, you can make requests using `client.get`, `client.post`, and other
To make requests to undocumented endpoints, you can make requests using `replicate.get`, `replicate.post`, and other
http verbs. Options on the client will be respected (such as retries) when making this request.

```py
import httpx

response = client.post(
response = replicate.post(
"/foo",
cast_to=httpx.Response,
body={"my_param": True},
Expand Down Expand Up @@ -370,7 +370,7 @@ You can directly override the [httpx client](https://www.python-httpx.org/api/#c
import httpx
from replicate import Replicate, DefaultHttpxClient

client = Replicate(
replicate = Replicate(
# Or use the `REPLICATE_BASE_URL` env var
base_url="http://my.test.server.example.com:8083",
http_client=DefaultHttpxClient(
Expand All @@ -383,7 +383,7 @@ client = Replicate(
You can also customize the client on a per-request basis by using `with_options()`:

```python
client.with_options(http_client=DefaultHttpxClient(...))
replicate.with_options(http_client=DefaultHttpxClient(...))
```

### Managing HTTP resources
Expand All @@ -393,7 +393,7 @@ By default the library closes underlying HTTP connections whenever the client is
```py
from replicate import Replicate

with Replicate() as client:
with Replicate() as replicate:
# make requests here
...

Expand Down
Loading
Loading