Skip to main content

Generate a FastAPI app from an OpenAPI file.

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastapi_code_generator-0.7.0.tar.gz (58.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastapi_code_generator-0.7.0-py3-none-any.whl (28.8 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_code_generator-0.7.0.tar.gz.

File metadata

  • Download URL: fastapi_code_generator-0.7.0.tar.gz
  • Upload date:
  • Size: 58.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for fastapi_code_generator-0.7.0.tar.gz
Algorithm Hash digest
SHA256 9364221d98abffc422f3b6e2cd9ccf9a5379496be1f3b7b18a38a26a1d311f5d
MD5 1e58786f50e4d4691cb9ef3ee685c5d1
BLAKE2b-256 91845917cb631053247bee80682e2c5ff8e4ef298cc54cbc10519d70a4a40d18

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastapi_code_generator-0.7.0.tar.gz:

Publisher: publish.yml on koxudaxi/fastapi-code-generator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastapi_code_generator-0.7.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_code_generator-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7c2ca71462e9947382befb620550062d257599e5e8200bd3d959fc3f06722d5d
MD5 4a00d28d3e81a1e0eb10eb08deacd59d
BLAKE2b-256 aa7ecf0a8a407ae1c7cc22edebf77393f687bd09c69fc5cf54cd99a39ce3fccf

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastapi_code_generator-0.7.0-py3-none-any.whl:

Publisher: publish.yml on koxudaxi/fastapi-code-generator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page