What problem does it solve?
This Skill enforces correct async/await patterns in Python, preventing common asyncio.run() errors within an already-running event loop and ensuring efficient non-blocking I/O. It helps developers write high-performance, concurrent applications without introducing subtle bugs.
Core Features & Use Cases
- Core
async/await Usage: Guides on using async def for functions that perform asynchronous operations and await for calling them.
- Parallel Execution: Provides patterns for running multiple asynchronous tasks concurrently using
asyncio.gather().
- Async I/O Operations: Shows examples for asynchronous database queries, HTTP requests (with
httpx), and file I/O (with aiofiles).
- Error Handling & Testing: Covers robust error handling in async code and testing async functions with
pytest.mark.asyncio.
- Use Case: A FastAPI application needs to fetch data from multiple external APIs concurrently. This skill helps the developer use
asyncio.gather() to make these HTTP requests in parallel, significantly reducing the total response time of the API endpoint.
Quick Start
Refactor the fetch_user_data function to be asynchronous and use await for database calls.