# Python Async Patterns

> Use when implementing async Python patterns.

- Skill: `loopyluci/python-async-patterns` (Agent Skill)
- Install (CLI): `npx skillmds@latest add loopyluci/python-async-patterns`
- Raw SKILL.md: https://api.skillmd.com/api/skills/loopyluci/python-async-patterns/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- License: MIT
- Author: LoopyLuci (https://skillmd.com/u/loopyluci)
- Updated: 2026-09-08
- Page: https://skillmd.com/skills/loopyluci/python-async-patterns

---


# Python Async Patterns

Implementing async Python — from asyncio patterns through concurrency, async context managers, and async generators.

## When to Use

- Writing async Python code
- Managing asyncio tasks and event loops
- Building async APIs and data pipelines

## Async Patterns

```python
import asyncio

async def fetch_all(urls):
    async with aiohttp.ClientSession() as session:
        tasks = [fetch_one(session, url) for url in urls]
        return await asyncio.gather(*tasks)

class AsyncCounter:
    """Async context manager pattern."""
    def __init__(self, limit): self.limit = limit
    async def __aenter__(self): return self
    async def __aexit__(self, *e): await self.close()
    async def close(self): pass
```

## Verification Checklist

- [ ] Async context managers for resources
- [ ] Task groups for structured concurrency (Python 3.11+)
- [ ] asyncio.gather with return_exceptions=True
- [ ] Semaphore for limiting concurrent tasks
- [ ] Proper cancellation handling

