Skip to main content

Tests PyPI version

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 and read from Environment:

from dataclasses import dataclass

from appysetty import EnvSource, read_configuration


@dataclass
class Config:
    host: str = "localhost"
    port: int = 8080
    debug: bool = False


config = read_configuration(
    Config,
    EnvSource(),
)

Or load values from YAML:

host: localhost
port: 8080
debug: false
config = read_configuration(
    Config,
    YamlSource(path="yaml_file.yaml"),
)

Or both:

config = read_configuration(
    Config,
    [YamlSource(path="yaml_file.yaml"), EnvSource()],
)

And also document your configuration with an example .yaml and a markdown document:

write_configuration_documentation(Config, output_dir=Path("./docs"))

Configuration Sources

ApPySetty uses AppConfigSource as the interface to define loaders. These sources are loaded and applied in the order they are provided.

cfg = read_configuration(
    Config, [YamlSource(...), TomlSource(...), EnvSource(...), DictSource(...)]
)

In the example above, YAML values are applied first, then environment variables, and finally dictionary values. Later sources override values from earlier sources.

The available sources are:

EnvSource() - Reading from Environment

cfg = read_configuration(Config, EnvSource(prefix="MY_PREFIX"))

For every key within the config, the key is converted to UPPER_SNAKE_CASE, the optional prefix is applied and the resulting key is used to read a value from the environment.

DictSource() - Reading from a Dict

cfg = read_configuration(Config, DictSource(input={"key": "val"}))

Values are read from the provided dictionary using the configuration field names as keys. Unknown dictionary keys are rejected.

YamlSource() - Reading from a .yaml file

cfg = read_configuration(Config, YamlSource(path="", required=True))

If path is specified, that file is used. Otherwise, the first existing file from the following list is used:

config.yml
config.yaml
config/config.yml
config/config.yaml

If required is False, a missing file will simply be ignored. If required is True an AppConfigError is raised. By default required is set to True.

TomlSource() - Reading from a .toml file

cfg = read_configuration(Config, TomlSource(path="", required=True))

If path is specified, that file is used. Otherwise, the first existing file from the following list is used:

config.toml
config/config.toml

If required is False, a missing file will simply be ignored. If required is True an AppConfigError is raised. By default required is set to True.

Define your own source

All sources are based on the AppConfigSource. To extend the list of sources, you could supply your own implementation:

@dataclass(frozen=True)
class MyOwnSource(AppConfigSource):
    """Example for your source, based on the DictSource"""

    input: dict[str, str]

    def load(self, config_type_hints):
        values: dict[str, object] = {}

        for name, value in self.input.items():
            ...

        return values

Define Config

The simplest form of a config class looks like this:

@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"

    debug: bool = False

Both variants can be mixed. If no description is provided, the name of the field will be the description.

Write Documentation

One feature of this tool is automating the documentation items for configuration options:

  • config.example.yaml containing an example YAML file with default values and descriptive comments (if descriptions were defined)
  • DefaultConfiguration.md containing a table of all options with ENV variant, a docker compose 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

Run Ruff:

uv run ruff check
uv run ruff format .

License

ApPySetty is licensed under the MIT License.

Release files for appysetty 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for appysetty 0.5.0
File Size Uploaded
appysetty-0.5.0.tar.gz 8.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for appysetty 0.5.0
File Interpreter ABI Platform
appysetty-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 19.4 kB

Release files / appysetty-0.5.0.tar.gz

Download URL appysetty-0.5.0.tar.gz
Size 8.4 kB
Tags Source
SHA-256 checksum
How to use checksums
c3f86a80e6f724bed98dcadafe77db1285d5378cbe478fb464d5b7bfd13e6b2f
BLAKE2b-256 checksum
How to use checksums
a546c9d465599de25320068e79f684aa4062cf7f958c3244e0c0c023eb2c99aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 25, 2026.

Transparency log

Release files / appysetty-0.5.0-py3-none-any.whl

Download URL appysetty-0.5.0-py3-none-any.whl
Size 11.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
13d97a1604de3757bc787385c8e83077c909dcf05f0f04acecc42c24e30feee7
BLAKE2b-256 checksum
How to use checksums
9d4cfff02a0a3999e9c47feaa1c31c2676526f0bb8b302b3a441ac6377af1955
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 25, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page