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+ (seepyproject.toml:requires-python). - A package manager:
pyproject.tomlis set up for PDM ([build-system]usespdm-backend) and the project ships auv.lock, souvworks equally well. The CI workflows install withuv.
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 devThis installs:
- The runtime dependencies from
[project.dependencies](starlette,pydantic,typing-extensions,typing-inspection,annotated-doc). - Every optional extra (
standard,all, …). - The
devgroup, which transitively pulls intests,docs,translations, plus tooling likeplaywright,prek,zizmor.
If you prefer PDM:
pdm install -G:allRun the tests
bash scripts/test.shThe 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_codepyproject.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 formatThe 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 installRun 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 sitescripts/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
fastapicommand — it is provided by the separatefastapi-clipackage, optional and resolved via thestandardextra.fastapi/cli.pyis a five-line wrapper that re-raisesImportErrorwith a helpful message. - The hosted documentation deploy —
.github/workflows/deploy-docs.ymlruns that.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.
Previous
Architecture
Next
Glossary