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
{{ message }}
This repository was archived by the owner on Sep 12, 2025. It is now read-only.
> 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.
50
+
45
51
The SDK can be installed with either *pip* or *poetry* package managers.
46
52
47
53
### PIP
@@ -59,6 +65,37 @@ pip install unkey.py
59
65
```bash
60
66
poetry add unkey.py
61
67
```
68
+
69
+
### Shell and script usage with `uv`
70
+
71
+
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:
72
+
73
+
```shell
74
+
uvx --from unkey.py python
75
+
```
76
+
77
+
It's also possible to write a standalone Python script without needing to set up a whole project like so:
78
+
79
+
```python
80
+
#!/usr/bin/env -S uv run --script
81
+
# /// script
82
+
# requires-python = ">=3.9"
83
+
# dependencies = [
84
+
# "unkey.py",
85
+
# ]
86
+
# ///
87
+
88
+
from unkey_py import Unkey
89
+
90
+
sdk = Unkey(
91
+
# SDK arguments
92
+
)
93
+
94
+
# Rest of script here...
95
+
```
96
+
97
+
Once that is saved to a file, you can run it with `uv run script.py` where
98
+
`script.py` can be replaced with the actual file name.
62
99
<!-- End SDK Installation [installation] -->
63
100
64
101
<!-- Start IDE Support [idesupport] -->
@@ -80,14 +117,17 @@ Generally, the SDK will work well with most IDEs out of the box. However, when u
If you'd like to override the default retry strategy for all operations that support retries, you can use the `retry_config` optional parameter when initializing the SDK:
239
288
```python
240
-
from unkey.utils import BackoffStrategy, RetryConfig
241
289
from unkey_py import Unkey
290
+
from unkey_py.utils import BackoffStrategy, RetryConfig
@@ -285,16 +338,19 @@ When custom error responses are specified for an operation, the SDK may also rai
285
338
```python
286
339
from unkey_py import Unkey, models
287
340
341
+
288
342
with Unkey(
289
343
bearer_auth="UNKEY_ROOT_KEY",
290
-
) ass:
344
+
) asunkey:
291
345
res =None
292
346
try:
293
-
res = s.liveness.check()
294
347
295
-
if res.object isnotNone:
296
-
# handle response
297
-
pass
348
+
res = unkey.liveness.check()
349
+
350
+
assert res.object isnotNone
351
+
352
+
# Handle response
353
+
print(res.object)
298
354
299
355
except models.ErrBadRequest as e:
300
356
# handle e.data: models.ErrBadRequestData
@@ -311,6 +367,9 @@ with Unkey(
311
367
except models.ErrConflict as e:
312
368
# handle e.data: models.ErrConflictData
313
369
raise(e)
370
+
except models.ErrPreconditionFailed as e:
371
+
# handle e.data: models.ErrPreconditionFailedData
372
+
raise(e)
314
373
except models.ErrTooManyRequests as e:
315
374
# handle e.data: models.ErrTooManyRequestsData
316
375
raise(e)
@@ -328,19 +387,22 @@ with Unkey(
328
387
329
388
### Override Server URL Per-Client
330
389
331
-
The default server can also be overridden globally by passing a URL to the `server_url: str` optional parameter when initializing the SDK client instance. For example:
390
+
The default server can be overridden globally by passing a URL to the `server_url: str` optional parameter when initializing the SDK client instance. For example:
332
391
```python
333
392
from unkey_py import Unkey
334
393
394
+
335
395
with Unkey(
336
396
server_url="https://api.unkey.dev",
337
397
bearer_auth="UNKEY_ROOT_KEY",
338
-
) as s:
339
-
res = s.liveness.check()
398
+
) as unkey:
399
+
400
+
res = unkey.liveness.check()
340
401
341
-
if res.object isnotNone:
342
-
# handle response
343
-
pass
402
+
assert res.object isnotNone
403
+
404
+
# Handle response
405
+
print(res.object)
344
406
345
407
```
346
408
<!-- End Server Selection [server] -->
@@ -441,18 +503,48 @@ To authenticate with the API the `bearer_auth` parameter must be set when initia
The `Unkey` 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