ApPySetty ⚙️
A simple, type-safe Python library for managing application configuration from environment variables and YAML.
ApPySetty uses Python dataclasses as the single definition of your application configuration. It can load values from configuration files and environment variables and generate documentation from the same definition.
Quick Start
Install:
uv add appysetty
Define your configuration:
from dataclasses import dataclass
from appysetty import AppConfigSource, read_configuration
@dataclass
class Config:
host: str = "localhost"
port: int = 8080
debug: bool = False
config = read_configuration(
Config,
AppConfigSource.ENV,
)
Override values with environment variables:
export HOST="0.0.0.0"
export PORT="9000"
export DEBUG="true"
Or load them from YAML:
host: localhost
port: 8080
debug: false
config = read_configuration(
Config,
AppConfigSource.YAML,
)
And also document your configuration with an example yaml and a markdown document:
write_configuration_documentation(Config, output_dir=Path("./docs"))
Configuration Sources
ApPySetty currently supports:
ENV: environment variables using UPPER_SNAKE_CASE onlyYAML: YAML configuration files
Multiple sources can be combined. Later sources overwrite values from earlier sources:
config = read_configuration(
Config,
[
AppConfigSource.YAML,
AppConfigSource.ENV,
],
)
By default, YAML files are searched for in:
config.yaml
config.yml
config/config.yaml
config/config.yml
An explicit YAML path can also be provided.
Usage Details
Define Config
First you need to define a dataclass which contains all the configuration options you want to support.
@dataclass
class Config:
host: str = "localhost"
port: int = 8080
debug: bool = False
timeout: float = 5.0
You can also extend your dataclass with additional information for better documentation and for masking secrets:
@dataclass
class ConfigWithMetadata:
host: Annotated[
str,
AppConfigEntry(description="The application host"),
] = "localhost"
password: Annotated[
str,
AppConfigEntry(description="The database password", is_secret=True),
] = "secret"
Both variants can be mixed. If no description is provided, the name of the field will be the description.
Read Config
To read the config, use:
cfg = read_configuration(ConfigWithMetadata, AppConfigSource.ENV)
After that cfg should have all configurations with auto-complete ready for you.
You can also pass an instance and use multiple sources, where each source will overwrite the previous one:
cfg = read_configuration(
ConfigWithMetadata(), [AppConfigSource.ENV, AppConfigSource.YAML]
)
The available sources are:
| Key | Source | Description |
|---|---|---|
AppConfigSource.ENV |
Environment | This will read config from environment, using UPPER_SNAKE_CASE variant of the field name |
AppConfigSource.YAML |
YAML file | This will read the config from a yaml file, only matching field name exactly |
Options
Options can be used to customize the config:
cfg = read_configuration(
ConfigWithMetadata,
[AppConfigSource.ENV, AppConfigSource.YAML],
AppConfigOptions(
env_prefix="MY_APP_PREFIX",
yaml_path="config.dev.yaml",
overwrite={"port": "8000"},
),
)
| Option | Description |
|---|---|
env_prefix |
A Prefix that will be prepended to all field names using UPPER_SNAKE_CASE to read environment . |
yaml_path |
Setting a specific yaml file to use. It unset, the tool will look for (config)/config.y(a)ml. |
overwrite |
This accepts a mapping. values set with overwrite will always overwrite anything else |
Write Documentation
The second feature of this tool is automated creation of a few documentation items for configuration options:
config.example.yamlcontaining an example yaml file with default values and descriptive comments (if descriptions were defined)DefaultConfiguration.mdcontaining a table of all options with ENV variant, a docker environment block for docker compose and a docker run example command with all -e set.
To create the documentation, use:
# Create both documents
write_configuration_documentation(
ConfigWithMetadata, env_prefix="MY_APP_PREFIX", output_dir=Path()
)
# Only create yaml example
write_config_yaml_example(ConfigWithMetadata, output_dir=Path())
# Only create markdown document
write_config_markdown(ConfigWithMetadata, env_prefix="MY_APP_PREFIX", output_dir=Path())
Development
Clone the repository and install the development dependencies:
git clone https://github.com/SmartFactory-KL/appysetty.git
cd appysetty
uv sync
Run the tests:
uv run pytest
Run tests with coverage:
uv run pytest --cov=appysetty --cov-report=term-missing
Run the examples:
uv run python -m examples.write_documentation
uv run python -m examples.read_documentation
License
ApPySetty is licensed under the MIT License.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file appysetty-0.1.0.tar.gz.
File metadata
- Download URL: appysetty-0.1.0.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
66097ae0ab1992d4151a71ace52929524da49b285b31cc106d2ba0f3d9ec8cf8
|
|
| MD5 |
221edc86e8193b7d9df6854f1590bf6f
|
|
| BLAKE2b-256 |
57438b89b8f3c4a8885c9c5a0ff19aa02205fdfc97db637f4631abeed2dd9eef
|
Provenance
The following attestation bundles were made for appysetty-0.1.0.tar.gz:
Publisher:
publish.yml on SmartFactory-KL/appysetty
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
appysetty-0.1.0.tar.gz -
Subject digest:
66097ae0ab1992d4151a71ace52929524da49b285b31cc106d2ba0f3d9ec8cf8 - Sigstore transparency entry: 2847087045
- Sigstore integration time:
-
Permalink:
SmartFactory-KL/appysetty@0fa95d1561878e214a813f994f56dd8c4fae71c6 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/SmartFactory-KL
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0fa95d1561878e214a813f994f56dd8c4fae71c6 -
Trigger Event:
release
-
Statement type:
File details
Details for the file appysetty-0.1.0-py3-none-any.whl.
File metadata
- Download URL: appysetty-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e4e45d56ccdc2e4772a770a6f1f4833cefb912ff61213b60a870ae9ba0039b3
|
|
| MD5 |
a7f04eb00a0b5011e5216c431ea38d66
|
|
| BLAKE2b-256 |
8e588dfacfd71e9dd2967fffe4c591b5189fe3f297959f0960206788b88c4f8b
|
Provenance
The following attestation bundles were made for appysetty-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on SmartFactory-KL/appysetty
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
appysetty-0.1.0-py3-none-any.whl -
Subject digest:
4e4e45d56ccdc2e4772a770a6f1f4833cefb912ff61213b60a870ae9ba0039b3 - Sigstore transparency entry: 2847087092
- Sigstore integration time:
-
Permalink:
SmartFactory-KL/appysetty@0fa95d1561878e214a813f994f56dd8c4fae71c6 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/SmartFactory-KL
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0fa95d1561878e214a813f994f56dd8c4fae71c6 -
Trigger Event:
release
-
Statement type: