
Product
Redesigned Repositories Page: A Faster Way to Prioritize Security Risk
Our redesigned Repositories page adds alert severity, filtering, and tabs for faster triage and clearer insights across all your projects.
Asyncer, async and await, focused on developer experience.
Documentation: https://asyncer.tiangolo.com
Source Code: https://github.com/fastapi/asyncer
Asyncer is a small library built on top of AnyIO.
Asyncer has a small number of utility functions that allow working with async
, await
, and concurrent code in a more convenient way under my (@tiangolo - Sebastián Ramírez) very opinionated and subjective point of view.
The main goal of Asyncer is to improve developer experience by providing better support for autocompletion and inline errors in the editor, and more certainty that the code is bug-free by providing better support for type checking tools like mypy.
Asyncer also tries to improve convenience and simplicity when working with async code mixed with regular blocking code, allowing to use them together in a simpler way... again, under my very subjective point of view.
This small library only exists to be able to use these utility functions until (and if) they are integrated into AnyIO.
It will probably take some time for that to happen (or to be decided if it will be included or not).
So I made this to be able to use these ideas right now. 🤓
Yes 🎉 (but continue reading).
You can use this and evaluate the library API design I'm proposing. It will probably be useful to know if it works and is useful for you (I hope so).
But still, consider this lab material, expect it to change a bit. 🧪
If you use it, pin the exact Asyncer version for your project, to make sure it all works.
Have tests for your project (as you should, anyway). And upgrade the version once you know that the new version continues to work correctly.
Still, it's just 4 functions, so there's not much to change, if you had to refactor your code to update something it would not be much.
And if you don't want to add asyncer
as a dependency to your project, you can also just copy the main file and try out those functions, it's quite small (but in that case you won't get updates easily).
As Asyncer is based on AnyIO it will be also installed automatically when you install Asyncer.
$ pip install asyncer
---> 100%
Successfully installed asyncer anyio
You can read more about each of the use cases and utility functions in Asyncer in the tutorial.
As a sneak preview of one of the utilities, you can call sync code from async code using asyncify()
:
import time
import anyio
from asyncer import asyncify
def do_sync_work(name: str):
time.sleep(1)
return f"Hello, {name}"
async def main():
message = await asyncify(do_sync_work)(name="World")
print(message)
anyio.run(main)
Asyncer's asyncify()
will use AnyIO underneath to do the smart thing, avoid blocking the main async event loop, and run the sync/blocking function in a worker thread.
Everything in Asyncer is designed to get the best developer experience possible, with the best editor support.
This project is licensed under the terms of the MIT license.
FAQs
Asyncer, async and await, focused on developer experience.
We found that asyncer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Our redesigned Repositories page adds alert severity, filtering, and tabs for faster triage and clearer insights across all your projects.
Security News
Multiple deserialization flaws in PyTorch Lightning could allow remote code execution when loading untrusted model files, affecting versions up to 2.4.0.
Security News
NVD now marks all pre-2018 CVEs as "Deferred," signaling it will no longer enrich older vulnerabilities, further eroding trust in its data.