This repository collects tiny, focused scripts I wrote while learning how Python's asyncio machinery fits together. Each numbered file is a self-contained example that adds one new idea on top of the previous ones, so you can read them in order or jump to the topic you care about.
- Python 3.10 or newer (for
asyncio.runandasyncio.to_thread) pipfor installing extras
python -m venv .venv
source .venv/bin/activate # Windows: .venv\\Scripts\\activate
pip install --upgrade pip
pip install aiohttpOnly 06.py needs the aiohttp dependency and an internet connection. The other scripts run with the Python standard library alone.
Execute the script you want to explore with the Python interpreter:
python 01.pyReplace 01.py with any of the other files. The modules are independent, so you can run them in any order.
01.py– Smallest possible coroutine: await a sleep and see the event loop in action.02.py– Run two coroutines concurrently withasyncio.gather.03.py– Compare sequentialawaits versus parallel gathering while timing both approaches.04.py– Collect coroutine return values fromasyncio.gatherto build a result list.05.py– Mix long-running background tasks with user input usingasyncio.create_taskandasyncio.to_thread.06.py– Make concurrent HTTP requests withaiohttpand inspect partial responses.
Feel free to experiment by modifying the delays, adding error handling, or extending the patterns with your own async functions. Happy hacking!