# Async python patterns

> Async python patterns is an open-source agent skill for developer tools. Guides async Python services: FastAPI handlers, AsyncSession DB access and event loop. It is available on Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf and Goose.

- **Kind:** Skill
- **Pricing:** Open source
- **Platforms:** Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf, Goose
- **Website:** https://github.com/ajyadav013/claude-kit/tree/main/providers/codex/claude-kit/skills/async-python-patterns
- **Repository:** https://github.com/ajyadav013/claude-kit
- **GitHub stars:** 13
- **License:** MIT
- **Skill name:** async-python-patterns
- **Collection:** https://github.com/ajyadav013/claude-kit
- **Categories:** [developer tools](https://ai-powered.com/categories/developer-tools)
- **Listing updated:** 2026-12-03

## About

This skill gives an agent a set of conventions for building high-throughput Python services with async/await. It covers how to structure FastAPI lifespan hooks, set up SQLAlchemy 2.0 async sessions on asyncpg with task-scoped session handling, run several workers and health checks together with asyncio.gather, and shut workers down cleanly on SIGTERM or SIGINT.

A large part of the guidance targets the sync-in-async trap. The skill shows how to offload blocking cloud clients to a thread with asyncio.to_thread or switch to an async client, and how to bridge a blocking Kafka consumer back onto the event loop with run_coroutine_threadsafe. It also lists common anti-patterns, such as omitting return_exceptions in gather or spinning up a second event loop inside a thread.

The examples are Python and assume FastAPI, SQLAlchemy with asyncpg, aiokafka or kafka-python, aiohttp, and optionally uvloop. The skill has no scripts and needs no special tools; it works through instructions and reference files that the agent reads when a task matches.

## When your agent uses it

> Async Python for high-performance services. Use when implementing FastAPI/Temporal/Kafka async handlers, AsyncSession database access, asyncio.gather concurrency, or diagnosing event loop blocking.

## What it can access

From a static check of the files on GitHub; nothing was run.

- [Instructions only, no scripts](https://github.com/ajyadav013/claude-kit/tree/HEAD/providers/codex/claude-kit/skills/async-python-patterns)
- [License: MIT](https://github.com/ajyadav013/claude-kit/tree/HEAD/providers/codex/claude-kit/skills/async-python-patterns)

## Features

- **FastAPI lifespan setup:** Initializes connections on startup and closes them on shutdown using an async context manager.
- **Async database sessions:** Configures SQLAlchemy 2.0 async engines and task-local scoped sessions on asyncpg.
- **Concurrent worker orchestration:** Runs workers and health tasks together with asyncio.gather and graceful signal-based shutdown.
- **Sync-to-async bridging:** Shows how to run a blocking Kafka consumer in a thread and dispatch handlers onto the main loop.
- **Event loop blocking fixes:** Explains how to detect sync cloud client calls in async code and offload or replace them.
- **Async HTTP client wrapper:** Provides an aiohttp-based client pattern with retry handling and clean session closure.

## Good for

- Write an async FastAPI endpoint that queries PostgreSQL through AsyncSession
- Run several Kafka consumers and a health check concurrently with graceful shutdown
- Find why my async service is stalling and whether a sync client is blocking the loop
- Wrap a blocking Google Cloud client call inside a Temporal activity
- Set up a reusable async HTTP client with retries for an API integration

## Install

### Claude Code

This skill ships in the `claude-kit` plugin. In Claude Code, add the marketplace and install the plugin (it may include other skills too):

```sh
/plugin marketplace add ajyadav013/claude-kit
/plugin install claude-kit@claude-kit
```

Or copy only this skill to `~/.claude/skills/async-python-patterns`:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/ajyadav013/claude-kit.git "$tmp" &&
mkdir -p ~/.claude/skills &&
rm -rf ~/.claude/skills/async-python-patterns &&
cp -R "$tmp/providers/codex/claude-kit/skills/async-python-patterns" ~/.claude/skills/async-python-patterns &&
rm -rf "$tmp"
```

For one project only, put the folder in `.claude/skills/async-python-patterns` inside it instead.

### Codex

Copy the skill folder to `~/.agents/skills/async-python-patterns` to use it in every repository:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/ajyadav013/claude-kit.git "$tmp" &&
mkdir -p ~/.agents/skills &&
rm -rf ~/.agents/skills/async-python-patterns &&
cp -R "$tmp/providers/codex/claude-kit/skills/async-python-patterns" ~/.agents/skills/async-python-patterns &&
rm -rf "$tmp"
```

For one repository only, put the folder in `.agents/skills/async-python-patterns` inside it instead.

### Cursor

Copy the skill folder to `~/.cursor/skills/async-python-patterns` to use it in every project:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/ajyadav013/claude-kit.git "$tmp" &&
mkdir -p ~/.cursor/skills &&
rm -rf ~/.cursor/skills/async-python-patterns &&
cp -R "$tmp/providers/codex/claude-kit/skills/async-python-patterns" ~/.cursor/skills/async-python-patterns &&
rm -rf "$tmp"
```

For one project only, put the folder in `.cursor/skills/async-python-patterns` inside it instead.

### Gemini CLI

Run in a terminal (add `--scope workspace` to install it for the current workspace only):

```sh
gemini skills install https://github.com/ajyadav013/claude-kit.git --path providers/codex/claude-kit/skills/async-python-patterns
```

Or copy the folder to `~/.gemini/skills/async-python-patterns` yourself.

### VS Code

For GitHub Copilot in VS Code, copy the skill folder to `~/.copilot/skills/async-python-patterns`:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/ajyadav013/claude-kit.git "$tmp" &&
mkdir -p ~/.copilot/skills &&
rm -rf ~/.copilot/skills/async-python-patterns &&
cp -R "$tmp/providers/codex/claude-kit/skills/async-python-patterns" ~/.copilot/skills/async-python-patterns &&
rm -rf "$tmp"
```

For one project only, put the folder in `.github/skills/async-python-patterns` inside it instead.

### Other agents

Get the folder:

```sh
git clone --depth 1 https://github.com/ajyadav013/claude-kit.git
```

Then copy `claude-kit/providers/codex/claude-kit/skills/async-python-patterns` into your agent's skills folder as `async-python-patterns`. Agents that support SKILL.md read one folder per skill.

## FAQ

### What does Async python patterns need to be installed or run?

It is a plain SKILL.md folder with reference files and no scripts, and it does not restrict allowed tools. It is also distributed as part of a Claude Code plugin marketplace called claude-kit.

### When does the agent load Async python patterns?

When the task involves FastAPI, Temporal or Kafka async handlers, AsyncSession database access, asyncio.gather concurrency, or diagnosing event loop blocking.

### Which libraries does the guidance assume?

It assumes FastAPI, SQLAlchemy 2.0 with asyncpg, aiokafka or kafka-python for Kafka, aiohttp for HTTP, and optionally uvloop.

### Does Async python patterns cover Kerberos-authenticated Kafka?

Yes. It notes that aiokafka does not support GSSAPI/Kerberos as of version 0.7.x, so kafka-python with the sync-to-async bridge is recommended for that case.

### How do I install Async python patterns in Claude Code?

Copy the skill folder from GitHub to ~/.claude/skills/async-python-patterns to use it in all your projects, or to .claude/skills/async-python-patterns in one project. Or install the claude-kit plugin, which includes it: /plugin marketplace add ajyadav013/claude-kit, then /plugin install claude-kit@claude-kit.

### Does Async python patterns run scripts?

No. It is instructions only, with no scripts. This comes from a static check of the files on GitHub; nothing was run. Read the files before you install it.

### Which AI agents can use Async python patterns?

Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf and Goose. Each reads skills in the SKILL.md format from its own folder; the install steps on this page list them.

### What are the best alternatives to Async python patterns?

The closest alternatives to Async python patterns are Python backend, Testing conventions, Backend repo architecture, Auth and rbac and Azure cosmos db py.

## Where this comes from

- Description: from the skill's own SKILL.md.

## Alternatives

- [Python backend](https://ai-powered.com/skills/python-backend): Python backend is an open-source agent skill for developer tools.
- [Testing conventions](https://ai-powered.com/skills/testing-conventions): Testing conventions is an open-source agent skill for developer tools.
- [Backend repo architecture](https://ai-powered.com/skills/backend-repo-architecture): Backend repo architecture is an open-source agent skill for developer tools.
- [Auth and rbac](https://ai-powered.com/skills/auth-and-rbac): Auth and rbac is an open-source agent skill for security.
- [Azure cosmos db py](https://ai-powered.com/skills/azure-cosmos-db-py): Azure cosmos db py is an open-source agent skill for cloud and infrastructure.
- [API integration](https://ai-powered.com/skills/api-integration-ajyadav013): API integration is an open-source agent skill for developer tools.
- [Asyncapi](https://ai-powered.com/skills/asyncapi): Asyncapi is an open-source agent skill for developer tools.
- [Django patterns](https://ai-powered.com/skills/django-patterns): Django patterns is an open-source agent skill for developer tools.

---
Source: https://ai-powered.com/skills/async-python-patterns
