-
-
Notifications
You must be signed in to change notification settings - Fork 954
Closed
Labels
user-experienceEnsuring that users have a good experience using the libraryEnsuring that users have a good experience using the library
Description
Currently, if users want to run HTTPX on trio
they need to manually pass a TrioBackend
to the AsyncClient
:
import trio
import httpx
from httpx.concurrency.trio import TrioBackend
async def main():
async with httpx.AsyncClient(backend=TrioBackend()) as client:
...
trio.run(main)
On the other hand, running on asyncio
doesn't require passing any backend
argument, which is a better user experience we'd like to have in all cases.
We should allow AsyncClient()
to auto-detect the async environment it's running in, and use the appropriate backend — and make that the default behavior, instead of asyncio.
Implementation ideas:
- Create a
get_default_concurrency_backend()
utility inutils.py
. Detecting the async library in use can be done using sniffio. If no backend is available, raise an appropriate exception. (For example, this should currently be the case if we tried to run oncurio
, since we don't have aCurioBackend
.) - Use this utility in all places where we currently default to
AsyncioBackend
as abackend
, e.g.AsyncClient
,ConnectionPool
, etc.
Metadata
Metadata
Assignees
Labels
user-experienceEnsuring that users have a good experience using the libraryEnsuring that users have a good experience using the library