Skip to main content

Asyncer, async and await, focused on developer experience.

Project description

Asyncer

Asyncer, async and await, focused on developer experience.

Test Publish 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.

🚨 Warning

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

Can I Use It?

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

Requirements

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

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

asyncer_slim-0.0.8.tar.gz (18.2 kB view details)

Uploaded Source

Built Distribution

asyncer_slim-0.0.8-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file asyncer_slim-0.0.8.tar.gz.

File metadata

  • Download URL: asyncer_slim-0.0.8.tar.gz
  • Upload date:
  • Size: 18.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for asyncer_slim-0.0.8.tar.gz
Algorithm Hash digest
SHA256 15f19c48b65ad85f3ccd5d7fef2b54bfb7bf1cf657b3070afb81f890003be126
MD5 b1079ce14fc639974f1174332b044c94
BLAKE2b-256 b502682c7905e37dceaa8b5b1fd2fefe9f62fbefe527e5b51014d3001ec661d5

See more details on using hashes here.

File details

Details for the file asyncer_slim-0.0.8-py3-none-any.whl.

File metadata

  • Download URL: asyncer_slim-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for asyncer_slim-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 cc593bc9b5d0ad6e0dd46a9bb22ef6676a40fc280e45f22c7d762eebd3e1ca2d
MD5 7ac84c6ebff5a0b716ac514afe524ea4
BLAKE2b-256 59e15a579dc5a01c4a62260d94267679e2833b659becc90a14f88a5e464e257e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page