|
1 | 1 | # Runloop Python API library |
2 | 2 |
|
3 | | -[](https://pypi.org/project/runloop_api_client/) |
| 3 | +[>)](https://pypi.org/project/runloop_api_client/) |
4 | 4 |
|
5 | 5 | The Runloop Python library provides convenient access to the Runloop REST API from any Python 3.8+ |
6 | 6 | application. The library includes type definitions for all request params and response fields, |
@@ -64,6 +64,38 @@ asyncio.run(main()) |
64 | 64 |
|
65 | 65 | Functionality between the synchronous and asynchronous clients is otherwise identical. |
66 | 66 |
|
| 67 | +### With aiohttp |
| 68 | + |
| 69 | +By default, the async client uses `httpx` for HTTP requests. However, for improved concurrency performance you may also use `aiohttp` as the HTTP backend. |
| 70 | + |
| 71 | +You can enable this by installing `aiohttp`: |
| 72 | + |
| 73 | +```sh |
| 74 | +# install from PyPI |
| 75 | +pip install runloop_api_client[aiohttp] |
| 76 | +``` |
| 77 | + |
| 78 | +Then you can enable it by instantiating the client with `http_client=DefaultAioHttpClient()`: |
| 79 | + |
| 80 | +```python |
| 81 | +import os |
| 82 | +import asyncio |
| 83 | +from runloop_api_client import DefaultAioHttpClient |
| 84 | +from runloop_api_client import AsyncRunloop |
| 85 | + |
| 86 | + |
| 87 | +async def main() -> None: |
| 88 | + async with AsyncRunloop( |
| 89 | + bearer_token=os.environ.get("RUNLOOP_API_KEY"), # This is the default and can be omitted |
| 90 | + http_client=DefaultAioHttpClient(), |
| 91 | + ) as client: |
| 92 | + devbox_view = await client.devboxes.create() |
| 93 | + print(devbox_view.id) |
| 94 | + |
| 95 | + |
| 96 | +asyncio.run(main()) |
| 97 | +``` |
| 98 | + |
67 | 99 | ## Using types |
68 | 100 |
|
69 | 101 | Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typing.html#typing.TypedDict). Responses are [Pydantic models](https://docs.pydantic.dev) which also provide helper methods for things like: |
@@ -235,7 +267,7 @@ client.with_options(max_retries=5).devboxes.create() |
235 | 267 | ### Timeouts |
236 | 268 |
|
237 | 269 | By default requests time out after 1 minute. You can configure this with a `timeout` option, |
238 | | -which accepts a float or an [`httpx.Timeout`](https://www.python-httpx.org/advanced/#fine-tuning-the-configuration) object: |
| 270 | +which accepts a float or an [`httpx.Timeout`](https://www.python-httpx.org/advanced/timeouts/#fine-tuning-the-configuration) object: |
239 | 271 |
|
240 | 272 | ```python |
241 | 273 | from runloop_api_client import Runloop |
|
0 commit comments