Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+35 added−0 removed
other:+35 added−0 removed
Provenance
Commit
926d6cd
Tree
b8babde
Author
Florimond Manca <florimond.manca@gmail.com>
Committer
GitHub <noreply@github.com>
Parent
f0e6acb
1 file changed+35 added−0 removed
modified:docs/async.md+35 added
103 unmodified lines
Expand all
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
103 unmodified lines
Expand all
```
!!! important
`trio` must be installed to import and use the `TrioBackend`.
## FAQ
### When should I use an `AsyncClient`?
You should use an `AsyncClient` whenever you are inside an *async environment*.
In particular, using `httpx.get()` or `httpx.Client()` in an async environment is **not** supported. There are several technical reasons to this, but the rationale is that you shouldn't be doing blocking-style network calls in the context of an event loop (for more discussion, see [#179](https://github.com/encode/httpx/issues/179)).
For example, this won't work:
```python
import asyncio
import httpx
async def main():
r = httpx.get("https://example.org")
asyncio.run(main())
```
Instead, you should use an `AsyncClient`:
```python
import asyncio
import httpx
async def main():
async with httpx.AsyncClient() as client:
r = await client.get("https://example.org")
asyncio.run(main())
```
If you *need* to make synchronous requests, or otherwise run into issues related to sync usage, you should probably consider using a regular threaded client such as [Requests](https://github.com/psf/requests) instead.