Async Python Patterns
Use when building or reviewing Python asyncio services, concurrent I/O, async APIs, background tasks, cancellation, or event-loop performance.
Install
npx skills add sandbaseai/workbuddy-skill --skill async-python-patternsgit clone --depth 1 https://github.com/sandbaseai/workbuddy-skill.git /tmp/workbuddy-skill
mkdir -p ~/.claude/skills
cp -r /tmp/workbuddy-skill/skills/async-python-patterns ~/.claude/skills/async-python-patternsPersonal skills live in ~/.claude/skills. Use .claude/skills in a project folder to share a skill with your team.
From the SKILL.md
# Async Python Patterns
用 `asyncio` 管理 I/O 并发,同时保持事件循环可响应、资源可回收、取消可传播、并发有上限。异步不是越多越好:CPU 密集任务、低并发脚本或阻塞 SDK 应选择同步、线程池或进程池,并用基线证明收益。
## 使用边界
- 开始前确认 Python/框架/依赖版本、调用链、并发量、deadline、资源配额、owner、SLO 和目标环境。
- 默认只读检查 coroutine、task、连接池、队列、超时、trace 和错误;在本地/预发布使用合成负载与受控故障。
- 不擅自修改生产并发、超时、线程/进程池、连接池、限流、流量或重启服务;这些变更需要授权和回滚方案。
- 日志、task 参数、异常和 trace 不得包含 token、完整 payload、个人信息或原始响应;使用脱敏摘要和受控 correlation ID。
## 同步/异步边界
多网络/数据库调用适合 asyncio;CPU 密集工作使用 `asyncio.to_thread`(阻塞但可释放事件循环)或进程池,并限制 worker。一个调用路径应有清晰的 sync/async 边界,不能在事件循环中执行 `time.sleep`、同步 HTTP/数据库客户端、重型序列化或无界文件操作。
每个外部调用都要有连接、读和总 deadline;每个 task 都说明 owner、结果、异常、取消和资源清理语义。优先使用 `async with`、`async for` 和结构化并发(如 `TaskGroup`,按 Python 版本确认行为)。
```python
import asyncio
async def fetch_bounded(items, client, *, limit=20):
semaphore = asyncio.Semaphore(limit)
async def one(item):
async with semaphore:
# The caller supplies a request deadline; no unbounded await.
return await client.fetch(item, timeout=5.0)
# Keep the result order and make the concurrency bound explicit.
return await asyncio.gather(*(one(item) for item in items))
```
## 并发、背压与结果
`gather`、task 集合、队列和连接池都必须有上限;不要一次为不受控输入创建百万个 task。生产者速度超过消费者时使用 `asyncio.Queue(maxsize=...)`、信号量或流式 `async for`,队列满时暂停、丢弃低优先级或快速失败,并返回明确状态。
决定失败策略:默认一个失败是否取消同组任务、是否收集部分结果、是否允许继续。不要用 `return_exceptions=True` 后静默过滤异常;逐项分类、记录受控上下文并为部分成功定义业务语义。对外部调用结合限流、指数退避+jitter、幂等键和总 deadline,避免并发重试放大。
## 取消、超时与清理Details
- Skill name
async-python-patterns- Repository
- sandbaseai/workbuddy-skill
- Path
skills/async-python-patterns/SKILL.md- License
- MIT
- Repo updated
- 8 September 2026
FAQ
What does the Async Python Patterns skill do?
Use when building or reviewing Python asyncio services, concurrent I/O, async APIs, background tasks, cancellation, or event-loop performance.
How do I install the Async Python Patterns skill?
skills CLI (Claude Code, Cursor, Codex and more): npx skills add sandbaseai/workbuddy-skill --skill async-python-patterns. Skills go in ~/.claude/skills (personal) or .claude/skills (project), and Claude loads them automatically when a task matches the description.
Is Async Python Patterns popular?
It lives in sandbaseai/workbuddy-skill, which has 9 GitHub stars and 3 forks.
Related skills
Access Control Security Best Practices
9sandbaseai/workbuddy-skill
Design, review, implement, and verify least-privilege access controls across users, services, tenants, resources, and administrative workflows.
Accessibility Review
9sandbaseai/workbuddy-skill
Use when reviewing a web interface or interaction for semantic, keyboard, focus, screen-reader, ARIA, and contrast accessibility risks.
Acquire Codebase Knowledge
9sandbaseai/workbuddy-skill
Use when the user asks to map, document, or onboard into an existing codebase and needs evidence-backed architecture, structure, conventions, integrations, testing, and concerns documentation.
Backend Review
9sandbaseai/workbuddy-skill
Use when reviewing backend handlers, services, jobs, persistence, validation, errors, transactions, dependencies, or service contracts for correctness and operational risk.
Architecture Patterns
9sandbaseai/workbuddy-skill
Use when designing or refactoring a backend module or service with Clean, Hexagonal, Onion, or Domain-Driven Design patterns; make boundaries, dependencies, ports, adapters, and test seams explicit before changing code.
Binary Analysis Patterns
9sandbaseai/workbuddy-skill
Use when performing authorized offline static analysis of a binary to understand architecture, control flow, data structures, and suspicious behavior without executing the sample or modifying a target system.
Browse the most popular Claude skills, all software development skills, or write your own with the skills generator.