Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Enable configuration via pyproject.toml and environment variables #18

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

killjoy1221
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

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

@killjoy1221 killjoy1221 changed the title Enable configuration via pyproject.toml and environment variables feat: Enable configuration via pyproject.toml and environment variables May 9, 2024
@killjoy1221 killjoy1221 force-pushed the config branch 2 times, most recently from 391eb99 to 52a9adf Compare May 16, 2024 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant