Source profileQuality 91/100

event4u-app/agent-config/src/skills/async-python-patterns/SKILL.md

async-python-patterns

Use when writing Python asyncio code — picking between gather / TaskGroup / wait, structured concurrency, timeouts, cancellation, sync-bridging — decision framework only, cookbook externalized.

Source repository stars
7
Declared platforms
0
Static risk flags
0
Last source update
2026-07-28
Source checked
2026-07-28

Decision brief

What it does—and where it fits

Decision framework for picking the right Python asyncio primitive. The pattern cookbook lives upstream (links in § Provenance) — this skill is the predicate, not the recipe library. Sunset-policy compliant: the 600+ lines of language-specific cookbook stay in authoritative Pytho…

Best for

  • Designing a new async I/O-bound service (FastAPI, aiohttp, async DB client).
  • Reviewing a diff that introduces asyncio.gather, asyncio.createtask, TaskGroup, ascompleted, or waitfor.
  • Mixing sync and async code (calling sync libs from async context, or vice versa).

Not for

  • Tasks that require unconfirmed production actions or broad system permissions.
  • Environments where the pinned source and install steps cannot be inspected.

Compatibility matrix

Platform support, with evidence labels

PlatformStatusEvidenceWhat to check
CodexNot declaredNo explicit evidencePortability before use
Claude CodeNot declaredNo explicit evidencePortability before use
CursorNot declaredNo explicit evidencePortability before use
Gemini CLINot declaredNo explicit evidencePortability before use
Open the compatibility checker

Installation

Inspect first. Install second.

The source command is displayed only when detected. A safe inspection prompt is always available so your agent can explain every action before execution.

Source-detected install commandSource
npx skills add https://github.com/event4u-app/agent-config --skill "src/skills/async-python-patterns"
Safe inspection promptEditorial

Inspect the Agent Skill "async-python-patterns" from https://github.com/event4u-app/agent-config/blob/0adf49a8ae84b0ff6e2de8759eea43257e020eff/src/skills/async-python-patterns/SKILL.md at commit 0adf49a8ae84b0ff6e2de8759eea43257e020eff. List every install step, command, network request, credential, file read/write, external action, and rollback step. Explain whether it fits my task. Do not install or execute anything until I approve.

Workflow

What the source asks the agent to do

  1. 01

    Step 1 — Verify async is the right tool

    Review the “Step 1 — Verify async is the right tool” section in the pinned source before continuing.

    Review and apply the “Step 1 — Verify async is the right tool” source section.
  2. 02

    Step 2 — Pick the concurrency primitive

    Review the “Step 2 — Pick the concurrency primitive” section in the pinned source before continuing.

    Review and apply the “Step 2 — Pick the concurrency primitive” source section.
  3. 03

    Step 3 — Bridge sync ↔ async correctly

    Review the “Step 3 — Bridge sync ↔ async correctly” section in the pinned source before continuing.

    Review and apply the “Step 3 — Bridge sync ↔ async correctly” source section.
  4. 04

    Step 4 — Cancellation discipline

    Every long-running coroutine MUST be cancellation-safe:

    Catch asyncio.CancelledError, perform cleanup, re-raise. Swallowing it silently breaks the propagation chain.Use try / finally (or async with) around resource acquisition so cancellation cannot leak file handles, DB connections, locks.Detached createtask without a strong reference is undefined behavior; either store the task or use a TaskGroup.
  5. 05

    Step 5 — Don't block the event loop

    A single blocking call (sync I/O, time.sleep, CPU-heavy parse, large JSON load) freezes every coroutine. Audit every leaf function under async def:

    Sleep → await asyncio.sleep, never time.sleep.HTTP → httpx.AsyncClient / aiohttp, never requests.DB → asyncpg / aiosqlite / motor, never the sync driver.

Permission review

Static risk signals and limitations

No configured static risk pattern was detected

This is not proof of safety. Runtime behavior, indirect dependencies, and hidden external systems are outside the static scan.

Evidence record

Why each signal appears

