1- # Replicate Client Python API library
1+ # Replicate Python API library
22
33[ ![ PyPI version] ( https://img.shields.io/pypi/v/replicate-stainless.svg )] ( https://pypi.org/project/replicate-stainless/ )
44
5- The Replicate Client Python library provides convenient access to the Replicate Client REST API from any Python 3.8+
5+ The Replicate Python library provides convenient access to the Replicate REST API from any Python 3.8+
66application. The library includes type definitions for all request params and response fields,
77and offers both synchronous and asynchronous clients powered by [ httpx] ( https://github.com/encode/httpx ) .
88
@@ -25,9 +25,9 @@ The full API of this library can be found in [api.md](api.md).
2525
2626``` python
2727import os
28- from replicate import ReplicateClient
28+ from replicate import Replicate
2929
30- client = ReplicateClient (
30+ client = Replicate (
3131 bearer_token = os.environ.get(" REPLICATE_API_TOKEN" ), # This is the default and can be omitted
3232)
3333
@@ -42,14 +42,14 @@ so that your Bearer Token is not stored in source control.
4242
4343## Async usage
4444
45- Simply import ` AsyncReplicateClient ` instead of ` ReplicateClient ` and use ` await ` with each API call:
45+ Simply import ` AsyncReplicate ` instead of ` Replicate ` and use ` await ` with each API call:
4646
4747``` python
4848import os
4949import asyncio
50- from replicate import AsyncReplicateClient
50+ from replicate import AsyncReplicate
5151
52- client = AsyncReplicateClient (
52+ client = AsyncReplicate (
5353 bearer_token = os.environ.get(" REPLICATE_API_TOKEN" ), # This is the default and can be omitted
5454)
5555
@@ -75,14 +75,14 @@ Typed requests and responses provide autocomplete and documentation within your
7575
7676## Pagination
7777
78- List methods in the Replicate Client API are paginated.
78+ List methods in the Replicate API are paginated.
7979
8080This library provides auto-paginating iterators with each list response, so you do not have to request successive pages manually:
8181
8282``` python
83- from replicate import ReplicateClient
83+ from replicate import Replicate
8484
85- client = ReplicateClient ()
85+ client = Replicate ()
8686
8787all_predictions = []
8888# Automatically fetches more pages as needed.
@@ -96,9 +96,9 @@ Or, asynchronously:
9696
9797``` python
9898import asyncio
99- from replicate import AsyncReplicateClient
99+ from replicate import AsyncReplicate
100100
101- client = AsyncReplicateClient ()
101+ client = AsyncReplicate ()
102102
103103
104104async def main () -> None :
@@ -147,9 +147,9 @@ All errors inherit from `replicate.APIError`.
147147
148148``` python
149149import replicate
150- from replicate import ReplicateClient
150+ from replicate import Replicate
151151
152- client = ReplicateClient ()
152+ client = Replicate ()
153153
154154try :
155155 client.account.get()
@@ -186,10 +186,10 @@ Connection errors (for example, due to a network connectivity problem), 408 Requ
186186You can use the ` max_retries ` option to configure or disable retry settings:
187187
188188``` python
189- from replicate import ReplicateClient
189+ from replicate import Replicate
190190
191191# Configure the default for all requests:
192- client = ReplicateClient (
192+ client = Replicate (
193193 # default is 2
194194 max_retries = 0 ,
195195)
@@ -204,16 +204,16 @@ By default requests time out after 1 minute. You can configure this with a `time
204204which accepts a float or an [ ` httpx.Timeout ` ] ( https://www.python-httpx.org/advanced/#fine-tuning-the-configuration ) object:
205205
206206``` python
207- from replicate import ReplicateClient
207+ from replicate import Replicate
208208
209209# Configure the default for all requests:
210- client = ReplicateClient (
210+ client = Replicate (
211211 # 20 seconds (default is 1 minute)
212212 timeout = 20.0 ,
213213)
214214
215215# More granular control:
216- client = ReplicateClient (
216+ client = Replicate (
217217 timeout = httpx.Timeout(60.0 , read = 5.0 , write = 10.0 , connect = 2.0 ),
218218)
219219
@@ -231,10 +231,10 @@ Note that requests that time out are [retried twice by default](#retries).
231231
232232We use the standard library [ ` logging ` ] ( https://docs.python.org/3/library/logging.html ) module.
233233
234- You can enable logging by setting the environment variable ` REPLICATE_CLIENT_LOG ` to ` info ` .
234+ You can enable logging by setting the environment variable ` REPLICATE_LOG ` to ` info ` .
235235
236236``` shell
237- $ export REPLICATE_CLIENT_LOG =info
237+ $ export REPLICATE_LOG =info
238238```
239239
240240Or to ` debug ` for more verbose logging.
@@ -256,9 +256,9 @@ if response.my_field is None:
256256The "raw" Response object can be accessed by prefixing ` .with_raw_response. ` to any HTTP method call, e.g.,
257257
258258``` py
259- from replicate import ReplicateClient
259+ from replicate import Replicate
260260
261- client = ReplicateClient ()
261+ client = Replicate ()
262262response = client.account.with_raw_response.get()
263263print (response.headers.get(' X-My-Header' ))
264264
@@ -330,10 +330,10 @@ You can directly override the [httpx client](https://www.python-httpx.org/api/#c
330330
331331``` python
332332import httpx
333- from replicate import ReplicateClient , DefaultHttpxClient
333+ from replicate import Replicate , DefaultHttpxClient
334334
335- client = ReplicateClient (
336- # Or use the `REPLICATE_CLIENT_BASE_URL ` env var
335+ client = Replicate (
336+ # Or use the `REPLICATE_BASE_URL ` env var
337337 base_url = " http://my.test.server.example.com:8083" ,
338338 http_client = DefaultHttpxClient(
339339 proxy = " http://my.test.proxy.example.com" ,
@@ -353,9 +353,9 @@ client.with_options(http_client=DefaultHttpxClient(...))
353353By default the library closes underlying HTTP connections whenever the client is [ garbage collected] ( https://docs.python.org/3/reference/datamodel.html#object.__del__ ) . You can manually close the client using the ` .close() ` method if desired, or with a context manager that closes when exiting.
354354
355355``` py
356- from replicate import ReplicateClient
356+ from replicate import Replicate
357357
358- with ReplicateClient () as client:
358+ with Replicate () as client:
359359 # make requests here
360360 ...
361361
0 commit comments