Loadfig
Official loadfig documentation.
Minimalistic library for loading tool-specific configuration from configuration files (either .<tool>.toml or pyproject.toml).
loadfig.config ¶
Load tool config from dedicated TOML files or pyproject.toml.
The following paths are checked in order (first found used):
.{name}.tomlin the start directory or a VCS-marked parent directory.config/{name}.tomlin the start directory or a VCS-marked parent directorypyproject.tomlin the start directory or a VCS-marked parent directory
Note
Parsed TOML files are loaded once and cached for subsequent usage.
Example:
Assume the following 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"
[!IMPORTANT] Automatically returns only the relevant configuration, not the content of the whole file.
[!WARNING] Empty dictionaries are returned if no configuration was found, client code should handle this case (and have a config with default values to use in such cases).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name | str | The name of the tool to search for in the configuration file. | required |
directory | Path | str | None | The directory where lookup starts. If not provided, the current working directory is used. | None |
vcs | bool | Whether VCS-marked parent directories are considered. Note: This searches for | True |
Raises:
| Type | Description |
|---|---|
TOMLDecodeError | If a found TOML file cannot be decoded. |
Returns:
| Type | Description |
|---|---|
dict[Any, Any] | Configuration dictionary of the tool or an empty dictionary |
dict[Any, Any] | if no configuration was found. |
Source code in src/loadfig/_config.py
loadfig.pyproject ¶
Read pyproject.toml configuration file.
The following paths are checked in order (first found used):
pyproject.tomlin thedirectory(if not specified,cwdis used)pyproject.tomlup the tree ifvcsistrue
Note
pyproject.toml is loaded once and cached for subsequent usage.
Example:
Assume the following pyproject.toml file at the root of your project:
pyproject = loadfig.pyproject()
# Get all pyproject dependencies
pyproject["project"]["dependencies"]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory | Path | str | None | The directory where lookup starts. If not provided, the current working directory is used. | None |
vcs | bool | Whether VCS-marked parent directories are considered. Note: This searches for | True |
Raises:
| Type | Description |
|---|---|
TOMLDecodeError | If a found |
Returns:
| Type | Description |
|---|---|
dict[Any, Any] |
|
dict[Any, Any] | if no |