async-python-patterns

Implement asyncio concurrency patterns for non-blocking Python applications.

Updated Apr 13, 2026
One-click install
npx skills add https://github.com/scoots31/engineering-playbook --skill async-python-patterns-scoots31
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: async-python-patterns
Source: https://github.com/scoots31/engineering-playbook/tree/main/references/async-python-patterns
Command: npx skills add https://github.com/scoots31/engineering-playbook --skill async-python-patterns-scoots31

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires aiohttp, httpx, pytest-asyncio.

What problem does it solve? Writing concurrent Python code that handles many I/O operations without blocking is error-prone, and developers often struggle with event loops, task management, and mixing sync and async code correctly. ## Core Features & Use Cases - Concurrency Patterns: Provides ready-to-use patterns for gather(), task creation, semaphores, locks, queues, and producer-consumer workflows. - Real-World Examples: Includes implementations for web scraping with aiohttp, async database operations, WebSocket servers, and rate-limited API calls. - Pitfall Guidance: Covers common mistakes like blocking the event loop, forgetting await, and improper cancellation handling, plus testing with pytest-asyncio. - Use Case: When building a FastAPI service that must call 20 external APIs per request, use the semaphore rate-limiting pattern to run requests concurrently without overwhelming downstream services. ## Quick Start Ask the assistant to show you how to fetch multiple URLs concurrently using asyncio and aiohttp with rate limiting.

Frequently Asked Questions about async-python-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I run multiple async tasks concurrently in Python?

Use asyncio.gather() to run multiple coroutines concurrently and collect their results as a list. For long-running work, create tasks with asyncio.create_task() and await them when needed.

How do I limit concurrent requests with asyncio?

Use asyncio.Semaphore to cap concurrency. Wrap each operation in 'async with semaphore' so only a fixed number of tasks run simultaneously, which is ideal for rate-limited API calls.

When should I use asyncio vs multiprocessing in Python?

Use asyncio for I/O-bound work like network and database calls, and multiprocessing for CPU-bound computation. For mixed workloads, offload CPU work with asyncio.to_thread() or run_in_executor().

Can I call a synchronous library inside async code?

Yes, wrap blocking calls with asyncio.to_thread() in Python 3.9+ or loop.run_in_executor() for older versions. Calling blocking code directly stalls the entire event loop and all concurrent tasks.

Why does my async code block the event loop?

Blocking happens when synchronous calls like time.sleep() or requests.get() run inside a coroutine. Replace them with asyncio.sleep() and async-native libraries such as httpx or aiohttp.

How do I test async functions with pytest?

Use the pytest-asyncio plugin and mark tests with @pytest.mark.asyncio. The test function can then use await directly, including assertions on timeouts with asyncio.wait_for.