fastapi-async-microservices

fastapi-async-microservices is a skill for Claude Code, Codex from hamzabellouch/agent-skills. It costs 77 tokens per session (1,535 once invoked), scanned A, original, MIT.

A guide to building asynchronous REST APIs and small services with FastAPI, a Python web framework. It covers validation, database access, configuration, logging, and service startup and shutdown.

In plain words
What is it for?
Use it to design FastAPI microservices that connect to PostgreSQL, validate requests with Pydantic, manage asynchronous database sessions, and return structured errors.
Why use it?
It gives a consistent structure for Python services and helps avoid scattered database, error-handling, and configuration code.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it to design FastAPI microservices that connect to PostgreSQL, validate requests with Pydantic, manage asynchronous database sessions, and return structured errors.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/hamzabellouch/agent-skills/fastapi-async-microservices
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add hamzabellouch/agent-skills --skill fastapi-async-microservices
Clone the repo
git clone --depth 1 https://github.com/hamzabellouch/agent-skills

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for fastapi-async-microservices

README.md
[![agentmods](https://agentmods.dev/badge/skills/hamzabellouch/agent-skills/fastapi-async-microservices/github.svg)](https://agentmods.dev/skills/hamzabellouch/agent-skills/fastapi-async-microservices)
Your own site
<a href="https://agentmods.dev/skills/hamzabellouch/agent-skills/fastapi-async-microservices"><img src="https://agentmods.dev/badge/skills/hamzabellouch/agent-skills/fastapi-async-microservices/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for fastapi-async-microservices

Your own site · 80×15
<a href="https://agentmods.dev/skills/hamzabellouch/agent-skills/fastapi-async-microservices"><img src="https://agentmods.dev/badge/skills/hamzabellouch/agent-skills/fastapi-async-microservices.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 77 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,535 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00077 $0.01535
Opus 5.5 $0.00031 $0.00614
Sonnet 5.5 $0.00015 $0.00307
Haiku 4.5 $0.00008 $0.00153

Measured 17d ago against content hash 23c3d8c09e74, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

fastapi-async-microservices scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 17d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

Backend Frameworks and Runtimes/fastapi-async-microservices/SKILL.md · 239 lines

How it starts

The opening of the file, as written. The whole thing — 239 lines — stays where its author put it; the contents beside it link to each section on GitHub.

FastAPI Async Microservices Skill Guide

This skill establishes production architecture and coding standards for high-performance, asynchronous REST microservices built with FastAPI, Pydantic v2, and async SQLAlchemy.


1. Async Microservice Architecture

[ Client HTTP Request ]
          |
          v
[ Uvicorn ASGI Server (uvloop) ]
          |
          v
[ FastAPI Application Pipeline ]
  |-- Lifespan Handler (DB pool startup / cleanup)
  |-- Global Middleware (CORS, Request-ID, Structured Logging)
  |-- Routers & Dependency Injection (Auth, DB AsyncSession, Rate-limiting)
          |
          +---> [ Pydantic v2 Validation & Deserialization ]
          |
          +---> [ Business Logic & Async SQLAlchemy 2.0 Engine ]
          |                  |
          |                  v (asyncpg connection pool)
          |           [ PostgreSQL 16+ ]
          |
          v
[ Structured JSON Response / RFC 7807 Error ]

2. Production Code Standards

A. Environment Configuration (config.py)

from functools import lru_cache
from pydantic import PostgresDsn
from pydantic_settings import BaseSettings, SettingsConfigDict


class Settings(BaseSettings):
    APP_NAME: str = "OrderService"
    ENV: str = "production"
    DEBUG: bool = False
    PORT: int = 8000

    # Database
    DATABASE_URL: PostgresDsn = "postgresql+asyncpg://user:secret@localhost:5432/orders_db"
    DB_POOL_SIZE: int = 20
    DB_MAX_OVERFLOW: int = 10
    DB_POOL_TIMEOUT: float = 30.0

    model_config = SettingsConfigDict(
        env_file=".env",
        env_file_encoding="utf-8",
        case_sensitive=True,
        extra="ignore"
    )


@lru_cache
def get_settings() -> Settings:
    return Settings()

B. Database Session Lifecycle (database.py)

from collections.abc import AsyncGenerator
from sqlalchemy.ext.asyncio import (
    AsyncSession,
    async_sessionmaker,
    create_async_engine,
)
from app.config import get_settings

settings = get_settings()

engine = create_async_engine(
    str(settings.DATABASE_URL),
    pool_size=settings.DB_POOL_SIZE,
    max_overflow=settings.DB_MAX_OVERFLOW,
    pool_timeout=settings.DB_POOL_TIMEOUT,
    pool_pre_ping=True,
    echo=settings.DEBUG,
)

AsyncSessionLocal = async_sessionmaker(
    bind=engine,
    class_=AsyncSession,
    expire_on_commit=False,
    autoflush=False,
)


async def get_db_session() -> AsyncGenerator[AsyncSession, None]:
    # FastAPI Dependency providing request-scoped async database session
    async with AsyncSessionLocal() as session:
        try:
            yield session
            await session.commit()
        except Exception:
            await session.rollback()
            raise

Read the full file on GitHub · 239 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 17d ago First seen · 239 lines · 77 tokens per session scan A 23c3d8c09e74

Subscribe to this mod's changes

fastapi-async-microservices is a skill published in the GitHub repository hamzabellouch/agent-skills (8 stars, last pushed 7d ago), licensed MIT. It adds 77 tokens to every session and 1,535 once invoked, about $0.0003 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-29.