You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -58,6 +57,11 @@ To authenticate your requests, include your API key in the `Authorization` heade
58
57
<!-- Start SDK Installation [installation] -->
59
58
## SDK Installation
60
59
60
+
> [!NOTE]
61
+
> **Python version upgrade policy**
62
+
>
63
+
> Once a Python version reaches its [official end of life date](https://devguide.python.org/versions/), a 3-month grace period is provided for users to upgrade. Following this grace period, the minimum python version supported in the SDK will be updated.
64
+
61
65
The SDK can be installed with either *pip* or *poetry* package managers.
62
66
63
67
### PIP
@@ -75,6 +79,37 @@ pip install comfydeploy
75
79
```bash
76
80
poetry add comfydeploy
77
81
```
82
+
83
+
### Shell and script usage with `uv`
84
+
85
+
You can use this SDK in a Python shell with [uv](https://docs.astral.sh/uv/) and the `uvx` command that comes with it like so:
86
+
87
+
```shell
88
+
uvx --from comfydeploy python
89
+
```
90
+
91
+
It's also possible to write a standalone Python script without needing to set up a whole project like so:
92
+
93
+
```python
94
+
#!/usr/bin/env -S uv run --script
95
+
# /// script
96
+
# requires-python = ">=3.9"
97
+
# dependencies = [
98
+
# "comfydeploy",
99
+
# ]
100
+
# ///
101
+
102
+
from comfydeploy import ComfyDeploy
103
+
104
+
sdk = ComfyDeploy(
105
+
# SDK arguments
106
+
)
107
+
108
+
# Rest of script here...
109
+
```
110
+
111
+
Once that is saved to a file, you can run it with `uv run script.py` where
112
+
`script.py` can be replaced with the actual file name.
78
113
<!-- End SDK Installation [installation] -->
79
114
80
115
<!-- Start IDE Support [idesupport] -->
@@ -96,6 +131,7 @@ Generally, the SDK will work well with most IDEs out of the box. However, when u
96
131
# Synchronous Example
97
132
from comfydeploy import ComfyDeploy
98
133
134
+
99
135
with ComfyDeploy(
100
136
bearer="<YOUR_BEARER_TOKEN_HERE>",
101
137
) as comfy_deploy:
@@ -117,6 +153,7 @@ import asyncio
117
153
from comfydeploy import ComfyDeploy
118
154
119
155
asyncdefmain():
156
+
120
157
asyncwith ComfyDeploy(
121
158
bearer="<YOUR_BEARER_TOKEN_HERE>",
122
159
) as comfy_deploy:
@@ -147,6 +184,7 @@ To authenticate with the API the `bearer` parameter must be set when initializin
<!-- End Server-sent event streaming [eventstream] -->
265
-
266
-
<!-- Start File uploads [file-upload] -->
267
-
## File uploads
268
-
269
-
Certain SDK methods accept file objects as part of a request body or multi-part request. It is possible and typically recommended to upload files as a stream rather than reading the entire contents into memory. This avoids excessive memory consumption and potentially crashing with out-of-memory errors when working with very large files. The following example demonstrates how to attach a file stream to a request.
270
-
271
-
> [!TIP]
272
-
>
273
-
> For endpoints that handle file uploads bytes arrays can also be used. However, using streams is recommended for large files.
274
-
>
275
-
276
-
```python
277
-
from comfydeploy import ComfyDeploy
278
-
279
-
with ComfyDeploy(
280
-
bearer="<YOUR_BEARER_TOKEN_HERE>",
281
-
) as comfy_deploy:
282
-
283
-
res = comfy_deploy.file.upload(request={
284
-
"file": {
285
-
"file_name": "example.file",
286
-
"content": open("example.file", "rb"),
287
-
},
288
-
})
289
-
290
-
assert res.file_upload_response isnotNone
291
-
292
-
# Handle response
293
-
print(res.file_upload_response)
294
-
295
-
```
296
-
<!-- End File uploads [file-upload] -->
297
-
298
221
<!-- Start Retries [retries] -->
299
222
## Retries
300
223
@@ -305,6 +228,7 @@ To change the default retry strategy for a single API call, simply provide a `Re
305
228
from comfydeploy import ComfyDeploy
306
229
from comfydeploy.utils import BackoffStrategy, RetryConfig
307
230
231
+
308
232
with ComfyDeploy(
309
233
bearer="<YOUR_BEARER_TOKEN_HERE>",
310
234
) as comfy_deploy:
@@ -324,6 +248,7 @@ If you'd like to override the default retry strategy for all operations that sup
324
248
from comfydeploy import ComfyDeploy
325
249
from comfydeploy.utils import BackoffStrategy, RetryConfig
@@ -366,6 +291,7 @@ When custom error responses are specified for an operation, the SDK may also rai
366
291
from comfydeploy import ComfyDeploy
367
292
from comfydeploy.models import errors
368
293
294
+
369
295
with ComfyDeploy(
370
296
bearer="<YOUR_BEARER_TOKEN_HERE>",
371
297
) as comfy_deploy:
@@ -395,17 +321,18 @@ with ComfyDeploy(
395
321
396
322
You can override the default server globally by passing a server index to the `server_idx: int` optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:
The `ComfyDeploy` class implements the context manager protocol and registers a finalizer function to close the underlying sync and async HTTPX clients it uses under the hood. This will close HTTP connections, release memory and free up other resources held by the SDK. In short-lived Python programs and notebooks that make a few SDK method calls, resource management may not be a concern. However, in longer-lived programs, it is beneficial to create a single SDK instance via a [context manager][context-manager] and reuse it across the application.
0 commit comments