Skip to main content

fastapi-code-generator

Generate a FastAPI application from an OpenAPI document.

PyPI version Downloads PyPI - Python Version codecov license Code style: black

📣 💼 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.
  --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.

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

Release files for fastapi-code-generator 0.8.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastapi-code-generator 0.8.1
File Size Uploaded
fastapi_code_generator-0.8.1.tar.gz 61.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fastapi-code-generator 0.8.1
File Interpreter ABI Platform
fastapi_code_generator-0.8.1-py3-none-any.whl Python 3 none any Details

Total release size: 92.0 kB

Release files / fastapi_code_generator-0.8.1.tar.gz

Download URL fastapi_code_generator-0.8.1.tar.gz
Size 61.4 kB
Tags Source
SHA-256 checksum
How to use checksums
1090acac5b5c9ec7f523aa811af0b8e94ddd8392791ec6f6b64c76b976f849c6
BLAKE2b-256 checksum
How to use checksums
c21053b806d94ac0f392bd58cd79dacb2bec25b106601daf58cf6200f6005859
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 1, 2026.

Transparency log

Release files / fastapi_code_generator-0.8.1-py3-none-any.whl

Download URL fastapi_code_generator-0.8.1-py3-none-any.whl
Size 30.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8182f85afc0d5d0b47fa2b7d7866e97c431a7e5323ac23434bb9669bc8b15e81
BLAKE2b-256 checksum
How to use checksums
037fea112ec43f75289e9a2e5cf254718ba19cd127c34cf4ca5f423598778d1f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 1, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.8.1 This release

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.4

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.18

2 release files

0.0.17

2 release files

0.0.16

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page