Skip to content

Conversation

mattmess1221
Copy link

This change allows configuration using both environment variables and a pyproject.toml file.

Environment variables

This takes advantage of the builtin functionality in click for loading options from environment variables. The prefix is FASTAPI.

Example:

$ export FASTAPI_DEV_PATH="server/app.py" FASTAPI_DEV_PORT="8001"
$ fastapi dev

Environment variables for each option are listed in the --help text.

Project configuration

If a pyproject.toml file exists in the current directory and contains the table tool.fastapi.cli, its keys will be merged into the click parameters. If a subtable matching the command exists, its keys will also be merged into the parameters, allowing for more precise configuration.

Example:

[tool.fastapi.cli]
app = "server/app.py"

[tool.fastapi.cli.run]
workers = 4

@mattmess1221
Copy link
Author

My PR seems to have exposed a bug in the tests when importing the app. I fixed it in 260242e. Feel free to cherry-pick it.

@mattmess1221 mattmess1221 changed the title Enable configuration via pyproject.toml and environment variables feat: Enable configuration via pyproject.toml and environment variables May 9, 2024
@mattmess1221 mattmess1221 force-pushed the config branch 2 times, most recently from 391eb99 to 52a9adf Compare May 16, 2024 17:11
@github-actions github-actions bot added the conflicts Automatically generated when a PR has a merge conflict label Sep 5, 2025
Copy link
Contributor

github-actions bot commented Sep 5, 2025

This pull request has a merge conflict that needs to be resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conflicts Automatically generated when a PR has a merge conflict
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant