Agent skill · software engineering · aiskillstore

py-async-patterns

Async/await patterns for FastAPI and SQLAlchemy. Use when working with async code, database sessions, concurrent operations, or debugging async issues in Python.

Why this skill is useful

Provides specific async patterns and best practices for managing database sessions and queries in FastAPI with SQLAlchemy that the AI wouldn't reliably generate on its own.

What it needs

Requires asyncio, fastapi, sqlalchemy installed locally. About 5k tokens when loaded. Last updated 2026-08-07. 405 stars on the source repository.

What this skill does

Python Async Patterns Problem Statement Async Python is powerful but error-prone. Race conditions, session leaks, and connection pool issues are common pitfalls in async codebases. --- Pattern: AsyncSession Lifecycle Problem: Session must be scoped to request. Leaking sessions causes stale data and connection exhaustion. Why it matters: Each request needs isolated database state. Shared sessions see stale data and can't be safely committed. --- Pattern: Concurrent vs Sequential Queries Problem: Running independent queries sequentially wastes time. But dependent queries must be sequential. Decision framework: Queries share data? Use --------------------- ----- No (independent) asyncio.gather() Yes (dependent) Sequential await --- Pattern: Transaction Boundaries Problem: Knowing when to commit, rollback, and refresh. When to use what: Scenario Pattern ---------- --------- Single create/update session.add() + commit() at request end Multi-step operation Explicit begin() / commit() / rollback() Need DB-generated values refresh() after commit Read-only query No commit needed --- Pattern: Connection Pool Management Problem: Exhausting connection pool causes requests to hang. --- Pattern: Background Tasks Problem: Long-running work shouldn't block the response. When to use what: Scenario Pattern ---------- --------- Post-response cleanup BackgroundTasks Fire-and-forget logging asyncio.createtask() Must complete before response Direct await --- Pattern: Avoiding Deadlocks Problem: Concurrent operations acquiring locks in different order. …

How to use it

Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:

@skills aiskillstore/py-async-patterns

View the source on GitHub

Browse the @skills marketplace