Metadata-Version: 2.1
Name: typed-settings
Version: 0.4
Summary: Typed settings based on attrs classes
Home-page: https://gitlab.com/sscherfke/typed-settings
Author: Stefan Scherfke
Author-email: stefan@sofa-rockers.org
Maintainer: Stefan Scherfke
Maintainer-email: stefan@sofa-rockers.org
License: MIT
Project-URL: Documentation, https://gitlab.com/sscherfke/typed-settings
Project-URL: Bug Tracker, https://gitlab.com/sscherfke/typed-settings/-/issues
Project-URL: Source Code, https://gitlab.com/sscherfke/typed-settings
Keywords: settings,types,configuration,options
Platform: UNKNOWN
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.7
Description-Content-Type: text/markdown
Requires-Dist: attrs
Requires-Dist: toml
Provides-Extra: click
Requires-Dist: click ; extra == 'click'
Provides-Extra: dev
Requires-Dist: click ; extra == 'dev'
Requires-Dist: pytest (>=6) ; extra == 'dev'
Requires-Dist: pytest-cov ; extra == 'dev'
Requires-Dist: coverage[toml] (>=5.0.2) ; extra == 'dev'
Requires-Dist: flake8 ; extra == 'dev'
Requires-Dist: flake8-bandit ; extra == 'dev'
Requires-Dist: flake8-black ; extra == 'dev'
Requires-Dist: flake8-bugbear ; extra == 'dev'
Requires-Dist: flake8-isort ; extra == 'dev'
Requires-Dist: mypy ; extra == 'dev'
Requires-Dist: nox ; extra == 'dev'
Requires-Dist: safety ; extra == 'dev'
Provides-Extra: lint
Requires-Dist: click ; extra == 'lint'
Requires-Dist: flake8 ; extra == 'lint'
Requires-Dist: flake8-bandit ; extra == 'lint'
Requires-Dist: flake8-black ; extra == 'lint'
Requires-Dist: flake8-bugbear ; extra == 'lint'
Requires-Dist: flake8-isort ; extra == 'lint'
Requires-Dist: mypy ; extra == 'lint'
Provides-Extra: test
Requires-Dist: click ; extra == 'test'
Requires-Dist: pytest (>=6) ; extra == 'test'
Requires-Dist: pytest-cov ; extra == 'test'
Requires-Dist: coverage[toml] (>=5.0.2) ; extra == 'test'

[![pipeline status](https://gitlab.com/sscherfke/typed-settings/badges/main/pipeline.svg)](https://gitlab.com/sscherfke/typed-settings/-/commits/main)
[![coverage report](https://gitlab.com/sscherfke/typed-settings/badges/main/coverage.svg)](https://gitlab.com/sscherfke/typed-settings/-/commits/main)

# Typed Settings

PoC for library for managing (typed) settings – for server processes as
well as commandline programms.


## Requirements

- Default settings are defined by app and can be overridden by config
  files, environment variables and click options.

- You define settings as attrs class with types, converters and
  validators.

- Attributes are basic data types (bool, int, float, str), lists of
  basic types, or nested settings classes.

- Settings can be loaded from multiple config files.

- Config files are allowed to contain settings for multiple apps (like
  `pyproject.toml`)

- Paths to config files have to be explicitly named.  Most defaults are
  not useful in many cases and have to be changed anyways.

- Additional paths for config files can be specified via an environment
  variable.  As in `PATH`, multiple paths are separated by a `:`.  The
  last file in the list has the highest priority.

- Environment variables with a defined prefix override settings from
  config files.  This can optionally be disabled.

- [Click](https://click.palletsprojects.com/) options for some or all
  settings can be generated.  They are passed to the cli function as
  a single object (instead of individually).

- Settings must be explicitly loaded, either via
  `typed_settings.load_settings()` or via
  `typed_settings.click_options()`.

- Both functions allow you to customize config file paths, prefixes et
  cetera.


## Example

```python
import click

import typed_settings as ts


@ts.settings
class Host:
    name: str
    port: int = ts.option(converter=int)


@ts.settings(kw_only=True)
class Settings:
    url: str
    default: int = 3
    host: Host = ts.option(converter=lambda d: Host(**d))


settings = ts.load_settings(
    settings_cls=Settings, appname='example', config_files=['settings.toml']
)
print(settings)


@click.command()
@ts.click_options(Settings, 'example', ['settings.toml'])
def main(settings):
    print(settings)


if __name__ == '__main__':
    main()
```


