Skip to content

Commit b320609

Browse files
docs(internal): add support for the client config option default_client_example_name to Python
1 parent 656cec0 commit b320609

File tree

3 files changed

+61
-61
lines changed

3 files changed

+61
-61
lines changed

README.md

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ The full API of this library can be found in [api.md](api.md).
2727
import os
2828
from replicate import Replicate
2929

30-
client = Replicate(
30+
replicate = Replicate(
3131
bearer_token=os.environ.get("REPLICATE_API_TOKEN"), # This is the default and can be omitted
3232
)
3333

34-
prediction = client.predictions.get(
34+
prediction = replicate.predictions.get(
3535
prediction_id="gm3qorzdhgbfurvjtvhg6dckhu",
3636
)
3737
print(prediction.id)
@@ -51,13 +51,13 @@ import os
5151
import asyncio
5252
from replicate import AsyncReplicate
5353

54-
client = AsyncReplicate(
54+
replicate = AsyncReplicate(
5555
bearer_token=os.environ.get("REPLICATE_API_TOKEN"), # This is the default and can be omitted
5656
)
5757

5858

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

89-
client = Replicate()
89+
replicate = Replicate()
9090

9191
all_models = []
9292
# Automatically fetches more pages as needed.
93-
for model in client.models.list():
93+
for model in replicate.models.list():
9494
# Do something with model here
9595
all_models.append(model)
9696
print(all_models)
@@ -102,13 +102,13 @@ Or, asynchronously:
102102
import asyncio
103103
from replicate import AsyncReplicate
104104

105-
client = AsyncReplicate()
105+
replicate = AsyncReplicate()
106106

107107

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

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

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

133133
```python
134-
first_page = await client.models.list()
134+
first_page = await replicate.models.list()
135135

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

151-
client = Replicate()
151+
replicate = Replicate()
152152

153-
client.files.create(
153+
replicate.files.create(
154154
content=Path("/path/to/file"),
155155
)
156156
```
@@ -170,10 +170,10 @@ All errors inherit from `replicate.APIError`.
170170
import replicate
171171
from replicate import Replicate
172172

173-
client = Replicate()
173+
replicate = Replicate()
174174

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

215215
# Configure the default for all requests:
216-
client = Replicate(
216+
replicate = Replicate(
217217
# default is 2
218218
max_retries=0,
219219
)
220220

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

236236
# Configure the default for all requests:
237-
client = Replicate(
237+
replicate = Replicate(
238238
# 20 seconds (default is 1 minute)
239239
timeout=20.0,
240240
)
241241

242242
# More granular control:
243-
client = Replicate(
243+
replicate = Replicate(
244244
timeout=httpx.Timeout(60.0, read=5.0, write=10.0, connect=2.0),
245245
)
246246

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

291-
client = Replicate()
292-
response = client.predictions.with_raw_response.create(
291+
replicate = Replicate()
292+
response = replicate.predictions.with_raw_response.create(
293293
input={
294294
"text": "Alice"
295295
},
@@ -312,7 +312,7 @@ The above interface eagerly reads the full response body when you make the reque
312312
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.
313313

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

333333
#### Undocumented endpoints
334334

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

338338
```py
339339
import httpx
340340

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

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

385385
```python
386-
client.with_options(http_client=DefaultHttpxClient(...))
386+
replicate.with_options(http_client=DefaultHttpxClient(...))
387387
```
388388

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

396-
with Replicate() as client:
396+
with Replicate() as replicate:
397397
# make requests here
398398
...
399399

0 commit comments

Comments
 (0)