Introducing Quattro - simple structured concurrency for asyncio

I realized I haven’t announced Quattro here yet, so here goes.

Quattro is a small library for structured concurrency in asyncio. Here’s the repo: GitHub - Tinche/quattro: Better control of your asyncio tasks. I wrote it because I needed it myself.

It contains a TaskGroup implementation originally written by @yselivanov 's team for the EdgeDB project, and some context managers (fail_after, move_on_after) I’ve modeled after Trio’s. I’ve added tests (in the case of the TaskGroup, just ported them to pytest) and type information for all of these. After TaskGroups are added to Python proper, this can serve as a backport.

You might be wondering why use Quattro when anyio exists. The anyio project is extremely ambitious (trying to establish an entire new ecosystem with a number of supporting libraries), and this has implications:

  • you need to learn it, and train your team to use it
  • I have doubts about it’s maturity; I think the developers behind it are tremendously talented but the scope of the project has its cost

Compared to it, Quattro has 260 lines of code, and you can install it and just start using it somewhere in an existing asyncio app without a large shift in focus. I’ve found getting a team on board using anyio requires a lot of preparation; with Quattro you don’t have to go into details of Curio, Trio, the concepts of structured concurrency, and finally anyio. You can just show people to use a TaskGroup if they don’t want to leak tasks.

anyio does quite a bit more; probably the biggest difference is Trio’s level-based cancellation. My personal opinion is that in practice it’s a red herring - the added complexity it costs isn’t worth the relatively small benefits. It’s a better system, yeah, but not that much better. I don’t think Quattro will ever match it, and that’s kind of the point.

Quattro is very early still, with only a v0.3 out, but I encourage you to give it a try.

4 Likes