This client supports asynchronous I/O that improves performance and increases throughput. See [hello_async.py](../samples/hello/hello_async.py) or [knn_async_basics.py](../samples/knn/knn_async_basics.py) for a working asynchronous sample.
To add the async client to your project, install it using [pip](https://pip.pypa.io/):
```bash
pip install opensearch-py[async]
```
In general, we recommend using a package manager, such as [poetry](https://python-poetry.org/docs/), for your projects. This is the package manager used for [samples](../samples). The following example includes `opensearch-py[async]` in `pyproject.toml`.
```toml
[tool.poetry.dependencies]
opensearch-py={path="../",extras=["async"]}
```
## Async Loop
```python
importasyncio
asyncdefmain():
client=AsyncOpenSearch(...)
try:
# your code here
finally:
client.close()
if__name__=="__main__":
loop=asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(main())
loop.close()
```
## Connect to OpenSearch
```python
host='localhost'
port=9200
auth=('admin','admin')# For testing only. Don't store credentials in code.
client=AsyncOpenSearch(
hosts=[{'host':host,'port':port}],
http_auth=auth,
use_ssl=True,
verify_certs=False,
ssl_show_warn=False
)
info=awaitclient.info()
print(f"Welcome to {info['version']['distribution']}{info['version']['number']}!")