Skip to content

python-trio/sniffio

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
September 4, 2022 20:55
April 19, 2019 21:00
September 1, 2022 16:33
July 28, 2018 00:15
July 28, 2018 01:28
July 28, 2018 00:15
July 28, 2018 01:28
July 28, 2018 00:15
July 28, 2018 00:15
July 28, 2018 00:15
July 28, 2018 00:15
July 28, 2018 01:28
September 1, 2022 14:54
Join chatroom Documentation Status Latest PyPi version Latest conda-forge version Automated test status Test coverage

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.

This library is maintained by the Trio project, as a service to the async Python community as a whole.

Quickstart

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.