async-python
Skill110 starsChanged 9 months agoApache-2.0View on GitHub
Python asyncio patterns for high-performance async code. Use when writing async functions, managing concurrency, working with aiohttp, asyncpg, or any async I/O in Python.
In this repository75 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- algorithmic-artSkill
- api-designSkill
- apple-notesSkill
- apple-remindersSkill
- article-writingSkill
- brand-guidelinesSkill
- camsnapSkill
- canvas-designSkill
- celery-tasksSkill
- claude-apiSkill
- coding-agentSkill
- content-engineSkill
- diffsSkill
- doc-coauthoringSkill
- docker-deploymentSkill
- docxSkill
- e2e-testingSkill
- email-serviceSkill
- fastapi-backendSkill
- frontend-designSkill
- frontend-slidesSkill
- gh-issuesSkill
- githubSkill
- git-workflowSkill
- graphql-apiSkill
- healthcheckSkill
- internal-commsSkill
- investor-materialsSkill
- jwt-authenticationSkill
- market-researchSkill
- mcp-builderSkill
- mermaid-diagramsSkill
- microservicesSkill
- mobile-react-nativeSkill
- model-usageSkill
- nextjs-fullstackSkill
- nodejs-expressSkill
- obsidianSkill
- openai-whisperSkill
- oracleSkill
- pdfSkill
- peekabooSkill
- planning-with-filesSkill
- postgres-databaseSkill
- pptxSkill
- prisma-ormSkill
- proseSkill
- pytest-patternsSkill
- react-typescriptSkill
- redis-cachingSkill
- s3-file-storageSkill
- security-reviewSkill
- session-logsSkill
- skill-creatorSkill
- slack-gif-creatorSkill
- sqlalchemy-ormSkill
- state-managementSkill
- strategic-compactSkill
- stripe-paymentsSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 6 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈6
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 138
NEVER use time.sleep, requests, or any blocking I/O in async functions
- Distinctive: line 139
Use asyncio.gather() for parallel work — sequential awaits waste time
- Distinctive: line 140
Use Semaphore to limit concurrency for rate-limited APIs or DB pools
- Distinctive: line 141
Always await asyncio.wait_for() for external calls (never hang forever)
- Distinctive: line 142
Keep strong references to background tasks (set pattern above)
- Distinctive: line 143
Use asyncpg for PostgreSQL, aioredis for Redis, aiohttp for HTTP
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Async Python Patterns
Core Concepts
import asyncio
# Basic async function
async def fetch_user(user_id: int) -> User:
async with aiohttp.ClientSession() as session:
async with session.get(f"/users/{user_id}") as resp:
return await resp.json()
# Run from sync context
user = asyncio.run(fetch_user(123))Concurrency Patterns
Run tasks in parallel (gather)
# All run at the same time — total time = slowest task
users, posts, comments = await asyncio.gather(
fetch_user(user_id),
fetch_posts(user_id),
fetch_comments(user_id),
)
# With error handling — return exceptions instead of raising
results = await asyncio.gather(
fetch_user(user_id),
fetch_posts(user_id),
return_exceptions=True,
)
for result in results:
if isinstance(result, Exception):
logger.error(f"Task failed: {result}")Limit concurrency (Semaphore)
# Process 100 items but max 10 at a time
sem = asyncio.Semaphore(10)
async def process_with_limit(item):
async with sem:
return await process(item)
results = await asyncio.gather(*[process_with_limit(i) for i in items])Timeout
try:
result = await asyncio.wait_for(fetch_data(), timeout=10.0)
except asyncio.TimeoutError:
logger.warning("Fetch timed out after 10s")
result = NoneBackground tasks (fire and forget)
async def main():
# Don't await — runs in background
task = asyncio.create_task(send_notification(user_id))
# But keep reference so GC doesn't kill it
background_tasks = set()
background_tasks.add(task)
task.add_done_callback(background_tasks.discard)Async context manager
class DatabasePool:
async def __aenter__(self):
self.pool = await asyncpg.create_pool(dsn)
return self
async def __aexit__(self, *args):
await self.pool.close()
async with DatabasePool() as db:
await db.pool.fetchrow("SELECT * FROM users WHERE id = $1", 1)Async generator
async def stream_records(table: str):
async with db.pool.acquire() as conn:
async for record in conn.cursor(f"SELECT * FROM {table}"):
yield dict(record)
async for record in stream_records("large_table"):
await process(record) # Never loads all into memoryEvent Loop Management
# FastAPI: use lifespan for startup/shutdown
@asynccontextmanager
async def lifespan(app: FastAPI):
# startup
app.state.db = await create_pool()
app.state.redis = await aioredis.from_url(REDIS_URL)
yield
# shutdown
await app.state.db.close()
await app.state.redis.close()Common Mistakes to Avoid
# ❌ WRONG: blocking call in async function kills concurrency
async def bad():
time.sleep(1) # Blocks entire event loop!
requests.get(url) # Blocking HTTP call
# ✅ RIGHT: use async equivalents
async def good():
await asyncio.sleep(1)
async with aiohttp.ClientSession() as s:
await s.get(url)
# ❌ WRONG: creating event loop manually in library code
loop = asyncio.get_event_loop()
loop.run_until_complete(coro())
# ✅ RIGHT
asyncio.run(coro()) # Creates and closes loop properlyRules
- NEVER use time.sleep, requests, or any blocking I/O in async functions
- Use asyncio.gather() for parallel work — sequential awaits waste time
- Use Semaphore to limit concurrency for rate-limited APIs or DB pools
- Always await asyncio.wait_for() for external calls (never hang forever)
- Keep strong references to background tasks (set pattern above)
- Use asyncpg for PostgreSQL, aioredis for Redis, aiohttp for HTTP
- asyncio.run() at the top level only — never inside async functions
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

