Skip to main content

Setting management library

Project description

Seth

A setting management library. By grouping all your application settings in one class, it's easier to document.

First, define a class for your settings. It must be a dataclass (or even better, a frozen dataclass) and inherit from seth.Settings.

from dataclasses import dataclass
from typing import Optional

from bl_seth import Settings

@dataclass
class MySettings(Settings):
    MANDATORY: str
    "A mandatory string."
    
    DEFAULT: str = "default"
    """A string that defaults to '"default"'."""

    INTEGER: int = 1
    "An integer that defaults to '1'."

    OPTIONAL: Optional[str] = None
    "An optional value."

Then instantiate it using its from_dict class method. Most probably, the dictionary is built from the environment.

import os

settings = MySettings.from_dict(os.environ)

You can now directly access its attributes.

settings.DEFAULT == "default"
settings.OPTIONAL is None

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bl-seth-0.2.0.tar.gz (14.6 kB view hashes)

Uploaded Source

Built Distribution

bl_seth-0.2.0-py3-none-any.whl (15.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page