Generate a FastAPI app from an OpenAPI file.
Project Links
Meta
Author: Koudai Aono
Requires Python: >=3.10
Classifiers
Development Status
- 2 - Pre-Alpha
License
- OSI Approved :: MIT License
Natural Language
- English
Programming Language
- Python :: 3
- Python :: 3 :: Only
- Python :: 3.10
- Python :: 3.11
- Python :: 3.12
- Python :: 3.13
- Python :: 3.14
- Python :: Implementation :: CPython
fastapi-code-generator
Generate a FastAPI application from an OpenAPI document.
๐ฃ ๐ผ Maintainer update: Open to opportunities. ๐ koxudaxi.dev
Documentation
The docs site is the source of truth for user-facing documentation:
Use this README as a quick start. The full examples, templating details, and development workflow live in docs/.
Installation
uv tool install fastapi-code-generator
pip install fastapi-code-generator
Quick Start
fastapi-codegen --input openapi.yaml --output app --output-model-type pydantic_v2.BaseModel
fastapi-code-generator uses datamodel-code-generator to build the model layer. See the overview guide for a complete end-to-end example, custom templates, custom visitors, and router generation.
Command Help Snapshot
This block is generated from the current CLI so the README and docs overview stay aligned. For tested option scenarios and examples, use the CLI reference page.
Usage: fastapi-codegen [OPTIONS]
Options:
-e, --encoding TEXT [default: utf-8]
-i, --input TEXT [required]
-o, --output PATH [required]
-m, --model-file TEXT
-t, --template-dir PATH
--model-template-dir PATH
--enum-field-as-literal [all|one|none]
-r, --generate-routers
--specify-tags TEXT
-c, --custom-visitor PATH
--disable-timestamp
--strict-nullable Respect explicit OpenAPI nullable flags when
generating models.
--include-request-argument Auto-inject a FastAPI Request parameter into
operations when not present.
-d, --output-model-type [pydantic_v2.BaseModel|pydantic_v2.dataclass|dataclasses.dataclass|typing.TypedDict|msgspec.Struct]
[default: pydantic_v2.BaseModel]
-p, --python-version [3.10|3.11|3.12|3.13|3.14]
[default: 3.10]
-V, --version
--use-annotated Use typing.Annotated for generated model
field constraints.
--reuse-model Reuse identical generated models as the same
type.
--enable-faux-immutability Generate frozen Pydantic models so instances
are hashable when their fields are hashable.
--install-completion Install completion for the current shell.
--show-completion Show completion for the current shell, to
copy it or customize the installation.
--help Show this message and exit.
Common Tasks
- Generate a single-file app from an OpenAPI spec:
fastapi-codegen --input openapi.yaml --output app - Generate router modules for larger applications:
fastapi-codegen --input openapi.yaml --output app --template-dir modular_template --generate-routers - Limit router regeneration to specific tags:
fastapi-codegen --input openapi.yaml --output app --template-dir modular_template --generate-routers --specify-tags "Wild Boars, Fat Cats" - Target Pydantic v2 output:
fastapi-codegen --input openapi.yaml --output app --output-model-type pydantic_v2.BaseModel
Further Reading
- Overview for the full walkthrough and generated output example
- CLI Reference for option-by-option behavior and tested scenarios
- Supported Formats for the generated support matrix
- Development & Contributing for the local workflow and docs maintenance steps
0.6.0
Apr 30, 2026
0.5.4
Apr 29, 2025
0.5.3
Apr 16, 2025
0.5.3rc0
Apr 16, 2025
0.5.2
Dec 14, 2024
0.5.1
Jul 02, 2024
0.5.0
May 02, 2024
0.4.4
Sep 07, 2023
0.4.3
Aug 19, 2023
0.4.2
Apr 27, 2023
0.4.1
Feb 15, 2023
0.4.0
Jan 17, 2023
0.3.6
Oct 24, 2022
0.3.5
May 13, 2022
0.3.4
Dec 03, 2021
0.3.3
Dec 03, 2021
0.3.2
Nov 29, 2021
0.3.1
Nov 28, 2021
0.3.0
Aug 08, 2021
0.2.7
Jun 17, 2021
0.2.6
May 29, 2021
0.2.5
May 04, 2021
0.2.4
Apr 29, 2021
0.2.3
Mar 01, 2021
0.2.2
Feb 19, 2021
0.2.1
Feb 18, 2021
0.2.0
Jan 25, 2021
0.1.1
Jan 12, 2021
0.1.0
Jan 07, 2021
0.0.19
Dec 02, 2020
0.0.18
Nov 21, 2020
0.0.17
Nov 14, 2020
0.0.16
Nov 10, 2020
0.0.15
Nov 09, 2020
0.0.14
Nov 04, 2020
0.0.13
Jul 27, 2020
0.0.12
Jun 26, 2020
0.0.11
Jun 20, 2020
0.0.10
Jun 20, 2020
0.0.9
Jun 19, 2020
0.0.8
Jun 18, 2020
0.0.7
Jun 18, 2020
0.0.6
Jun 17, 2020
0.0.5
Jun 17, 2020
0.0.4
Jun 16, 2020
0.0.3
Jun 16, 2020
0.0.2
Jun 15, 2020
0.0.1
Jun 14, 2020