Generate a FastAPI app from an OpenAPI file.
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastapi_code_generator-0.6.0.tar.gz.
File metadata
- Download URL: fastapi_code_generator-0.6.0.tar.gz
- Upload date:
- Size: 52.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
51776ea5760757a87c8ce7c0bd93dd02e969e2c29ce25dee965da1d2e360338c
|
|
| MD5 |
75b5ca6df03cb13fd937e4bd4066df4a
|
|
| BLAKE2b-256 |
50cc6df598b1b08472d6b69a74358310af94ca34e98ef43d408ed421b7a68421
|
Provenance
The following attestation bundles were made for fastapi_code_generator-0.6.0.tar.gz:
Publisher:
publish.yml on koxudaxi/fastapi-code-generator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastapi_code_generator-0.6.0.tar.gz -
Subject digest:
51776ea5760757a87c8ce7c0bd93dd02e969e2c29ce25dee965da1d2e360338c - Sigstore transparency entry: 1411814996
- Sigstore integration time:
-
Permalink:
koxudaxi/fastapi-code-generator@b1c8c22e2fc41e4756e703a1df351c06753886a1 -
Branch / Tag:
refs/tags/0.6.0 - Owner: https://github.com/koxudaxi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b1c8c22e2fc41e4756e703a1df351c06753886a1 -
Trigger Event:
push
-
Statement type:
File details
Details for the file fastapi_code_generator-0.6.0-py3-none-any.whl.
File metadata
- Download URL: fastapi_code_generator-0.6.0-py3-none-any.whl
- Upload date:
- Size: 28.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
27a6c7ee4f4f02b35e5d5f42188aa53c53cad71c63f36f2ab550482e6ac63722
|
|
| MD5 |
f8de583f636bd5c4b8d44de09f5bfcc0
|
|
| BLAKE2b-256 |
3e956e0a22014ef1ad6baf51ffc76bb7670723e2092d3fce227fd87449d0dfca
|
Provenance
The following attestation bundles were made for fastapi_code_generator-0.6.0-py3-none-any.whl:
Publisher:
publish.yml on koxudaxi/fastapi-code-generator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastapi_code_generator-0.6.0-py3-none-any.whl -
Subject digest:
27a6c7ee4f4f02b35e5d5f42188aa53c53cad71c63f36f2ab550482e6ac63722 - Sigstore transparency entry: 1411815113
- Sigstore integration time:
-
Permalink:
koxudaxi/fastapi-code-generator@b1c8c22e2fc41e4756e703a1df351c06753886a1 -
Branch / Tag:
refs/tags/0.6.0 - Owner: https://github.com/koxudaxi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b1c8c22e2fc41e4756e703a1df351c06753886a1 -
Trigger Event:
push
-
Statement type: