Skip to content

Commit 176968a

Browse files
committed
Document Trio support
1 parent 1094d2d commit 176968a

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

docs/reference/async.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,27 @@ All APIs that are available under the sync client are also available under the a
5050

5151
See also the [Using OpenTelemetry](/reference/opentelemetry.md) page.
5252

53+
## Trio support
54+
55+
If you prefer using Trio instead of asyncio to take advantage of its better structured concurrency support, you can use the HTTPX async node which supports Trio out of the box.
56+
57+
```python
58+
import trio
59+
from elasticsearch import AsyncElasticsearch
60+
61+
client = AsyncElasticsearch(
62+
"https://...",
63+
api_key="...",
64+
node_class="httpxasync")
65+
66+
async def main():
67+
resp = await client.info()
68+
print(resp.body)
69+
70+
trio.run(main)
71+
```
72+
73+
The one limitation of Trio support is that it does not currently support node sniffing, which was not implemented with structured concurrency in mind.
5374

5475
## Frequently Asked Questions [_frequently_asked_questions]
5576

docs/reference/dsl_how_to_guides.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,6 +1555,12 @@ The DSL module supports async/await with [asyncio](https://docs.python.org/3/lib
15551555
$ python -m pip install "elasticsearch[async]"
15561556
```
15571557

1558+
The DSL module also supports [Trio](https://trio.readthedocs.io/en/stable/) when using the Async HTTPX client. You do need to install Trio and HTTPX separately:
1559+
1560+
```bash
1561+
$ python -m pip install "elasticsearch trio httpx"
1562+
```
1563+
15581564
### Connections [_connections]
15591565

15601566
Use the `async_connections` module to manage your asynchronous connections.
@@ -1565,6 +1571,14 @@ from elasticsearch.dsl import async_connections
15651571
async_connections.create_connection(hosts=['localhost'], timeout=20)
15661572
```
15671573

1574+
If you're using Trio, you need to explicitly request the Async HTTP client:
1575+
1576+
```python
1577+
from elasticsearch.dsl import async_connections
1578+
1579+
async_connections.create_connection(hosts=['localhost'], node_class="httpxasync")
1580+
```
1581+
15681582
All the options available in the `connections` module can be used with `async_connections`.
15691583

15701584
#### How to avoid *Unclosed client session / connector* warnings on exit [_how_to_avoid_unclosed_client_session_connector_warnings_on_exit]
@@ -1576,8 +1590,6 @@ es = async_connections.get_connection()
15761590
await es.close()
15771591
```
15781592

1579-
1580-
15811593
### Search DSL [_search_dsl]
15821594

15831595
Use the `AsyncSearch` class to perform asynchronous searches.

0 commit comments

Comments
 (0)