Å·±¦ÓéÀÖ

Jump to ratings and reviews
Rate this book

Using Asyncio in Python: Understanding Python's Asynchronous Programming Features

Rate this book
If you're among the Python developers put off by Asyncio's complexity, it's time to take another look. Asyncio is complicated because it aims to solve problems in concurrent network programming for both framework developers and end-user developers like you. The features you need to consider are a small subset of the whole Asyncio API, but picking out the right features is the tricky part. That's where this practical book comes in.

Veteran Python developer Caleb Hattingh helps end-user developers gain a basic understanding of Asyncio's building blocks--enough to get you started writing simple event-based programs. You'll learn why Asyncio offers a safer alternative to preemptive multitasking (threading) and how this API provides a simple way to support thousands of simultaneous socket connections.


Get a critical comparison of Asyncio and threading for concurrent network programming
Take an Asyncio walkthrough, including a quickstart guide to help you hit the ground looping with event-based programming
Learn the difference between Asyncio features for end-user developers and those for framework developers
Understand Asyncio's new async/await language syntax, including coroutines and task and future APIs
Get detailed case studies (with code) of some popular Asyncio-compatible third-party libraries

156 pages, Paperback

Published February 18, 2020

41 people are currently reading
138 people want to read

About the author

Caleb Hattingh

3Ìýbooks4Ìýfollowers

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
22 (21%)
4 stars
38 (37%)
3 stars
36 (35%)
2 stars
4 (3%)
1 star
1 (<1%)
Displaying 1 - 21 of 21 reviews
Profile Image for Sebastian Gebski.
1,151 reviews1,260 followers
July 5, 2020
TBH:
1. The book doesn't shine when it comes to smoothly presenting & clarifying the asyncio concepts (personally I've benefitted from knowing async/await from .NET)
2. But if you manage through the initial struggle somehow, there's a lot of good content around - examples, accompanying libraries, detailed description on how asyncio works under the good

To summarize:
Such a book should have an onion-like composition. It should start with the most approachable basics and follow up with additional layers of complexity. Unfortunately, the idea here was different and it doesn't work very well. For me, it was enought to learn asyncio, but I had an additional, external practical experience that has helped a lot.
Profile Image for Matthew Balshaw.
155 reviews2 followers
August 29, 2022
I finally feel confident with event loop and the usage of asyncio after reading this short book.

Highly recommended if you have been struggling with event loop. The best takeaway was that the asyncio API has a readability problem that makes it very hard for a developer to understand it. The problem is that the API has to cater to framework developers as well as end user developers. The needs of a framework developer are much more complex and specific, but the flat hierarchy of the asyncio docs obscures this. This causes the regular developer who just wants to run things asynchronously to get easily confused when reading the docs (as I did!).

This book goes through the history and common real life use cases of asyncio and also provides some good event loop theory that makes it easier to grasp.
9 reviews
February 15, 2021
Could easily remove the chapter on 20 library recommendations which is like half the book. Also the metaphor about Thread Bots was bad.


I think a better book would dive a whole lot deeper:
- how are coroutines implemented?
- how does the event loop wake up a task?
- the c10k problem or the birth of event loops

Unfortunately, this book doesn’t cover anything missing in the documentation, but some of the ideas are more presentable.
Profile Image for Redowan Delowar.
46 reviews4 followers
April 3, 2021
I'm on my second pass through the book and just got reminded how good it actually is. It starts easy and lays out the basics first but quickly picks up the pace without beating around any bush. I'm keeping this as reference material until the API changes because�

1. The core material of the book is short, only 90 pages.

2. It Does a great job in differentiating and explaining the functions of the two major types of asyncio APIs—APIs targeted towards developers writing services and APIs targeted towards framework writers.

3. Talks about the difference between asyncio.create_task and low-level asyncio.ensure_future. The behavior of the latter seems to be a source of major confusion among developers trying out asyncio for the first time.

4. Talks about how to handle SIGINT and SIGTERM properly, it's inherently difficult to gracefully handle interrupt and terminate signals in concurrent I/O programming.

5. Before Python 3.9, asyncio.run didn't wait for futures created by loop.run_in_executor(). So the book presents a good workaround.
Profile Image for Nick Groenen.
2 reviews
September 13, 2021

’s official documentation on the historically didn’t do a great job of distinguishing between end-user goals and goals for library/framework authors. This has made it harder and more confusing for people to get started writing async Python because the functions and methods you have to know about as an end-user are only a small subset of the entire asyncio API.


This book does a good job explaining these concepts for end-users. It includes a number of examples/case studies which demonstrate how traditional threads-based applications could be written with asyncio instead.


When I read this book I was already familiar with async concepts from other languages/runtimes, which made this a breezy read that quickly got me familiar with the main concepts the way they are implemented in Python.


Because of this, to me personally it also felt longer that it needed to be while simultaneously lacking a bit of depth. For example, I would have loved more of a look into handling timeouts as well as .


I recognize that I’m at the fringes of the book’s intended target audience, but it does make the list price ($44.99) feel rather steep for what you get in terms of content.


