Skip to content

Commit 2c68288

Browse files
committed
manual readme sprucing
1 parent c7424c5 commit 2c68288

File tree

1 file changed

+40
-21
lines changed

1 file changed

+40
-21
lines changed

README.md

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,67 @@
1-
# Replicate Python API library
1+
# Replicate Python API SDK
22

33
<!-- prettier-ignore -->
44
[![PyPI version](https://img.shields.io/pypi/v/replicate.svg?label=pypi%20(stable))](https://pypi.org/project/replicate/)
55

6-
The Replicate Python library provides convenient access to the Replicate REST API from any Python 3.8+
7-
application. The library includes type definitions for all request params and response fields,
8-
and offers both synchronous and asynchronous clients powered by [httpx](https://github.com/encode/httpx).
6+
This is the repo for Replicate's official v2 Python SDK, which provides access to Replicate's HTTP API from any Python 3.8+
7+
application.
98

10-
It is generated with [Stainless](https://www.stainless.com/).
9+
## Docs
1110

12-
## Documentation
11+
- https://sdks.replicate.com/python
12+
- https://replicate.com/docs/reference/http
1313

14-
The REST API documentation can be found on [replicate.com](https://replicate.com/docs/reference/http). The full API of this library can be found in [api.md](api.md).
1514

1615
## Installation
1716

17+
The [`replicate`](https://pypi.org/project/replicate/) package is available on PyPI. Install it with [pip](https://pip.pypa.io/en/stable/):
18+
1819
```sh
19-
# install from PyPI
2020
pip install --pre replicate
2121
```
2222

2323
## Usage
2424

25-
The full API of this library can be found in [api.md](api.md).
25+
Start by getting a [Replicate API token](https://replicate.com/account/api-tokens), then set it as `REPLICATE_API_TOKEN` in your environment:
26+
27+
```sh
28+
export REPLICATE_API_TOKEN="r8_..."
29+
```
30+
31+
Then in your Python code, import the library and use it:
32+
33+
```python
34+
import replicate
35+
36+
claude = replicate.use("anthropic/claude-4.5-sonnet")
37+
seedream = replicate.use("bytedance/seedream-4")
38+
veo = replicate.use("google/veo-3-fast")
39+
40+
# Enhance a simple prompt
41+
image_prompt = claude(prompt="bananas wearing cowboy hats", system_prompt="turn prompts into image prompts")
42+
43+
# Generate an image from the enhanced prompt
44+
images = seedream(prompt=image_prompt)
45+
46+
# Generate a video from the image
47+
video = veo(prompt="dancing bananas", image_input=images[0])
48+
49+
open(video)
50+
```
51+
52+
### Initialization and authentication
53+
54+
The library uses the `REPLICATE_API_TOKEN` environment variable by default to implicitly initialize a client, but you can also initialize a client explicitly and set the `bearer_token` parameter:
2655

2756
```python
2857
import os
2958
from replicate import Replicate
3059

31-
replicate = Replicate(
32-
bearer_token=os.environ.get("REPLICATE_API_TOKEN"), # This is the default and can be omitted
33-
)
34-
35-
prediction = replicate.predictions.get(
36-
prediction_id="gm3qorzdhgbfurvjtvhg6dckhu",
60+
client = Replicate(
61+
bearer_token=os.environ.get("REPLICATE_API_TOKEN")
3762
)
38-
print(prediction.id)
3963
```
4064

41-
While you can provide a `bearer_token` keyword argument,
42-
we recommend using [python-dotenv](https://pypi.org/project/python-dotenv/)
43-
to add `REPLICATE_API_TOKEN="My Bearer Token"` to your `.env` file
44-
so that your Bearer Token is not stored in source control.
45-
4665
## Run a model
4766

4867
You can run a model synchronously using `replicate.run()`:

0 commit comments

Comments
 (0)