jpskill.com
💼 ビジネス コミュニティ

fastapi-mastery

FastAPIを使ったREST API開発全般を支援し、ルーティングやリクエスト処理、認証、データベース連携、ミドルウェア設定、デプロイまで、API構築に必要な様々な作業を効率的に進めるSkill。

📜 元の英語説明(参考)

Comprehensive FastAPI development skill covering REST API creation, routing, request/response handling, validation, authentication, database integration, middleware, and deployment. Use when working with FastAPI projects, building APIs, implementing CRUD operations, setting up authentication/authorization, integrating databases (SQL/NoSQL), adding middleware, handling WebSockets, or deploying FastAPI applications. Triggered by requests involving .py files with FastAPI code, API endpoint creation, Pydantic models, or FastAPI-specific features.

🇯🇵 日本人クリエイター向け解説

一言でいうと

FastAPIを使ったREST API開発全般を支援し、ルーティングやリクエスト処理、認証、データベース連携、ミドルウェア設定、デプロイまで、API構築に必要な様々な作業を効率的に進めるSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o fastapi-mastery.zip https://jpskill.com/download/16932.zip && unzip -o fastapi-mastery.zip && rm fastapi-mastery.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/16932.zip -OutFile "$d\fastapi-mastery.zip"; Expand-Archive "$d\fastapi-mastery.zip" -DestinationPath $d -Force; ri "$d\fastapi-mastery.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して fastapi-mastery.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → fastapi-mastery フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
4

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

FastAPI Mastery

概要

最新の Python の機能、自動検証、インタラクティブなドキュメント、および非同期機能を使用して、FastAPI で本番環境に対応できる REST API を構築します。

クイックスタート

基本的な FastAPI アプリケーションを作成します:

from fastapi import FastAPI

app = FastAPI()

@app.get("/")
async def root():
    return {"message": "Hello World"}

以下で実行します:

uvicorn main:app --reload

インタラクティブなドキュメントにアクセスします: http://localhost:8000/docs

複雑度レベル別のスキル構成

このスキルは、3つの段階的なレベルに編成されています。

初級 (references/01-beginner.md)

以下を扱う際に参照してください:

  • 最初の FastAPI アプリケーションのセットアップ
  • 基本的なルーティングとパス操作
  • リクエストパラメータ (path, query, body)
  • Pydantic モデルと検証
  • レスポンスモデルとステータスコード
  • 基本的なエラー処理

中級 (references/02-intermediate.md)

以下を実装する際に参照してください:

  • 認証と認可 (JWT, OAuth2)
  • データベース統合 (SQLAlchemy, async databases)
  • 依存性注入システム
  • ミドルウェアと CORS
  • バックグラウンドタスク
  • ファイルのアップロードとダウンロード

上級 (references/03-advanced.md)

以下を構築する際に参照してください:

  • WebSocket 接続
  • テスト戦略 (pytest, TestClient)
  • パフォーマンス最適化
  • コンテナ化とデプロイメント
  • API バージョニング
  • 高度なエラー処理とロギング

一般的な開発ワークフロー

CRUD API の構築

  1. リクエスト/レスポンス用の Pydantic モデルを定義します
  2. データベースモデル (SQLAlchemy) をセットアップします
  3. パス操作 (GET, POST, PUT, DELETE) を作成します
  4. 検証とエラー処理を追加します
  5. 必要に応じて認証を実装します
  6. テストを追加します

基本的な CRUD パターンについては references/01-beginner.md を、データベース統合については references/02-intermediate.md を参照してください。

認証の追加

  1. 認証方法を選択します (JWT, OAuth2, API keys)
  2. セキュリティ依存関係をセットアップします
  3. ログインエンドポイントを作成します
  4. 依存関係でルートを保護します
  5. JWT を使用している場合は、トークンのリフレッシュを処理します

完全な認証の実装については references/02-intermediate.md を参照してください。

データベース統合

  1. データベースを選択します (PostgreSQL, MySQL, MongoDB)
  2. ORM (SQLAlchemy, Tortoise, Motor) をインストールして構成します
  3. データベースモデルを定義します
  4. データベース接続とセッション管理をセットアップします
  5. CRUD 操作を作成します
  6. マイグレーションを追加します (Alembic)

データベースパターンについては references/02-intermediate.md を参照してください。

ベストプラクティス

型ヒント: 自動検証とドキュメントのために、常に Python の型ヒントを使用してください。

from typing import Optional
from pydantic import BaseModel

class Item(BaseModel):
    name: str
    price: float
    description: Optional[str] = None

