README.rst 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. .. image:: https://img.shields.io/badge/chat-join%20now-blue.svg
  2. :target: https://gitter.im/python-trio/general
  3. :alt: Join chatroom
  4. .. image:: https://img.shields.io/badge/docs-read%20now-blue.svg
  5. :target: https://sniffio.readthedocs.io/en/latest/?badge=latest
  6. :alt: Documentation Status
  7. .. image:: https://img.shields.io/pypi/v/sniffio.svg
  8. :target: https://pypi.org/project/sniffio
  9. :alt: Latest PyPi version
  10. .. image:: https://img.shields.io/conda/vn/conda-forge/sniffio.svg
  11. :target: https://anaconda.org/conda-forge/sniffio
  12. :alt: Latest conda-forge version
  13. .. image:: https://travis-ci.org/python-trio/sniffio.svg?branch=master
  14. :target: https://travis-ci.org/python-trio/sniffio
  15. :alt: Automated test status
  16. .. image:: https://codecov.io/gh/python-trio/sniffio/branch/master/graph/badge.svg
  17. :target: https://codecov.io/gh/python-trio/sniffio
  18. :alt: Test coverage
  19. =================================================================
  20. sniffio: Sniff out which async library your code is running under
  21. =================================================================
  22. You're writing a library. You've decided to be ambitious, and support
  23. multiple async I/O packages, like `Trio
  24. <https://trio.readthedocs.io>`__, and `asyncio
  25. <https://docs.python.org/3/library/asyncio.html>`__, and ... You've
  26. written a bunch of clever code to handle all the differences. But...
  27. how do you know *which* piece of clever code to run?
  28. This is a tiny package whose only purpose is to let you detect which
  29. async library your code is running under.
  30. * Documentation: https://sniffio.readthedocs.io
  31. * Bug tracker and source code: https://github.com/python-trio/sniffio
  32. * License: MIT or Apache License 2.0, your choice
  33. * Contributor guide: https://trio.readthedocs.io/en/latest/contributing.html
  34. * Code of conduct: Contributors are requested to follow our `code of
  35. conduct
  36. <https://trio.readthedocs.io/en/latest/code-of-conduct.html>`_
  37. in all project spaces.
  38. This library is maintained by the Trio project, as a service to the
  39. async Python community as a whole.
  40. Quickstart
  41. ----------
  42. .. code-block:: python3
  43. from sniffio import current_async_library
  44. import trio
  45. import asyncio
  46. async def print_library():
  47. library = current_async_library()
  48. print("This is:", library)
  49. # Prints "This is trio"
  50. trio.run(print_library)
  51. # Prints "This is asyncio"
  52. asyncio.run(print_library())
  53. For more details, including how to add support to new async libraries,
  54. `please peruse our fine manual <https://sniffio.readthedocs.io>`__.