Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Asyncer, async and await, focused on developer experience.

License

NotificationsYou must be signed in to change notification settings

fastapi/asyncer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Asyncer

Asyncer, async and await, focused on developer experience.

TestPublishCoveragePackage version


Documentation:https://asyncer.tiangolo.com

Source Code:https://github.com/fastapi/asyncer


Asyncer is a small library built on top ofAnyIO.

Asyncer has a small number of utility functions that allow working withasync,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 ofAsyncer is to improvedeveloper experience by providing better support forautocompletion andinline errors in the editor, andmore certainty that the code isbug-free by providing better support for type checking tools likemypy.

Asyncer also tries to improveconvenience and simplicity when working withasync codemixed with regularblocking code, allowing to use them together in a simpler way... again, under my verysubjective point of view.

🚨 Warning

This small library only exists to be able to use theseutility functions until (and if) they are integrated intoAnyIO.

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

Can I Use It?

Yes 🎉 (but continue reading).

You can use this and evaluate thelibrary 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.

Havetests for your project (as you should, anyway). Andupgrade the version once you know that the new version continues to work correctly.

Still, it'sjust 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 addasyncer 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

AsAsyncer is based onAnyIO it will be also installed automatically when you installAsyncer.

Installation

$pip install asyncer---> 100%Successfully installed asyncer anyio

How to Use

You can read more about each of the use cases and utility functions inAsyncer in thetutorial.

As a sneak preview of one of the utilities, you cancall sync code from async code usingasyncify():

importtimeimportanyiofromasyncerimportasyncifydefdo_sync_work(name:str):time.sleep(1)returnf"Hello,{name}"asyncdefmain():message=awaitasyncify(do_sync_work)(name="World")print(message)anyio.run(main)

Asyncer'sasyncify() will use AnyIO underneath to dothe smart thing, avoid blocking the mainasync event loop, and run thesync/blocking function in aworker thread.

Editor Support

Everything inAsyncer is designed to get the bestdeveloper experience possible, with the best editor support.

  • Autocompletion for function arguments:

  • Autocompletion for return values:

  • Inline errors in editor:

  • Support for tools likemypy, that can help you verify that yourcode is correct, and prevent many bugs.

License

This project is licensed under the terms of theMIT license.


[8]ページ先頭

©2009-2025 Movatter.jp