AsyncIO
charlesleifer.com
charlesleifer.com
I love async Python.
It solves an entire class of problems really nicely, and makes certain types of applications possible.
Once you've got your head around it - and that is not easy especially if you have not done much JavaScript - then it's almost magical.
For database access you can use asyncpg which is natively written as async. asyncpg is the fastest Python driver and faster than anything implemented on psycopg2.
https://magicstack.github.io/asyncpg/current/
Huzzah for async Python!
Having decided that async is appropriate, the question is how you express that in a language or framework. I've used several approaches, from the magical "don't worry about it we'll just make it work for you" type of approach that he seems to advocate with gevent, to things like the callback-based approach of old Twisted (back in the days that python was a scrappy little upstart rather than this globally ubiquitous language). They are all equivalent from the machine's point of view more or less, but I find the async model easier to reason about and therefore easier to debug. This seems largely a question of taste. It's absolutely not the case that (as the author claims) the async versions of libraries are literally the same with just the word 'async' added into the function definitions. To take synchronous code and make it async, you have to reason about where your program spends its time, what parts of computation you can put into a future vs which parts belong in a seperate task etc. You can't just 's/def/async def/' add a few "awaits" and you're done.
asyncio is fun to play with, but it is a menace to any production level project