There’s a few gems in here about known pitfalls and often-misunderstood methods, but a part of me can’t help but wonder what would have happened if some of the effort that went into this book was instead put into improving Python’s official documentation on the asyncio module itself.

116 reviews
August 23, 2020
I’m kinda lying by saying that I read the book in a day. This is my second attempt at reading the book, the first attempt ended when I developed a headache trying to understand the concepts in the book.

This time, I was slightly better prepared in terms of the vocabulary used in the book and I also coded along - which improved my understanding tremendously.

I confess that I flipped through the �20 asyncio libraries you should be using� chapter but it looks interesting.

Overall, I’m very happy with the content in the book and the approach the author takes to explain those contents.
Profile Image for Rahul Salgare.
6 reviews
October 6, 2023
Start was promising and built a clear understanding on the concurrency part of python with the analogy of threadbots, however the main chapter of asyncio failed to build the intution. It was just sample codes explained with steps. It would have been good if more emphasis was given on internal working, execution flow. though case study has some good examples to practice.
Overall its a good read, but not a final one on python asyncio
Profile Image for Michael.
113 reviews5 followers
August 28, 2021
Before reading the book, I saw await and async in python code and scratched my head
After reading the book, I understand the concept and will be applying it in my own work.

I think the material probably could have been presented more clearly but the fact is it succeeded with me. So thanks Caleb!
Profile Image for Bruce Lowther.
23 reviews
March 20, 2022
Thin volume but densely packed with information and examples of asyncio code. Very timely for me. Will probably read through it several more times in the next few months to extract more information from it.
The packages referenced are evolving rapidly so i’m not sure that this volume will she well. I would probably look for a “revised and extended� volume before too long.
Profile Image for Maxim.
33 reviews1 follower
August 22, 2020
4.5 / 5

I liked it.

It's a very good overview of async-related built-in features and third-party libraries.

The book is not for beginners, though.
43 reviews
September 8, 2020
Good, with plenty code examples, but felt it was rather abrupt and could have delved a bit deeper at times.
Profile Image for Ali Zafari.
32 reviews10 followers
December 18, 2020
Explanation of the async-programming in python gets really confusing in the 3rd chapter. Maybe the author assumes a higher level of familiarity than being just a beginner.
Profile Image for Warren Cheng.
10 reviews2 followers
February 15, 2021
hands down, easier to read than the official doc.
for application developers who already hav knowledge in threading, coroutines, and async programming
37 reviews4 followers
February 24, 2021
Must read if you want to get a good understanding of how python's asyncio framework is put together. Excellent organization and explanation of the various components.
Profile Image for Vladislav Ladenkov.
12 reviews
March 26, 2022
One of the best technical books, I've seen. It doesn't contain water - chapters are small, giving concept, giving details and examples, which are, imho, perfect. Strong recommend.
7 reviews
March 24, 2023
great introduction to python asyncio world, especially the first half
1 review
December 30, 2020
Terrible collection of random thoughts. The author has no clue what asyncio is, and clearly has no experience in clearly communicating ideas.
Profile Image for ZeV.
185 reviews21 followers
August 7, 2020
I have read the previous edition of which this version obsoletes, and it is nice that the coverage extends to Python 3.8 in which the asyncio interface has even more stabilized.

The target audience is someone who has some experience in threading (or multiprocessing) already, and who wants to do async programming as an end-user developer (but not as a framework developer). The author starts by comparing the pre-emptive threading and asynchronous programming paradigms. It probably won't make much sense if you have no experience in either of these.

Unfortunately, code examples have a couple of bugs and indentation inconsistencies. You may need Docker for setting up a couple of experiments; you might run into issues running example programs otherwise.

Overall it is a good introduction to async programming for relatively experienced Python programmers. The author does a good job of extracting the gist of how to use asyncio tools. It would have been more useful if the introduction extended to how to write unit tests and such.
Profile Image for ZeV.
185 reviews21 followers
June 25, 2020
I'm fairly experienced with threading in Python using the threading and gevent modules and whatnot but have been hesitant to pick up asyncio. Using Asyncio in Python 3 is a great introductory book for someone in that position, as it thoroughly evaluates the pros and cons of threading versus asynchronous programming and makes it very clear why the latter is desired in some cases.

The only issue, if I nitpick, would be that the book was written before Python 3.7 and some features are already becoming obsolete. The author is aware of this and does correctly mention what to expect in that future version, so it is still a minor issue. Overall, the book is a great resource for picking up asyncio as a library user (though not so much as a library writer). The code examples are self-contained with good style and it touches on how to test code using asyncio, which is definitely a plus.

Am I excited to jump on the bandwagon? Not really (LOL), but I am glad that I'm exposed to the style of programming as more Python code becomes asyncio-aware. It is officially part of the language, so the chances are that I will need to deal with them at some point.
Profile Image for Vlad Bezden.
230 reviews12 followers
July 10, 2018
Great book, very informative with all you need to know about asyncio in Python.
It is a first book that provides such great detail about asyncio. It covers all aspects of asyncio. I wish it covered Python 3.7.
Displaying 1 - 21 of 21 reviews

Can't find what you're looking for?

Get help and learn more about the design.