Skip to main content

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

from attr import frozen, field
import click

import typed_settings as ts


@frozen
class Host:
    name: str
    port: int = field(converter=int)


@frozen(kw_only=True)
class Settings:
    url: str
    default: int = 3
    host: Host = field(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()

Metadata

Release files for typed-settings 0.2

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

Source distribution (sdist)

Source distribution for typed-settings 0.2
File Size Uploaded Provenance Actions
typed-settings-0.2.tar.gz 5.4 kB Without provenance Details for typed-settings-0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for typed-settings 0.2
File Interpreter ABI Platform Actions
typed_settings-0.2-py3-none-any.whl Python 3 none any Details for typed_settings-0.2-py3-none-any.whl

Total release size: 11.0 kB

Release files / typed-settings-0.2.tar.gz

Download URL typed-settings-0.2.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
386124778bd680eec501f3bfe4787c4860f914eec71fa1101d21fc14dbb9bd93
BLAKE2b-256 checksum
How to use checksums
f437f4bf9f45129123fd6083bae9f230c1796af73cc3c51426c8f684f1151b16
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

Release files / typed_settings-0.2-py3-none-any.whl

Download URL typed_settings-0.2-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
915e9e7ccc2e89665029caa0b626b011f96b0ce7e2d86c8ccbe5c8469d207f37
BLAKE2b-256 checksum
How to use checksums
716f6493898bd5bf6a56e77301e1df09650b1d338f292800c3e1d32b76576280
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

Security for typed-settings 0.2

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2 This release

2 release files No provenance

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