loadfig¶
Features¶
loadfig is a Python package designed to load pyproject and TOML configuration files adhering to modern standards:
- Unified: Load your configuration either from
.<mytool>.toml,.config/mytool.tomlorpyproject.toml(section[tool.mytool]) using single line:tool_config = loadfig.config(name="<mytool>") - Load
pyproject.toml: Find and load the wholepyproject.tomlusing single line:pyproject = loadfig.pyproject() - No dependencies: Python-only, no third-party dependencies.
- Do one thing well: Only load the configuration, use other libraries like
python-dotenv⧉ for bells and whistles. - Git-aware: Automatically detects project's
rootusing git (or other VCS), no need to specify the path to your configuration file.
Where can I use it?¶
When creating Python tools and you want to:
- give your users a standard place to configure it (
pyproject.tomlor.<mytool>.toml) - make the choices readable and findable
- create tools without maintaining boilerplate
Quick start¶
Installation¶
Usage¶
pyproject.toml loading¶
One line is all you need:
# Returns dict with all pyproject contents
pyproject = loadfig.pyproject()
# Get the name of the project
print(pyproject["project"]["name"])
Tool configuration loading¶
Assume you have the following section in your pyproject.toml file at the root of your project:
You can load the configuration for mytool using:
import loadfig
config = loadfig.config("mytool")
config["name"] # "My Tool"
config["version"] # "1.0.0"
That is all you will likely need to do to load your configuration for your Python project (in a modern, unified way).
Important
pyproject.toml can be located at the root of your project, while the loading file can be in a subfolder (e.g. src/mytool/loader.py).
See documentation ⧉ for more details about the arguments and options available.