Skip to main content

Extensible library for separation of settings from code.

Project description

ClassyConf

PyPI Run tests codecov

carbon

ClassyConf is the configuration architecture solution for perfectionists with deadlines.

It provides a declarative way to define settings for your projects contained in a class that can be extended, overriden at runtime, config objects can be passed around modules and settings are lazily loaded, plus some other goodies.

You can find out more documentation at Read the Docs website, and the intro post here to understand the motivations behind it.

Here is a preview of how to use it:

from classyconf import Configuration, Value, Environment, IniFile, as_boolean, EnvPrefix

class AppConfig(Configuration):
    """Configuration for My App"""
    class Meta:
        loaders = [
            Environment(keyfmt=EnvPrefix("MY_APP_")),
            IniFile("/etc/app/conf.ini", section="myapp")
        ]

    DEBUG = Value(default=False, cast=as_boolean, help="Toggle debugging mode.")
    DATABASE_URL = Value(default="postgres://localhost:5432/mydb", help="Database connection.")

Later this object can be used to print settings

>>> config = AppConfig()
>>> print(config)
DEBUG=True - Toggle debugging mode.
DATABASE_URL='postgres://localhost:5432/mydb' - Database connection.

or with __repr__()

>>> config = AppConfig()
>>> config
AppConf(loaders=[Environment(keyfmt=EnvPrefix("MY_APP_"), EnvFile("main.env")])

extended

class TestConfig(AppConfig):
    class Meta:
        loaders = [IniFile("test_settings.ini"), EnvFile("main.env")]

overridden at runtime

>>> dev_config = AppConfig(loaders=[IniFile("dev_settings.ini")])
>>> dev_config.DEBUG
True

accessed as dict or object

>>> config.DEBUG
False
>>> config["DEBUG"]
False

iterated

 >>> for setting in config:
...     print(setting)
...
('DEBUG', Value(key="DEBUG", help="Toggle debugging on/off."))
('DATABASE_URL', Value(key="DATABASE_URL", help="Database connection."))

or passed around

def do_something(cfg):
    if cfg.DEBUG:   # this is evaluated lazily
         return

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

classyconf-0.5.2.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

classyconf-0.5.2-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file classyconf-0.5.2.tar.gz.

File metadata

  • Download URL: classyconf-0.5.2.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.9.5 Linux/5.12.9-300.fc34.x86_64

File hashes

Hashes for classyconf-0.5.2.tar.gz
Algorithm Hash digest
SHA256 b04c7e7de2d00feefb85dbe1b72c4ab932f6135cdb8e6eccd73f7ccfa5fd63a9
MD5 cc5d344b1ede4c95281b6fb92143f9df
BLAKE2b-256 b4a84f5fdb6c44f82de71eded5a81af23a7d388fec1e7719fd82b6c4a84aff56

See more details on using hashes here.

File details

Details for the file classyconf-0.5.2-py3-none-any.whl.

File metadata

  • Download URL: classyconf-0.5.2-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.9.5 Linux/5.12.9-300.fc34.x86_64

File hashes

Hashes for classyconf-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d8a3f3d3c8d0ef898772b87369699bacc8c9e910102f64adec4c95e7cfc5428d
MD5 a002caa81514d9f1ef373a005dff9dbb
BLAKE2b-256 658feb533876435560eb865ebce089cc6b65c3efc9450109d15309b632b8950f

See more details on using hashes here.

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