This code generator creates FastAPI app from an openapi file.
Python
1,407
764 commits
updated Oct 12, 2026
Generate a FastAPI application from an OpenAPI document.
📣 💼 Maintainer update: Open to opportunities. 🔗 koxudaxi.dev
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/.
uv tool install fastapi-code-generator
pip install fastapi-code-generator
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.
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.
--allow-remote-refs / --no-allow-remote-refs
Allow or block fetching remote $ref targets
over HTTP/HTTPS. The default follows
datamodel-code-generator compatibility
behavior.
--allow-private-network Allow trusted remote $ref targets on local
or private network addresses.
-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.
fastapi-codegen --input openapi.yaml --output appfastapi-codegen --input openapi.yaml --output app --template-dir modular_template --generate-routersfastapi-codegen --input openapi.yaml --output app --template-dir modular_template --generate-routers --specify-tags "Wild Boars, Fat Cats"fastapi-codegen --input openapi.yaml --output app --output-model-type pydantic_v2.BaseModelOverall
Maintained
Code review
Latest release
Releases this year
2,355 followers · starred Aug 2021
32,342 followers · starred Jun 2020
582 followers · starred Jan 2023
179 followers · starred Jan 2021
This code generator creates FastAPI app from an openapi file.
Python
1,407
764 commits
updated Oct 12, 2026
Generate a FastAPI application from an OpenAPI document.
📣 💼 Maintainer update: Open to opportunities. 🔗 koxudaxi.dev
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/.
uv tool install fastapi-code-generator
pip install fastapi-code-generator
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.
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.
--allow-remote-refs / --no-allow-remote-refs
Allow or block fetching remote $ref targets
over HTTP/HTTPS. The default follows
datamodel-code-generator compatibility
behavior.
--allow-private-network Allow trusted remote $ref targets on local
or private network addresses.
-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.
fastapi-codegen --input openapi.yaml --output appfastapi-codegen --input openapi.yaml --output app --template-dir modular_template --generate-routersfastapi-codegen --input openapi.yaml --output app --template-dir modular_template --generate-routers --specify-tags "Wild Boars, Fat Cats"fastapi-codegen --input openapi.yaml --output app --output-model-type pydantic_v2.BaseModelOverall
Maintained
Code review
Latest release
Releases this year
2,355 followers · starred Aug 2021
32,342 followers · starred Jun 2020
582 followers · starred Jan 2023
179 followers · starred Jan 2021