mirror of
https://github.com/sanjeed5/awesome-cursor-rules-mdc.git
synced 2026-11-29 06:02:55 +08:00
- Refreshed all 241 library rules with current best practices - Updated Exa search results for all libraries with 2025 content - Fixed --regenerate-all flag logic to properly process all libraries - Removed duplicate astro entry in rules.json (merged tags) - Added missing docker.mdc and vim.mdc files - All rules now include modern patterns and anti-patterns - Updated with framework-specific recommendations for 2025 Technical improvements: - Fixed retry_failed_only logic in generate_mdc_files.py - Improved progress tracking for regeneration scenarios - Ensured proper handling of --refresh-exa flag
36 lines
1.3 KiB
Plaintext
36 lines
1.3 KiB
Plaintext
---
|
|
description: Definitive guidelines for writing robust, maintainable, and backend-agnostic asynchronous Python code using AnyIO. Prioritize structured concurrency and native AnyIO primitives.
|
|
globs: **/*.py
|
|
---
|
|
# AnyIO Best Practices
|
|
|
|
AnyIO is the definitive choice for modern asynchronous Python development. It provides a unified, Trio-inspired API on top of `asyncio` or `Trio`, fixing critical design shortcomings of `asyncio` and enforcing structured concurrency. Adhere to these rules to build reliable, high-performance async applications.
|
|
|
|
## 1. Entry Point and Backend Selection
|
|
|
|
Always use `anyio.run()` as your application's entry point. Explicitly select your preferred backend and leverage backend-specific optimizations.
|
|
|
|
❌ **BAD**: Relying on default backend or `asyncio.run()`.
|
|
```python
|
|
import asyncio
|
|
from anyio import run, sleep
|
|
|
|
async def main():
|
|
print("Running on default backend (asyncio) without uvloop.")
|
|
await sleep(0.1)
|
|
|
|
asyncio.run(main) # Bypasses AnyIO's entry point
|
|
run(main) # Implicit backend, no optimizations
|
|
```
|
|
|
|
✅ **GOOD**: Explicit backend selection and performance enhancements.
|
|
```python
|
|
from anyio import run, sleep
|
|
import sniffio
|
|
|
|
async def main():
|
|
backend = sniffio.current_async_library()
|
|
print(f"Hello from {backend}!")
|
|
await sleep(0.1)
|
|
|
|
# For production, prefer |