python-async-patterns

Solid

Python asyncio patterns for concurrent programming. Triggers on: asyncio, async, await, coroutine, gather, semaphore, TaskGroup, event loop, aiohttp, concurrent.

AI & Automation 335 stars 29 forks Updated today

Install

View on GitHub

Quality Score: 85/100

Stars 20%
84
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
80
License 10%
0
Description 5%
100

Skill Content

# Python Async Patterns Asyncio patterns for concurrent Python programming. ## Core Concepts ```python import asyncio # Coroutine (must be awaited) async def fetch(url: str) -> str: async with aiohttp.ClientSession() as session: async with session.get(url) as response: return await response.text() # Entry point async def main(): result = await fetch("https://example.com") return result asyncio.run(main()) ``` ## Pattern 1: Concurrent with gather ```python async def fetch_all(urls: list[str]) -> list[str]: """Fetch multiple URLs concurrently.""" async with aiohttp.ClientSession() as session: tasks = [fetch_one(session, url) for url in urls] return await asyncio.gather(*tasks, return_exceptions=True) ``` ## Pattern 2: Bounded Concurrency ```python async def fetch_with_limit(urls: list[str], limit: int = 10): """Limit concurrent requests.""" semaphore = asyncio.Semaphore(limit) async def bounded_fetch(url): async with semaphore: return await fetch_one(url) return await asyncio.gather(*[bounded_fetch(url) for url in urls]) ``` ## Pattern 3: TaskGroup (Python 3.11+) ```python async def process_items(items): """Structured concurrency with automatic cleanup.""" async with asyncio.TaskGroup() as tg: for item in items: tg.create_task(process_one(item)) # All tasks complete here, or exception raised ``` ## Pattern 4: Timeout ```python async def wit...

Details

Author
aiskillstore
Repository
aiskillstore/marketplace
Created
5 months ago
Last Updated
today
Language
Python
License
None

Similar Skills

Semantically similar based on skill content — not just same category