]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Document supported async libraries (#387)
authorFlorimond Manca <florimond.manca@gmail.com>
Thu, 26 Sep 2019 11:43:56 +0000 (13:43 +0200)
committerGitHub <noreply@github.com>
Thu, 26 Sep 2019 11:43:56 +0000 (13:43 +0200)
* Document supported async libraries

* Update async.md

docs/async.md

index 9e5179e1f29ddcb3f15aa59d6779c1fc6c50380d..feda22d472622df264d84968a0b04a1e0181a17a 100644 (file)
@@ -64,3 +64,44 @@ The async parallel methods are:
 * `.parallel()` *Used as an "async with" context manager.*
 * `.get_response()`
 * `.next_response()`
+
+## Supported async libraries
+
+You can use `AsyncClient` with any of the following async libraries.
+
+!!! tip
+    You will typically be using `AsyncClient` in async programs that run on `asyncio`. If that's the case, or if you're not sure what this is all about, you can safely ignore this section.
+
+### [asyncio](https://docs.python.org/3/library/asyncio.html) (Default)
+
+By default, `AsyncClient` uses `asyncio` to perform asynchronous operations and I/O calls.
+
+```python
+import asyncio
+import httpx
+
+async def main():
+    async with httpx.AsyncClient() as client:
+        ...
+
+asyncio.run(main())
+```
+
+### [trio](https://github.com/python-trio/trio)
+
+To make asynchronous requests in `trio` programs, pass a `TrioBackend` to the `AsyncClient`:
+
+```python
+import trio
+import httpx
+from httpx.concurrency.trio import TrioBackend
+
+async def main():
+    async with httpx.AsyncClient(backend=TrioBackend()) as client:
+        ...
+
+trio.run(main)
+```
+
+!!! important
+    `trio` must be installed to import and use the `TrioBackend`.