📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials Python from Zero Async / Await

Async / Await

7 min read
async/await runs multiple I/O tasks concurrently in a single thread. Define coroutines with async def and wait for them with await. Use asyncio.gather() to run multiple tasks at the same time.

Async Python

import asyncio
import aiohttp

async def fetch(url):
    async with aiohttp.ClientSession() as session:
        async with session.get(url) as res:
            return await res.text()

async def main():
    urls = ["https://example.com", "https://httpbin.org"]
    tasks = [fetch(url) for url in urls]
    results = await asyncio.gather(*tasks)
    print(results)

asyncio.run(main())