sniffio

1.3.1 · active · verified Sat Mar 28

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.

Warnings

Install

Imports

Quickstart

A simple script demonstrating how to use sniffio to detect the current async library and run a coroutine accordingly.

import sniffio
import trio
import asyncio

async def print_library():
    library = sniffio.current_async_library()
    print(f'This is {library}')

# Prints 'This is trio'
trio.run(print_library)

# Prints 'This is asyncio'
asyncio.run(print_library())

view raw JSON →