A [ContextVar](https://docs.python.org/3/library/contextvars.html) behaves the same as threading.local in multi-threading environments, but it will also work for coroutines as well. Consider using that to make your library compatible with async contexts.