Sniff out which async library your code is running under
sniffio: Sniff out which async library your code is running under
You’re writing a library. You’ve decided to be ambitious, and support multiple async I/O packages, like Trio, and asyncio, and … You’ve written a bunch of clever code to handle all the differences. But… how do you know which piece of clever code to run?
This is a tiny package whose only purpose is to let you detect which async library your code is running under.
- Documentation: https://sniffio.readthedocs.io
- Bug tracker and source code: https://github.com/python-trio/sniffio
- License: MIT or Apache License 2.0, your choice
- Contributor guide: https://trio.readthedocs.io/en/latest/contributing.html
- Code of conduct: Contributors are requested to follow our code of conduct in all project spaces.
This library is maintained by the Trio project, as a service to the async Python community as a whole.
from sniffio import current_async_library import trio import asyncio async def print_library(): library = current_async_library() print("This is:", library) # Prints "This is trio" trio.run(print_library) # Prints "This is asyncio" asyncio.run(print_library())
For more details, including how to add support to new async libraries, please peruse our fine manual.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size sniffio-1.1.0-py3-none-any.whl (4.5 kB)||File type Wheel||Python version py3||Upload date||Hashes View|
|Filename, size sniffio-1.1.0.tar.gz (15.3 kB)||File type Source||Python version None||Upload date||Hashes View|