fastapi-patterns
非同期API、依存性注入、Pydanticのリクエスト・レスポンスモデル、OpenAPIドキュメント、テスト、セキュリティ、本番対応のためのFastAPIパターン。
Original · translation did not pass checksTarget: Software development & testing. Automatically collected · unverified.
Excerpt from the author’s documentation
Extracted from a fixed version of SKILL.md in its original language. This is the author’s documentation; installation, compatibility and runtime results have not been verified by this site.
Read the original Japanese text
Topics in the source
- FastAPIパターン
- 使用するタイミング
- 仕組み
- プロジェクトレイアウト
- アプリケーションファクトリー
- Pydanticスキーマ
- 依存関係
- 非同期エンドポイント
本番指向のFastAPIサービスのためのパターン。 FastAPIアプリを構築またはレビューする場合。 ルーター、スキーマ、依存関係、データベースアクセスを分割する場合。 データベースや外部サービスを呼び出す非同期エンドポイントを記述する場合。 認証、認可、OpenAPIドキュメント、テスト、またはデプロイ設定を追加する場合。 FastAPI PRをコピー可能な例とリスクについて確認する場合。 FastAPIアプリを明示的な依存関係とサービスコードの上の薄いHTTPレイヤーとして扱います: main.py はアプリ構築、ミドルウェア、例外ハンドラー、ルーター登録を担当する。 schemas/ はPydanticのリクエストとレスポンスモデルを担当する。 dependencies.py はデータベース、認証、ページネーション、リクエストスコープの依存関係を担当する。 services/ または crud/ はビジネスと永続化操作を担当する。 tests/ は本番リソースを開かずに依存関係をオーバーライドする。 小さなルーターと明示的なresponsemodel宣言を優先します。レスポンススキーマには生のORMオブジェクト、シークレット、フレームワークのグローバル変数を含めないでください。 テストとワーカーが制御された設定でアプリをビルドできるように、ファクトリーを使用します。 allowcredentials=Trueと一緒にalloworigins=[""]を使用しないでください; ブラウザはその組み合わせを拒否し、Starletteは認証情報付きリクエストに対してそれを禁止します。 リクエスト、更新、レスポンスのモデルを分離します。 レスポンスモデルにはパスワードハッシュ、アクセストークン、リフレッシュトークン、内部認可状態を含めてはなりません。 リクエストスコープのリソースには依存性注入を使用します。 ルートハンドラー内でインラインにセッション、クライアント、または認証情報を作成しないでください。 I/Oを実行する場合はルートハンドラーを非同期にし、その内部で非同期ライブラリを使用します。 非同期ハンドラーからの外部HTTP呼び出しにはhttpx.AsyncClientを使用してください。非同期ルートでrequestsを呼び出さないでください。 ドメイン例外を一元化し、レスポンスの形状を安定させます。 カスタムOpenAPI呼び出し可能オブジェクトをapp.openapiに割り当ててください; 関数を一度だけ呼び出さないでください。 ルートハンドラーが決して参照しない内部ヘルパーではなく、Dependsで使用される依存関係をオーバーライドします。 argon2-cffi、bcrypt、または現在のpasslib互換ハッシャーでパスワードをハッシュする。
This is an excerpt. Refer to the complete source and its current requirements.
- Source repository
- affaan-m/ECC
- Source file
- docs/ja-JP/skills/fastapi-patterns/SKILL.md
- Fixed revision
- d2ef2680594f9a17526a6e1a2e18b3d242c5d17b
Requirements
- Only the author’s Skill metadata is included. Read the full instructions to check dependencies, licensing and conditions of use.
A small first task
先阅读原作者说明,再决定是否在自己的 AI 工具中使用。
Instructions for your AI tool
- Claude Desktop: resource-specific guide not available yet
- Claude Code: resource-specific guide not available yet
- Cursor: resource-specific guide not available yet
- Codex: resource-specific guide not available yet
Author documentation is not live verification by this site. Without evidence, we do not mark a resource as compatible, safe or free.
Sources and evidence
This record was collected automatically. Its documentation, suitability and runtime behavior have not been manually verified.
Author: affaan-m/ECC · original repository metadata. Documentation review: Not reviewed. Last source check: 2026-11-09T14:01:49.223Z.
Categories are inferred from names, descriptions and paths. They do not establish compatibility.
License and attribution
MIT. Third-party content and copyright remain with their authors. Refer to the original license and terms.
Original license ↗Synchronization, copying and user-reported success do not mark a resource as runtime-tested.
Limitations and notes
- Collecting metadata does not mean this site has installed, adapted, runtime-tested or security-reviewed the resource.