home / skills / oimiragieo / agent-studio / asynchronous-programming-preference

This skill helps improve code by preferring async and await patterns in asynchronous programming for Python, guiding compliance and refactoring.

npx playbooks add skill oimiragieo/agent-studio --skill asynchronous-programming-preference

Review the files below or copy the command above to add this skill to your agents.

Files (3)
SKILL.md
1.5 KB
---
name: asynchronous-programming-preference
description: Favors the use of async and await for asynchronous programming in Python.
version: 1.0.0
model: sonnet
invoked_by: both
user_invocable: true
tools: [Read, Write, Edit]
globs: '**/*.py'
best_practices:
  - Follow the guidelines consistently
  - Apply rules during code review
  - Use as reference when writing new code
error_handling: graceful
streaming: supported
---

# Asynchronous Programming Preference Skill

<identity>
You are a coding standards expert specializing in asynchronous programming preference.
You help developers write better code by applying established guidelines and best practices.
</identity>

<capabilities>
- Review code for guideline compliance
- Suggest improvements based on best practices
- Explain why certain patterns are preferred
- Help refactor code to meet standards
</capabilities>

<instructions>
When reviewing or writing code, apply these guidelines:

- **Asynchronous Programming:** Prefer `async` and `await`
  </instructions>

<examples>
Example usage:
```
User: "Review this code for asynchronous programming preference compliance"
Agent: [Analyzes code against guidelines and provides specific feedback]
```
</examples>

## Memory Protocol (MANDATORY)

**Before starting:**

```bash
cat .claude/context/memory/learnings.md
```

**After completing:** Record any new patterns or exceptions discovered.

> ASSUME INTERRUPTION: Your context may reset. If it's not in memory, it didn't happen.

Overview

This skill champions using async and await for asynchronous programming in Python. It evaluates code, recommends refactors, and explains why async/await patterns improve readability, error handling, and performance. The skill is written to help teams adopt consistent, modern asynchronous practices.

How this skill works

The skill inspects Python code for asynchronous patterns and flags imperative or callback-style approaches that can be simplified with async/await. It suggests concrete refactors, points out common pitfalls (blocking I/O, improper coroutine handling), and provides brief implementation examples. It also explains trade-offs and when alternative concurrency models might be appropriate.

When to use it

  • When codebase mixes callbacks, threads, or synchronous blocking calls with async libraries
  • During code reviews to enforce consistent async/await usage
  • When refactoring legacy I/O-heavy modules for concurrency and performance
  • When onboarding developers to modern Python asynchronous patterns
  • Before introducing new async libraries to ensure compatibility with existing coroutines

Best practices

  • Prefer async/await for readable asynchronous control flow over nested callbacks
  • Use non-blocking libraries (aiohttp, aiomysql, asyncpg) to avoid blocking the event loop
  • Always await coroutines or schedule them explicitly with create_task when concurrency is intended
  • Handle cancellation and timeouts explicitly using asyncio.wait_for and proper exception handling
  • Keep async functions small and testable; avoid mixing heavy CPU-bound work inside coroutines

Example use cases

  • Review a web client that mixes requests and asyncio and suggest replacing requests with aiohttp
  • Refactor a callback-heavy TCP handler into async/await style for clarity and error propagation
  • Audit database access code and recommend async drivers and connection pooling changes
  • Convert synchronous batch-processing functions to async pipelines to improve throughput while avoiding thread overhead

FAQ

Can I use async/await with existing synchronous libraries?

You can wrap blocking calls in executors, but the preferred approach is to use native async libraries to keep the event loop responsive.

When is threading preferred over async/await?

Use threads for CPU-bound tasks or when only synchronous libraries exist and rewriting is impractical; use async/await for high-concurrency I/O-bound workloads.