|
1 | 1 | # ZeroEntropy Python SDK |
2 | 2 |
|
3 | | -[](https://pypi.org/project/zeroentropy/) |
| 3 | +[>)](https://pypi.org/project/zeroentropy/) |
4 | 4 |
|
5 | 5 | The ZeroEntropy Python SDK provides convenient access to the [ZeroEntropy REST API](https://docs.zeroentropy.dev/api-reference/) from any Python 3.8+ |
6 | 6 | application. |
@@ -79,6 +79,45 @@ asyncio.run(main()) |
79 | 79 |
|
80 | 80 | Functionality between the synchronous and asynchronous clients is otherwise identical. |
81 | 81 |
|
| 82 | +### With aiohttp |
| 83 | + |
| 84 | +By default, the async client uses `httpx` for HTTP requests. However, for improved concurrency performance you may also use `aiohttp` as the HTTP backend. |
| 85 | + |
| 86 | +You can enable this by installing `aiohttp`: |
| 87 | + |
| 88 | +```sh |
| 89 | +# install from PyPI |
| 90 | +pip install --pre zeroentropy[aiohttp] |
| 91 | +``` |
| 92 | + |
| 93 | +Then you can enable it by instantiating the client with `http_client=DefaultAioHttpClient()`: |
| 94 | + |
| 95 | +```python |
| 96 | +import os |
| 97 | +import asyncio |
| 98 | +from zeroentropy import DefaultAioHttpClient |
| 99 | +from zeroentropy import AsyncZeroEntropy |
| 100 | + |
| 101 | + |
| 102 | +async def main() -> None: |
| 103 | + async with AsyncZeroEntropy( |
| 104 | + api_key=os.environ.get("ZEROENTROPY_API_KEY"), # This is the default and can be omitted |
| 105 | + http_client=DefaultAioHttpClient(), |
| 106 | + ) as client: |
| 107 | + response = await client.documents.add( |
| 108 | + collection_name="example_collection", |
| 109 | + content={ |
| 110 | + "type": "text", |
| 111 | + "text": "Example Content", |
| 112 | + }, |
| 113 | + path="my_document.txt", |
| 114 | + ) |
| 115 | + print(response.message) |
| 116 | + |
| 117 | + |
| 118 | +asyncio.run(main()) |
| 119 | +``` |
| 120 | + |
82 | 121 | ## Using types |
83 | 122 |
|
84 | 123 | 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: |
@@ -224,7 +263,7 @@ client.with_options(max_retries=5).status.get_status() |
224 | 263 | ### Timeouts |
225 | 264 |
|
226 | 265 | By default requests time out after 1 minute. You can configure this with a `timeout` option, |
227 | | -which accepts a float or an [`httpx.Timeout`](https://www.python-httpx.org/advanced/#fine-tuning-the-configuration) object: |
| 266 | +which accepts a float or an [`httpx.Timeout`](https://www.python-httpx.org/advanced/timeouts/#fine-tuning-the-configuration) object: |
228 | 267 |
|
229 | 268 | ```python |
230 | 269 | from zeroentropy import ZeroEntropy |
|
0 commit comments