Factory.ai

Open-Source Wikis

/

FastAPI

/

FastAPI

/

Getting started

fastapi/fastapi

Getting started

This page is for someone working on the FastAPI codebase, not someone using FastAPI to build an app. For user-facing install/quickstart instructions see https://fastapi.tiangolo.com.

Prerequisites

  • Python: the repo pins Python 3.11 in .python-version. The package itself supports Python 3.10+ (see pyproject.toml:requires-python).
  • A package manager: pyproject.toml is set up for PDM ([build-system] uses pdm-backend) and the project ships a uv.lock, so uv works equally well. The CI workflows install with uv.

Repository layout

fastapi/         # Framework source.
fastapi-slim/    # Alternate distribution — pyproject.toml only, sources reused via build hooks.
tests/           # Pytest suite, including tests/test_tutorial/ that runs docs examples.
docs_src/        # Example apps used in the docs site and exercised by tests.
docs/            # Markdown content for the documentation site (multi-language).
scripts/         # Local automation: test.sh, lint.sh, format.sh, docs.py, people.py, translate.py, …
.github/workflows/  # CI: tests, docs deploy, translation bot, sponsors page rebuild, …
pyproject.toml   # Project metadata + tool configuration.

Install for development

The simplest path uses uv:

uv sync --all-extras --group dev

This installs:

  • The runtime dependencies from [project.dependencies] (starlette, pydantic, typing-extensions, typing-inspection, annotated-doc).
  • Every optional extra (standard, all, …).
  • The dev group, which transitively pulls in tests, docs, translations, plus tooling like playwright, prek, zizmor.

If you prefer PDM:

pdm install -G:all

Run the tests

bash scripts/test.sh

The script runs pytest -n auto --dist loadgroup tests scripts/tests/ with PYTHONPATH=./docs_src so the tutorial tests can import the example apps. Any extra arguments are forwarded to pytest, so the usual flags work:

bash scripts/test.sh tests/test_security_oauth2.py -k authorization_code

pyproject.toml enables filterwarnings = ["error"], so tests fail on previously unseen warnings — keep that in mind when bumping dependencies.

To get a coverage report:

bash scripts/test-cov.sh        # combine + report
bash scripts/test-cov-html.sh   # HTML report under htmlcov/

Lint and format

bash scripts/lint.sh    # mypy + ty + ruff check + ruff format --check
bash scripts/format.sh  # ruff check --fix + ruff format

The lint script runs four tools:

Tool Scope Purpose
mypy fastapi/ Strict type checking — tool.mypy sets strict = true and the pydantic.mypy plugin.
ty fastapi/ Astral's ty type checker, used in addition to mypy.
ruff check fastapi tests docs_src scripts Lint rules: E, W, F, I, B, C4, UP.
ruff format --check fastapi tests Formatting verification. format.sh widens this to docs_src and scripts.

Pre-commit hook

.pre-commit-config.yaml is provided and prek >=0.2.22 (a fast pre-commit-compatible runner) is in the dev dependency group. Install once and hooks run automatically:

prek install   # or: pre-commit install

Run the docs site locally

python scripts/docs.py live           # serve English docs
python scripts/docs.py live es        # serve a translated language
python scripts/docs.py build-all      # build every language
python scripts/docs.py preview        # serve a built site

scripts/docs.py is the entry point for everything documentation-related, including translation orchestration, Material insiders detection, and per-language MkDocs config generation. It depends on the docs group in pyproject.toml.

Build the package

pdm build           # produces sdist + wheel under dist/

fastapi-slim/ builds an alternate distribution from the same sources by pointing its own pyproject.toml at the parent directory; see .github/workflows/test-redistribute.yml for the workflow that exercises both builds.

What you cannot run from this repo

  • The CLI fastapi command — it is provided by the separate fastapi-cli package, optional and resolved via the standard extra. fastapi/cli.py is a five-line wrapper that re-raises ImportError with a helpful message.
  • The hosted documentation deploy — .github/workflows/deploy-docs.yml runs that.

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

Getting started – FastAPI wiki | Factory