MIT License

项目介绍

fastapi/asyncer 是一个托管在 GitHub 上的开源项目,主要使用 Python 编写,采用 MIT License 许可证,目前获得 2.5k 个 Star、88 次 Fork。

仓库全名
fastapi/asyncer
开源许可证
MIT License
Star 数
2.5k
Fork 数
88
未关闭 Issue
1

README 摘要

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…

完整内容见 GitHub 原始 README 或本页 。

常见问题

asyncer 用什么语言开发?

主要使用 Python 编写,采用 MIT License 许可证,目前有 2.5k 个 Star。

asyncer 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 asyncer 的源码?

可以直接克隆仓库:git clone https://github.com/fastapi/asyncer.git,默认分支为 main;安装与运行步骤见仓库 README。

asyncer 最近还在维护吗?

仓库最近一次更新为 4 天前,当前有 1 个未关闭 Issue;Star 数为 2.5k,可作为社区活跃度的参考。

简要分析

热度分
2695
价值分
1531
活跃状态
活跃

README

Asyncer

Asyncer, async and await, focused on developer experience.

Test Coverage Package version


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.

Can I Use It?

Yes 🎉 (but continue reading).

This is a very small library, there are things that can change and improve in the future.

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).

Requirements

As Asyncer is based on AnyIO it will be also installed automatically when you install Asyncer.

Installation

First, install uv, and then add Asyncer to your project:

$ uv add asyncer
---> 100%

If you prefer to use pip, install asyncer inside a virtual environment. See the installation guide for the alternative steps.

How to Use

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.

Editor Support

Everything in Asyncer is designed to get the best developer experience possible, with the best editor support.

  • Autocompletion for function arguments:
  • Autocompletion for return values:
  • Inline errors in editor:
  • Support for tools like mypy, that can help you verify that your code is correct, and prevent many bugs.

License

This project is licensed under the terms of the MIT license.

评论

暂无评论