Enable Starlette Config
to load pyproject.toml
metadata
#20
br3ndonland
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Description
Python now supports a
pyproject.toml
file for project metadata. PEP 621 defined how to store package metadata and dependencies inpyproject.toml
.Settings models like Starlette
Config
could benefit from the ability to read project metadata frompyproject.toml
.Suggestions
Add optional dependencies
Add Starlette and
tomli
as optional dependencies, with a marker to indicate thattomli
is only needed on Python <3.11.Python 3.11 added a new TOML library,
tomllib
. There doesn't appear to be a backport for earlier versions of Python, but thetomllib
API is basically the same astomli
, sotomli
can be used for Python <3.11.Add a utility function for loading TOML files
To start, add a simple function to
fastenv.utilities
for loading TOML files.The new code in
fastenv.utilities
could look something like this:Add the utility function to the Starlette
Config
modelAdd a module
fastenv.settings.starlette_config
(if not already added by #19) that importsstarlette.config
and adds atoml_file
argument.Rough suggestion for
fastenv.settings.starlette_config
:And then a project might use it with something like:
Add tests
Add some unit tests that load
fastenv/pyproject.toml
and make assertions on the resultant values, and potentially some tests on example TOML files (could be added toconftest.py
as docstrings and made into pytest fixtures).Related
tomllib
Beta Was this translation helpful? Give feedback.
All reactions