python-async
npx machina-cli add skill athola/claude-night-market/python-async --openclawAsync Python Patterns
asyncio and async/await patterns for Python applications.
Quick Start
import asyncio
async def main():
print("Hello")
await asyncio.sleep(1)
print("World")
asyncio.run(main())
When To Use
- Building async web APIs (FastAPI, aiohttp)
- Implementing concurrent I/O operations
- Creating web scrapers with concurrent requests
- Developing real-time applications (WebSockets)
- Processing multiple independent tasks simultaneously
- Building microservices with async communication
When NOT To Use
- CPU-bound optimization - use python-performance instead
- Testing async code - use python-testing async module
Modules
This skill uses progressive loading. Content is organized into focused modules:
- See
modules/basic-patterns.md- Core async/await, gather(), and task management - See
modules/concurrency-control.md- Semaphores and locks for rate limiting - See
modules/error-handling-timeouts.md- Error handling, timeouts, and cancellation - See
modules/advanced-patterns.md- Context managers, iterators, producer-consumer - See
modules/testing-async.md- Testing with pytest-asyncio - See
modules/real-world-applications.md- Web scraping and database operations - See
modules/pitfalls-best-practices.md- Common mistakes and best practices
Load specific modules based on your needs, or reference all for detailed guidance.
Exit Criteria
- Async patterns applied correctly
- No blocking operations in async code
- Proper error handling implemented
- Rate limiting configured where needed
- Tests pass with pytest-asyncio
Troubleshooting
Common Issues
RuntimeError: no current event loop
Use asyncio.run() as the entry point. Avoid get_event_loop() in Python 3.10+.
Blocking call in async context
Move sync I/O to asyncio.to_thread() or loop.run_in_executor().
Tests hang indefinitely
Ensure pytest-asyncio is installed and test functions are decorated with @pytest.mark.asyncio.
Source
git clone https://github.com/athola/claude-night-market/blob/master/plugins/parseltongue/skills/python-async/SKILL.mdView on GitHub Overview
Offers asyncio and async/await patterns for building scalable Python apps. It covers async APIs, concurrent I/O, rate limiting, and async context managers. It notes when to avoid this skill (CPU-bound tasks and testing scenarios).
How This Skill Works
This skill centers on Python's asyncio and async/await, illustrating patterns such as gather, semaphores, and run_in_executor for I/O-bound work. It organizes content into focused modules (basic-patterns, concurrency-control, error-handling-timeouts, advanced-patterns, testing-async, real-world-applications, pitfalls-best-practices) to guide progressive learning and practical implementation.
When to Use It
- Building async web APIs (FastAPI, aiohttp)
- Implementing concurrent I/O operations
- Creating web scrapers with concurrent requests
- Developing real-time applications (WebSockets)
- Processing multiple independent tasks simultaneously
Quick Start
- Step 1: Import asyncio and define an async function
- Step 2: Use await for async I/O (e.g., asyncio.sleep(1))
- Step 3: Run with asyncio.run(main()) to execute the coroutine
Best Practices
- Async patterns applied correctly
- No blocking operations in async code
- Proper error handling implemented
- Rate limiting configured where needed
- Tests pass with pytest-asyncio
Example Use Cases
- Async APIs development with FastAPI or aiohttp
- Concurrent I/O operations across multiple services
- Web scraping with concurrent requests
- Real-time WebSocket based applications
- Async database operations and background tasks