Metadata-Version: 2.4
Name: advexp-configuration
Version: 0.1.0
Summary: Read-only application configuration for Python
Author: Alexey Ivakin
License-Expression: Apache-2.0
Project-URL: Homepage, https://advexp.net
Project-URL: Documentation, https://docs.advexp.net/configuration/
Project-URL: Repository, https://github.com/advexp/advexp.settings.python
Project-URL: Issue tracker, https://github.com/advexp/advexp.settings.python/issues
Keywords: configuration,config,settings,appconfig,environment-variables,dotenv,json,toml,yaml
Classifier: Development Status :: 1 - Planning
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development :: Libraries
Classifier: Typing :: Typed
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: advexp-settings-base==0.1.0
Provides-Extra: dotenv
Requires-Dist: python-dotenv; extra == "dotenv"
Provides-Extra: toml
Requires-Dist: tomli; python_version < "3.11" and extra == "toml"
Provides-Extra: yaml
Requires-Dist: ruamel.yaml<0.20,>=0.18; extra == "yaml"
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Requires-Dist: tomli; python_version < "3.11" and extra == "test"
Requires-Dist: ruamel.yaml<0.20,>=0.18; extra == "test"
Requires-Dist: python-dotenv; extra == "test"
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Requires-Dist: build; extra == "dev"
Requires-Dist: twine; extra == "dev"
Requires-Dist: ruff==0.16.5; extra == "dev"
Requires-Dist: mypy==1.20.2; extra == "dev"
Requires-Dist: python-dotenv; extra == "dev"
Dynamic: license-file

# Advexp.Configuration: the read-only package

Typed, read-only application configuration for Python.

Advexp.Configuration is the read-only counterpart of
[Advexp.Settings](https://docs.advexp.net/settings/). Declare your
configuration once as a typed class. The library loads it from a chain of
pluggable sources and never writes anything back.

```python
from datetime import timedelta

import advexp.configuration as adv_config
import advexp.configuration.plugins.environment.variables as env
import advexp.configuration.plugins.json_settings as js


class AppConfig(
    adv_config.Configuration,
    options=adv_config.Sources(
        env.env_source(name_prefix="APP_", name_case=env.NameCase.UPPER),
        js.json_source(file="app-configuration.json"),
    ),
):
    # read from APP_MODE — the prefix plus the member name in upper
    # case — or, with no such variable, from the JSON file's key
    # (the module, class and member, dotted)
    mode: str = "production"

    # the same chain as mode — APP_SESSION_TTL first, else the JSON
    # key — in the rich chain_setting form, which carries the default
    session_ttl: timedelta = adv_config.chain_setting(
        default=timedelta(minutes=30)
    )

    # read from the "retries" key of the JSON file
    retries: int = js.json_setting(name="retries", default=3)


# suppose the environment contains APP_SESSION_TTL=1:30:00
AppConfig.load_configuration()

# prints datetime.timedelta(seconds=5400):
# the value is parsed into a timedelta, not left as a string
print(repr(AppConfig.session_ttl))
```

> **Status:** This project is a work in progress. The package structure is
> in place, but the public API is still under development and may change
> before the first stable release.

## Installation

```bash
pip install advexp-configuration
```

## Why Advexp.Configuration

- **Plain declarations.** Declare a member with a type annotation. Add a
  value to give it a default, or leave the value out to make it required.
  The sources configured on the class determine where the values come from.
- **Typed values.** Values are converted to the annotated type when they
  are loaded, so a member always holds a value of its declared type.
- **Class-level operations.** You load the configuration on the class
  itself. There are no instances to create or pass around.
- **Read-only by design.** The library never writes to sources, and loaded
  values are read-only: assigning to a declared member raises `TypeError`.
  To pick up new values after the sources change, call
  `load_configuration()` again.
- **A chain of sources.** Sources are read in the order in which they are
  listed, and the first source that has a value wins. If no source has a
  value, the member gets its declared default.
- **Pluggable sources.** Environment variables, dotenv, JSON, TOML, and
  YAML files are supported out of the box, and a mapping source reads
  values from a dictionary. A custom source is a plain plugin class.
- **No third-party dependencies.** Installed without extras, the package
  pulls in nothing beyond its own family: its only dependency is
  `advexp-settings-base`, the family's shared base package, which itself
  depends on nothing. Environment variables and JSON files run on the
  standard library alone, and each parser that is not already in the
  standard library arrives as an extra.
- **Shared type conversion.** Dataclasses, datetimes, decimals, UUIDs,
  secrets, and nested containers are converted from source values using the
  same rules as in Advexp.Settings.
- **Validation.** Value constraints and rules that involve several members
  (cross-member rules) are checked when the class is created and at the end
  of every load.
- **One file per environment.** A file name can contain a placeholder that
  is filled in from an environment variable. For example,
  `settings-{APP_ENV}.json` gives you a separate file for each environment.
- **A read-write counterpart.** The Advexp.Settings package loads **and
  saves** values through its backends. Both packages use the same
  declaration syntax, so you can usually move a class between them by
  changing the base class and the imports.

## Where to go next

- [Project site](https://advexp.net/advexp.configuration/): the
  Advexp.Configuration product page.
- [Getting started](https://docs.advexp.net/configuration/getting-started/):
  installation and your first configuration class.
- [Backends](https://docs.advexp.net/backends/): environment variables,
  dotenv, JSON, TOML, and YAML files. Configuration sources correspond to
  these backends.
- [Value types](https://docs.advexp.net/value-types/): supported types and
  how they are converted from source values.
- [Validation](https://docs.advexp.net/validation/): value constraints and
  cross-member rules.
- [Dynamic settings](https://docs.advexp.net/dynamic-settings/#reading-a-written-collection):
  reading a collection written by Advexp.Settings.
- [Samples](https://docs.advexp.net/samples/): runnable example programs
  for both packages, located in the project's repository.
- [Settings](https://docs.advexp.net/settings/): Advexp.Settings, the
  read-write counterpart.
- [API reference](https://docs.advexp.net/api/): classes, exceptions, and
  plugin interfaces, generated from the docstrings.

## License

Apache License 2.0. The full text is at
<https://www.apache.org/licenses/LICENSE-2.0> and in the LICENSE file.