EvidenceSourceComputedTestedEditorial
SignalValueEvidence typeMeaning
Quality score91/100ComputedDocumentation, specificity, maintenance, and trust rules
Repository stars7SourceRepository attention, not individual Skill quality
Compatibility0 platformsSourceDeclared in the catalog source record
Usage guideautomated source guideEditorialGenerated or reviewed according to the visible evidence level

Pinned source

Provenance and original SKILL.md

Repository
event4u-app/agent-config
Skill path
src/skills/async-python-patterns/SKILL.md
Commit
0adf49a8ae84b0ff6e2de8759eea43257e020eff
License
MIT
Collected
2026-07-28
Default branch
main
View the original SKILL.md

async-python-patterns

Decision framework for picking the right Python asyncio primitive. The pattern cookbook lives upstream (links in § Provenance) — this skill is the predicate, not the recipe library. Sunset-policy compliant: the 600+ lines of language-specific cookbook stay in authoritative Python docs.

When to use

  • Designing a new async I/O-bound service (FastAPI, aiohttp, async DB client).
  • Reviewing a diff that introduces asyncio.gather, asyncio.create_task, TaskGroup, as_completed, or wait_for.
  • Mixing sync and async code (calling sync libs from async context, or vice versa).
  • Diagnosing event-loop blocking, never-awaited warnings, or cancellation leaks.

Do NOT use when:

  • The work is CPU-bound — async will not help; route to multiprocessing or threadpool.
  • The runtime is not Python — read the host runtime's concurrency guide.
  • The fix is a single missing await — read the upstream tutorial directly.

Decision framework

Step 1 — Verify async is the right tool

Workload is:
  I/O-bound, many concurrent waits  → async fits (network, disk, IPC).
  CPU-bound (parsing, math, crypto) → async is wrong; use ProcessPoolExecutor.
  Mixed                              → async shell + run_in_executor for CPU bursts.
  Single sequential call             → don't introduce async; sync is simpler.

Step 2 — Pick the concurrency primitive

Run N independent coroutines, ALL must complete:
  Same trust level, exceptions cancel siblings  → asyncio.TaskGroup (3.11+; preferred).
  Pre-3.11 OR exceptions must NOT cancel peers  → asyncio.gather(*, return_exceptions=...).

Run N coroutines, react to results as they finish:
  → asyncio.as_completed (yields completed futures in finish order).

Run N coroutines, race to first success / failure:
  → asyncio.wait(..., return_when=FIRST_COMPLETED) + cancel pending.

Schedule fire-and-forget background work:
  → asyncio.create_task + keep a strong reference (else GC eats it).
  Forgetting the reference is the #1 silent-failure source.

Bound the wait time:
  → asyncio.wait_for(coro, timeout=...)  → raises TimeoutError on expiry.
  → asyncio.timeout(...) context manager (3.11+; preferred when many awaits share a deadline).

Bound concurrency (rate-limit, connection pool):
  → asyncio.Semaphore(n); acquire around the awaitable.

Step 3 — Bridge sync ↔ async correctly

Async code calls sync, blocking, function:
  Short pure-CPU              → fine, accept the block (microseconds).
  Long, blocking, or I/O-sync → await loop.run_in_executor(None, fn, *args).
  Library has async sibling   → switch the library (httpx vs requests, aiosqlite vs sqlite3).

Sync code calls async function:
  Top-level entrypoint        → asyncio.run(coro()).
  Inside running loop         → never asyncio.run; create_task + await it.
  Test suite                  → pytest-asyncio fixture; never raw run() in tests.

Step 4 — Cancellation discipline

Every long-running coroutine MUST be cancellation-safe:

  • Catch asyncio.CancelledError, perform cleanup, re-raise. Swallowing it silently breaks the propagation chain.
  • Use try / finally (or async with) around resource acquisition so cancellation cannot leak file handles, DB connections, locks.
  • Detached create_task without a strong reference is undefined behavior; either store the task or use a TaskGroup.

Step 5 — Don't block the event loop

A single blocking call (sync I/O, time.sleep, CPU-heavy parse, large JSON load) freezes every coroutine. Audit every leaf function under async def:

  • Sleep → await asyncio.sleep, never time.sleep.
  • HTTP → httpx.AsyncClient / aiohttp, never requests.
  • DB → asyncpg / aiosqlite / motor, never the sync driver.
  • File → aiofiles for hot-paths, or run_in_executor for one-shots.

Procedure: Apply to a new async feature

  1. Inspect the existing call graph and identify each await site, sync↔async boundary, and any blocking leaf calls before touching code.
  2. Run Step 1; reject if work is CPU-bound.
  3. Sketch the call graph; tag each await site with its primitive (Step 2).
  4. Mark every sync↔async boundary; pick the bridge per Step 3.
  5. For each long-running coroutine, write the cancel-safety contract (Step 4).
  6. Grep the leaf calls for blocking sins (Step 5); replace or push to executor.
  7. Hand the sketch to a reviewer before coding; cite this skill.

Output format

  1. Call-graph table: coroutine · concurrency primitive · timeout · cancel-safety note.
  2. Sync↔async boundary list: site · bridge · justification.
  3. Blocking-call audit: leaf function · status (async / executor / accepted-block + reason).
  4. Cancel-safety contract for each background task.

Gotcha

  • "It works in my REPL" — asyncio.run inside an already-running loop (Jupyter, FastAPI startup) raises RuntimeError. Use await directly or nest_asyncio (last resort).
  • asyncio.gather swallows the second exception silently; use return_exceptions=True and inspect, or use TaskGroup (cancels all on first error, surfaces the group).
  • create_task results that nobody awaits look fine until the program exits and Python prints Task was destroyed but it is pending!. Always await or use a TaskGroup.
  • wait_for on a non-cancellation-safe coroutine leaks resources; the timeout cancels the task but cleanup never runs.
  • Libraries that "support async" via thread pools (e.g. requests-async) often re-block the loop under load; verify with the cited upstream library docs, not the README.

Do NOT

  • Do NOT call asyncio.run from a running loop.
  • Do NOT swallow CancelledError without re-raising.
  • Do NOT call sync blocking I/O from async paths without run_in_executor.
  • Do NOT spawn create_task without storing the reference (or using TaskGroup).
  • Do NOT inline the asyncio cookbook into this skill — externalize per Sunset Policy.

Auto-trigger keywords

  • asyncio
  • async / await
  • gather / TaskGroup / wait_for
  • event loop blocking
  • cancellation
  • sync to async bridge

Provenance

Alternatives

Compare before choosing

Computed 7538,313

wshobson/agents

async-python-patterns

Master Python asyncio, concurrent programming, and async/await patterns for high-performance applications. Use when building async APIs, concurrent systems, or I/O-bound applications requiring non-blocking operations.

Computed 9731,966

K-Dense-AI/scientific-agent-skills

esm

Use when working directly with the `esm` Python SDK, ESM3 or ESMC model IDs, Forge/Biohub inference clients, or ESMFold2 folding workflows.

Computed 9510,762

Jeffallan/claude-skills

fastapi-expert

Use when building high-performance async Python APIs with FastAPI and Pydantic V2. Invoke to create REST endpoints, define Pydantic models, implement authentication flows, set up async SQLAlchemy database operations, add JWT authentication, build WebSocket endpoints, or generate OpenAPI documentation. Trigger terms: FastAPI, Pydantic, async Python, Python API, REST API Python, SQLAlchemy async, JWT authentication, OpenAPI, Swagger Python.

Computed 9331,966

K-Dense-AI/scientific-agent-skills

genomic-intelligence

Predict regulatory features, gene structure, and expression directly from DNA sequence using Genomic Intelligence's hosted transformer DNA language models — no local GPU or model weights. Six tasks over a REST API and a hosted MCP server (keyless public demo): promoter regions, splice donor/acceptor sites, enhancer activity, chromatin state, sequence-to-expression (log TPM), and de-novo gene annotation, plus a composite find-genes-then-predict-expression workflow. Use when the user has a gene sy