依存性注入: 共有ロジックには、FastAPI の依存性注入を使用します。

from fastapi import Depends

def get_current_user(token: str = Depends(oauth2_scheme)):
    # Validate token and return user
    return user

有益な場合は非同期: I/O バウンドの操作 (データベース、外部 API) には非同期を使用します。

@app.get("/items/{item_id}")
async def read_item(item_id: int):
    item = await database.fetch_one(query)
    return item

レスポンスモデル: API ドキュメントと検証のために、常にレスポンスモデルを定義してください。

@app.get("/items/{item_id}", response_model=ItemResponse)
async def read_item(item_id: int):
    return item

リファレンスガイドの選択

タスクに基づいて適切なリファレンスを選択してください:

  • 最初の API または基本的なエンドポイントを作成しますか? → references/01-beginner.md
  • 認証、データベース、またはミドルウェアを追加しますか? → references/02-intermediate.md
  • WebSockets、テスト、またはデプロイメントを行いますか? → references/03-advanced.md

すべてのリファレンスファイルには包括的な例が含まれており、個別に読むことができます。

📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

FastAPI Mastery

Overview

Build production-ready REST APIs with FastAPI using modern Python features, automatic validation, interactive documentation, and asynchronous capabilities.

Quick Start

Create a basic FastAPI application:

from fastapi import FastAPI

app = FastAPI()

@app.get("/")
async def root():
    return {"message": "Hello World"}

Run with:

uvicorn main:app --reload

Access interactive docs: http://localhost:8000/docs

Skill Structure by Complexity Level

This skill is organized into three progressive levels:

Beginner (references/01-beginner.md)

Read when working with:

  • First FastAPI application setup
  • Basic routing and path operations
  • Request parameters (path, query, body)
  • Pydantic models and validation
  • Response models and status codes
  • Basic error handling

Intermediate (references/02-intermediate.md)

Read when implementing:

  • Authentication and authorization (JWT, OAuth2)
  • Database integration (SQLAlchemy, async databases)
  • Dependency injection system
  • Middleware and CORS
  • Background tasks
  • File uploads and downloads

Advanced (references/03-advanced.md)

Read when building:

  • WebSocket connections
  • Testing strategies (pytest, TestClient)
  • Performance optimization
  • Containerization and deployment
  • API versioning
  • Advanced error handling and logging

Common Development Workflows

Building a CRUD API

  1. Define Pydantic models for request/response
  2. Set up database models (SQLAlchemy)
  3. Create path operations (GET, POST, PUT, DELETE)
  4. Add validation and error handling
  5. Implement authentication if needed
  6. Add tests

See references/01-beginner.md for basic CRUD patterns, references/02-intermediate.md for database integration.

Adding Authentication

  1. Choose authentication method (JWT, OAuth2, API keys)
  2. Set up security dependencies
  3. Create login endpoint
  4. Protect routes with dependencies
  5. Handle token refresh if using JWT

See references/02-intermediate.md for complete authentication implementation.

Database Integration

  1. Choose database (PostgreSQL, MySQL, MongoDB)
  2. Install and configure ORM (SQLAlchemy, Tortoise, Motor)
  3. Define database models
  4. Set up database connection and session management
  5. Create CRUD operations
  6. Add migrations (Alembic)

See references/02-intermediate.md for database patterns.

Best Practices

Type hints: Always use Python type hints for automatic validation and documentation.

from typing import Optional
from pydantic import BaseModel

class Item(BaseModel):
    name: str
    price: float
    description: Optional[str] = None

Dependency injection: Use FastAPI's dependency injection for shared logic.

from fastapi import Depends

def get_current_user(token: str = Depends(oauth2_scheme)):
    # Validate token and return user
    return user

Async when beneficial: Use async for I/O-bound operations (database, external APIs).

@app.get("/items/{item_id}")
async def read_item(item_id: int):
    item = await database.fetch_one(query)
    return item

Response models: Always define response models for API documentation and validation.

@app.get("/items/{item_id}", response_model=ItemResponse)
async def read_item(item_id: int):
    return item

Reference Guide Selection

Choose the appropriate reference based on your task:

  • Creating first API or basic endpoints? → references/01-beginner.md
  • Adding auth, databases, or middleware? → references/02-intermediate.md
  • WebSockets, testing, or deployment? → references/03-advanced.md

All reference files include comprehensive examples and can be read independently.

同梱ファイル

※ ZIPに含まれるファイル一覧。`SKILL.md` 本体に加え、参考資料・サンプル・スクリプトが入っている場合があります。