{"id":331,"library":"sniffio","title":"sniffio","description":"A Python library that detects which asynchronous I/O library (e.g., Trio, asyncio) is currently running in your code. Current version: 1.3.1, released on February 25, 2024. Maintained by the Trio project, it has a stable release cadence with updates approximately every 1-2 years.","status":"active","version":"1.3.1","language":"python","source_language":"en","source_url":"https://github.com/python-trio/sniffio","tags":["asyncio","Trio","asynchronous I/O","Python 3.7+"],"install":[{"cmd":"pip install sniffio","lang":"bash","label":"Install sniffio"}],"dependencies":[{"reason":"Required for Trio support","package":"trio"},{"reason":"Required for asyncio support","package":"asyncio"}],"imports":[{"note":"Ensure correct import path to access the function.","symbol":"current_async_library","correct":"from sniffio import current_async_library"}],"quickstart":{"code":"import sniffio\nimport trio\nimport asyncio\n\nasync def print_library():\n    library = sniffio.current_async_library()\n    print(f'This is {library}')\n\n# Prints 'This is trio'\ntrio.run(print_library)\n\n# Prints 'This is asyncio'\nasyncio.run(print_library())","lang":"python","description":"A simple script demonstrating how to use sniffio to detect the current async library and run a coroutine accordingly."},"warnings":[{"fix":"Upgrade to Python 3.7 or later.","message":"Dropped support for Python 3.5 and 3.6 in version 1.3.0","severity":"breaking","affected_versions":"1.3.0"},{"fix":"Remove explicit version specifications in USES=python.","message":"Explicit version specifications in USES=python for '3.x+' are deprecated","severity":"deprecated","affected_versions":"1.3.0"},{"fix":"Install the 'trio' package using pip: `pip install trio`.","message":"ModuleNotFoundError: No module named 'trio'. The 'trio' package is not installed.","severity":"breaking","affected_versions":"N/A"},{"fix":"Install the 'trio' package using pip (e.g., `pip install trio`) or ensure it's included in your project's dependencies.","message":"Module 'trio' not found. Ensure the 'trio' package is installed in the environment.","severity":"breaking","affected_versions":"all"}],"env_vars":null,"search_vec":"'-2':44 '1':43 '1.3.1':22 '2024':27 '25':26 '3.7':51 'approxim':41 'asynchron':8,48 'asyncio':13,46 'cadenc':38 'code':19 'current':15,20 'detect':6 'e.g':11 'everi':42 'februari':25 'i/o':9,49 'librari':4,10 'maintain':28 'project':32 'python':3,50 'releas':23,37 'run':16 'sniffio':1 'stabl':36 'trio':12,31,47 'updat':40 'version':21 'year':45","created_at":"2026-03-28T08:31:41.108628+00:00","updated_at":"2026-04-16T21:53:00.295531+00:00","problems":[{"fix":"Ensure that calls to `sniffio.current_async_library()` are made within an `async` function that is itself executed by an asynchronous runner like `asyncio.run()` or `trio.run()`.\n\n```python\nimport sniffio\nimport asyncio\n\nasync def my_async_function():\n    print(f\"Current async library: {sniffio.current_async_library()}\")\n\nasyncio.run(my_async_function())\n```","cause":"You are attempting to call `sniffio.current_async_library()` (or a similar sniffio function) from a synchronous context, outside of an active Trio or asyncio event loop.","error":"RuntimeError: This function is only available from inside a Trio or asyncio task."},{"fix":"Install the `sniffio` package using pip.\n\n```bash\npip install sniffio\n```","cause":"The `sniffio` package has not been installed in your current Python environment.","error":"ModuleNotFoundError: No module named 'sniffio'"},{"fix":"Use the correct function name `sniffio.current_async_library()` to retrieve information about the running async library.\n\n```python\nimport sniffio\nimport asyncio\n\nasync def get_library_info():\n    lib = sniffio.current_async_library()\n    if lib:\n        print(f\"Detected: {lib.sniffio_name}\")\n    else:\n        print(\"No async library detected.\")\n\nasyncio.run(get_library_info())\n```","cause":"You are attempting to access a non-existent attribute or made a typo when trying to call the correct function to detect the current async library.","error":"AttributeError: module 'sniffio' has no attribute 'async_library'"},{"fix":"Always check if the return value of `sniffio.current_async_library()` is not `None` before attempting to access its attributes.\n\n```python\nimport sniffio\nimport asyncio\n\nasync def check_and_use_library():\n    detected_lib = sniffio.current_async_library()\n    if detected_lib:\n        print(f\"Running with: {detected_lib.sniffio_name}\")\n    else:\n        print(\"No async library is currently active.\")\n\nasyncio.run(check_and_use_library())\n```","cause":"This error occurs when `sniffio.current_async_library()` returns `None` (indicating no async event loop is running), and you then attempt to access an attribute like `sniffio_name` directly on that `None` value without checking if a library was actually detected.","error":"AttributeError: 'NoneType' object has no attribute 'sniffio_name'"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"quickstart_score":0,"quickstart_tag":"stale","pypi_latest":"1.3.1","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/python-trio/sniffio","docs":"https://sniffio.readthedocs.io/","changelog":"https://sniffio.readthedocs.io/en/latest/history.html","pypi":"https://pypi.org/project/sniffio/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["http-networking"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-27","next_check":"2026-07-28","install_tag":"verified"}}