Develop Responsive Python Programs, Once You Learn Asyncio
Imagine developing Python programs that scaled to as many as 10,000+ concurrent tasks (and much more).
Don’t study asyncio the wrong way, waste months of your time, then give up in frustration
If you can invest as little as one hour per day, then in one week you will know how to confidently bring asynchronous programming to your current and future projects.
Convinced? Jump to the book, otherwise read on…
Asyncio provides modern asynchronous programming in Python.
Asynchronous programming is a popular programming paradigm that allows a vast number of lightweight tasks to run concurrently with very little memory overhead, compared to threads.
The beauty is that this capability is available in Python today, thanks to recent changes to the language and the "asyncio" module added to the standard library.
And there's nothing extra to install. All of this has been available since Python 3.5, released in 2015.
The problem is few Python developers know how to use it, and even fewer know how to study it the right way.
Writing asyncio programs is different from writing regular Python programs.
You cannot just sprinkle coroutines into your program like you can with threads.
If you do, you will fail.
- You will call a coroutine like a function and nothing will happen.
- Your program will generate all kinds of warnings.
- You won't know how to allow coroutines to cooperate when executing concurrently.
You need to flip things on their head.
You must start with asyncio in mind, then design your program.
Take an "async-first" Approach
To be successful with asyncio, you need to do 2 things:
- 1) You must start with the asynchronous programming paradigm in mind from the beginning.
This means knowing that an event loop is going to be the heart of your program and will drive the execution of coroutines.
- 2) You must develop your tasks around coroutines.
This means you need to know how and when tasks will suspend, allowing other tasks to run, and what legacy tasks might block the event loop and need to be dispatched to threads or processes.
After the basics, you then need to know the asyncio API.
And this is where most (almost all) Python developers trying to learn asyncio fail.
The Mistakes Python Developers Make When Learning Asyncio
(and how you're going to avoid them)
When learning something new in Python, we hit the API documentation.
The Python API docs are pretty good. They tell you how to use each class and function.
But, they give you no idea of which function and class to use, or when.
If you set yourself the mission of figuring out asyncio and coroutines from the API docs, then you will lose 6 months of your time. Easy.
Trust me, I did exactly that.
The standard library docs are excellent, once you already know how to develop asyncio programs.
- The docs will not teach you about asynchronous programming.
- The docs won't teach you about the new coroutine type.
- The docs won't show you the new expressions built into the language.
- The docs won't give you ideas of when to use the various API capabilities.
And fair enough. It's not the job of API docs to do this.
It's worse still.
The biggest problem of all is that the API docs describe two asyncio APIs.
- A low-level asyncio API, intended for framework and library developers.
- A high-level asyncio API, built on top of the low-level API, intended for application developers (like you and me).
The demarcation between the two APIs is not always clear and obvious. And the APIs did change a lot before they finally stabilized into their current form.
As such, the vast majority of asyncio examples you find around the web (and in other books) will use the low-level API mixed in with the high-level API.
For example, if you see code utorials throwing around a "loop" variable, run away. You almost never need to interact with the event loop directly.
And everyone is copying everyone, propagating this terrible practice.
This makes the asyncio API harder to understand for beginners.
It makes the code more verbose and ultimately causes frustration.
No wonder hoards of developers rage quit asyncio completely.
Skip the Pain and Frustration
(jump straight to getting results)
Don't worry, I figured it out for you.
Firstly, you need a solid idea of asynchronous programming, what it's for, and how it's related and different to concurrency with threads and processes.
You need to know what non-blocking I/O is and why we call it asynchronous I/O.
You need to know when to use asynchronous programming on a project, and when not.
You need to know that asynchronous tasks are not limited to non-blocking I/O, that any concurrent program developed with threading or multiprocessing can be developed with asyncio, and vice-versa.
You need to know what a coroutine is, how to define, create and run one, and how multiple coroutines can cooperate.
You then need to know how to drive the high-level asyncio API to develop asynchronous programs in Python.
As I said, it can take months to figure this all out.
I know, I did exactly that.
I wrote 70+ tutorials along the way.
Then I distilled down the absolute most important details and hard-earned knowledge into my new book.
Python Asyncio Jump-Start
"Python Asyncio Jump-Start" is my new book that will teach you how to develop asyncio programs in Python, from scratch.
This book distills only what you need to know to get started and be effective with asyncio, super fast.
It's exactly how I would teach you asyncio if we were sitting together, pair programming.
- 7 lessons taught by example with full working code listings.
- 27 .py code files included that you can use as templates
- 131 pages for on-screen reading open next to your editor.
- 2 formats (PDF and EPUB) for screen, tablet, and kindle reading.
- 3 megabyte .zip download that contains the ebook and all source code.
"Python Asyncio Jump-Start" will lead you on the path from a Python developer interested in asyncio to a developer that can confidently develop asyncio programs.
- No fluff.
- Just concepts and code.
- With full working examples.
The book is divided into 7 lessons.
The idea is you can read and work through one lesson per day, and become capable in one week.
It is the shortest and most effective path that I know of transforming you into an asyncio Python developer.
Choose your package:
You get the book:
- Asyncio Jump-Start
PDF and EPUB formats
Includes all source code files
You get all 7 books:
- Threading Jump-Start
- Multiprocessing Jump-Start
- Asyncio Jump-Start
- ThreadPool Jump-Start
- Pool Jump-Start
- ThreadPoolExecutor Jump-Start
- ProcessPoolExecutor Jump-Start
(that is a 9.52% discount)
You get everything (14+ books):
- Threading Jump-Start
- Multiprocessing Jump-Start
- Asyncio Jump-Start
- ThreadPool Jump-Start
- Pool Jump-Start
- ThreadPoolExecutor Jump-Start
- ProcessPoolExecutor Jump-Start
- Threading Interview Questions
- Multiprocessing Interview Questions
- Asyncio Interview Questions
- Executors Interview Questions
- Concurrent File I/O
- Concurrent NumPy
- Python Benchmarking
Bonus, you also get:
- Concurrent For Loops Guide
- API Mind Maps (4)
- API Cheat Sheets (7)
That is $184 of Value!
(you get a 8.74% discount)
All prices are in USD.
See What Customers Are Saying:
great read… quick to comprehend
I enjoyed the book. The chapters are succinct and to the point. The chapter on collections of tasks was by far the best I’ve read on the subject.
A really good introduction to Python parallel processing on the right technical level.
The SuperFastPython series was exactly what I needed. The information was concise. I was able to understand things much quicker than any other lesson, tutorial, or resource I’d used before. I worked through a lot of the problems I had in the past with my particular use-case and also discovered some things just weren’t possible unless I wanted to recode the dependencies.
I was able to test it and double my speed compared to the BEST results of my past concurrency and async approaches.
Clear. Insightful. Helped me develop from scratch a fully async system used in production
Greatly eases the learning curve for multitasking in Python
ASYNCIO is one Python subsystem for simple multitasking. I wouldn’t classify this library as fully mature and I was struggling greatly to absorb the concepts behind the function calls. I also found it difficult to get the function call syntax right without a bunch of trial-an-error.
I realized that at some point I would need to move some of my tasks to different multi-tasking subsystems. I’d been using the author’s web site for help and discovered the book set. It has provided me with both perspective and practical application of ASYNCIO.
If you don’t have a lot of time to waste learning about this topic and you aren’t into pain, I’d recommend the book set. Well worth the money for me.
The whole series of books from Jason is really good. All concepts are well explained, he goes in-depth with clear examples.
I succeed to faster my code using of Process pool 2.3 times. After some additional optimization I have succeed to speed up to 10 times.
You Get 7 Laser-Focused Lessons
This book is designed to bring you up to speed with how to use asyncio fast and thoroughly.
It is laser-focused on teaching you two things:
- The new coroutine language features in Python.
- The high-level API in the standard library for application developers.
The structure of the book is a course with 7 lessons.
- Lesson 01: Asyncio Concurrency
- What are Coroutines
- What is Asynchronous Programming
- Welcome to Asyncio
- Asyncio Hello World Example
- When to Use Asyncio
- Lesson 02: Coroutines and Tasks
- How to Create and Run Coroutines
- How to Create and Run Tasks
- How to Use Asyncio Tasks
- Lesson 03: Collections of Tasks
- How to Run Many Tasks as a Group
- How to Wait for Many Tasks
- How to Wait for a Task With a Timeout
- How to Handle Tasks in Completion Order
- How to Run Blocking Tasks
- Lesson 04: Iterators, Generators, and Context Managers
- How to Use Asynchronous Iterators
- How to Use Asynchronous Generators
- How to Use Asynchronous Context Managers
- Lesson 05: Queues and Synchronization Primitives
- What is Coroutine-Safe
- How to Share DataBetweek Coroutines with Queues
- How to Protect Critical Sections with a Mutex Lock
- How to Limit Access to a Resource with a Semaphore
- How to Signal Between Coroutines Using an Event
- How to Coordinate Using a Condition Variable
- Lesson 06: Subprocesses and Streams
- How to Run Commands in Subprocesses
- How to Use Non-Blocking I/O Steams
- Lesson 07: Port Scanner Case Study
- Develop an Asyncio Port Scanner
- How to Open a Socket Connection on a Port
- How to Scan a Range of Ports on a Server (slow)
- How to Scan Ports Concurrently (fast)
- How to Report Scan Results Dynamically
Next, let's look at the structure of each lesson.
Highly-structured lessons on how you can get results
Each lesson has two main parts, they are:
- 1) The lesson body that teaches the concepts and working code examples.
- 2) The lesson review that summarizes what was learned with exercises.
The body of the lesson will introduce a topic with code examples, whereas the lesson overview will review what was learned with exercises and links for further information.
Each lesson has a specific learning outcome and is designed to be completed in about one hour.
Each lesson is also designed to be self-contained so that you can read the lessons out of order if you choose, such as dipping into topics in the future to solve specific programming problems.
We Python developers learn best from real and working code examples. So each lesson has multiple large worked examples with sample output.
Next, let's look at what you will know after finishing the book.
Your Learning Outcomes
Transform from "python developer" into "Python developer that can create scalable and responsive programs using asynchronous programming"
After working through all of the lessons in this book, you will know:
- How to define, create, and run coroutines and how to use the async/await expressions.
- How to create asynchronous tasks, query their status, cancel them and add callback functions.
- How to run many coroutines concurrently in a group and handle their results.
- How to wait for many coroutines to complete, meet a condition, or timeout.
- How to define, create and use asynchronous iterators, generators, and context managers.
- How to use the "async for" and "async with" expressions in asyncio programs.
- How to synchronize and coordinate coroutines with locks, semaphores, events, and condition variables.
- How to share data between coroutines using coroutine-safe queues.
- How to run, read, and write from subprocesses and streams with coroutines.
- How to develop a concurrent and dynamically updating port scanner using non-blocking I/O.
You will learn from code examples, not pages and pages of fluff.
Get your copy now:
100% Money-Back Guarantee
(no questions asked)
I want you to actually learn asyncio so well that you can confidently use it on current and future projects.
I designed my book to read just like I'm sitting beside you, showing you how.
I want you to be happy. I want you to win!
I stand behind all of my materials. I know they get results and I'm proud of them.
Nevertheless, if you decide that my books are not a good fit for you, I'll understand.
I offer a 100% money-back guarantee, no questions asked.
To get a refund, contact me with your purchase name and email address.
Frequently Asked Questions
This section covers some frequently asked questions.
If you have any questions. Contact me directly. Any time about anything. I will do my best to help.
What are your prerequisites?
This book is designed for Python developers who want to discover how to use and get the most out of asyncio.
Specifically, this book is for:
- Developers that can write simple Python programs.
- Developers that need better performance from current or future Python programs.
- Developers that want to learn asynchronous programming in Python.
This book does not require that you are an expert in the Python programming language or concurrency.
- You do not need to be an expert Python developer.
- You do not need to be an expert in concurrency.
What version of python do you need?
All code examples use Python 3.
Python 3.9+ to be exact.
Python 2.7 is not supported because it reached its "end of life" in 2020.
Are there code examples?
There are 26 .py code files.
Each lesson has one or more complete, standalone, and fully-working code examples.
The book is provided in a .zip file that includes a src/ directory containing all source code files used in the book.
How long will the book take you to finish?
About 1 hour per lesson.
Work at your own pace.
I recommend 1 lesson per day, over 7 days (1 week).
There's no rush and I recommend that you take your time.
The book is designed to be read linearly from start to finish, guiding you from being a Python developer at the start of the book to being a Python developer that can confidently use asyncio in your projects by the end of the book.
In order to avoid overload, I recommend completing one lesson per day, such as in the evening or during your lunch break. This will allow you to complete the transformation in about one week.
I recommend you maintain a directory with all of the code you type from the lessons in the book. This will allow you to use the directory as your own private code library, allowing you to copy-paste code into your projects in the future.
I recommend trying to adapt and extend the examples in the lessons. Play with them. Break them. This will help you learn more about how the API works and why we follow specific usage patterns.
What format is the book?
You can read the book on your screen, next to your editor.
You can also read the book on your tablet, away from your workstation.
The ebook is provided in 2 formats:
- PDF (.pdf): perfect for reading on the screen or tablet.
- EPUB (.epub): perfect for reading on a tablet with a Kindle or iBooks app.
Many developers like to read technical books on their tablet or iPad.
How can you get more help?
The lessons in this book were designed to be easy to read and follow.
Nevertheless, sometimes we need a little extra help.
A list of further reading resources is provided at the end of each lesson. These can be helpful if you are interested in learning more about the topic covered, such as fine-grained details of the standard library and API functions used.
The conclusions at the end of the book provide a complete list of websites and books that can help if you want to learn more about Python concurrency and the relevant parts of the Python standard library. It also lists places where you can go online and ask questions about Python concurrency.
Finally, if you ever have questions about the lessons or code in this book, you can contact me any time and I will do my best to help. My contact details are provided at the end of the book.
How many pages is the book?
The PDF is 131 US letter-sized pages.
Can you print the book?
Although, I think it's better to work through it on the screen.
- You can search, skip, and jump around really fast.
- You can copy and paste code examples.
- You can compare code output directly.
Is there digital rights management?
The ebooks have no DRM.
Do you get free updates?
Each time I release an updated version, I will send you an email with a link so that you can download the latest version for free.
You can also email me any time and I will send you the latest version.
Can you buy the book elsewhere?
You can get a kindle or paperback version from Amazon.
Many developers prefer to buy from the kindle store on amazon directly.
In fact, the book was the #1 new release in its category shortly after its release.
Can you get a paperback version?
You can get a paperback version from Amazon.
Below is a photo of me holding the paperback edition of the book.
Can you read a sample?
You can read a book sample via google books "preview" or via the amazon "look inside" feature:
Generally, if you like my writing style on SuperFastPython, then you will like the books.
Can you download the source code now?
The source code (.py) files are included in the .zip with the book.
Nevertheless, you can also download all of the code from the dedicated GitHub Project:
Does asyncio work on your operating system?
Python concurrency is built into the Python programming language and works equally well on:
Does asyncio work on your hardware?
Python concurrency is agnostic to the underlying CPU hardware.
If you are running Python on a modern computer, then you will have support for concurrency, e.g. Intel, AMD, ARM, and Apple Silicon CPUs are supported.
How does the "Jump-Start Book" compare to the "Complete Guides"?
The SuperFastPython Jump-Start books are laser-focused on making you productive with a Python concurrency module or class as fast as possible.
This means that many broader topics are not covered because they are not on the critical path.
The guides on SuperFastPython.com are broader in scope and compare the class or module to related modules, describing best practices, common errors, common usage questions, and common objects.
This material may be interesting but is a distraction when you are focused on getting productive as fast as possible.
Another important difference is that the jump-start books are provided in book form, whereas the guides are very long web pages.
This makes the books easy to read on a kindle, tablet, or paperback, as well as the screen, whereas the guides must be read in the browser.
About the Author
Hi, I'm Jason Brownlee, Ph.D.
I'm a Python developer, husband, and father to two boys.
I want to share something with you.
I am obsessed with Python concurrency, but I wasn't always this way.
My background is in Artificial Intelligence and I have a few fancy degrees and past job titles to prove it.
You can see my LinkedIn profile here:
- Jason Brownlee LinkedIn Profile
(follow me if you like)
Well, AI and machine learning has been hot for the last decade. I have spent that time as a Python machine learning developer:
- Working on a range of predictive modeling projects.
- Writing more than 1,000+ tutorials.
- Authoring over 20+ books.
There's one thing about machine learning in Python, your code must be fast.
Modeling code is already generally fast, built on top of C and Fortran code libraries.
But you know how it is on real projects…
You always have to glue bits together, wrap the fast code and run it many times, and so on.
Making code run fast requires Python concurrency and I have spent most of the last decade using all the different types of Python concurrency available.
Including threading, multiprocessing, asyncio, and the suite of popular libraries.
I know my way around Python concurrency and I am deeply frustrated at the bad wrap it has.
This is why I started SuperFastPython.com where you can find hundreds of free tutorials on Python concurrency.
And this is why I wrote this book.
Praise for Super Fast Python
Python developers write to me all the time and let me know how helpful my tutorials and books have been.
Below are some select examples posted to LinkedIn.
What Are You Waiting For?
Stop reading outdated StackOverflow answers.
Learn Python concurrency correctly, step-by-step.
Buy now and get your copy in seconds!