Skip to main content

A small framework to build your flexible project configurations

Project description

ConfigFramework

A small and simple framework to build your configs.

This project been created mostly because of me myself needing some simplistic and same time powerful enough tool to create configs, validate them and to have simple interface.

Installing

Pypi link: https://pypi.org/project/ConfigFramework

pip install ConfigFramework

Example of usage

Here's basic example:

from ConfigFramework import loaders, variables, BaseConfig


first_loader = loaders.JsonStringLoader.load('{"Is it simple?": true}', defaults={"useful?": "maybe", "pi": 2.74})
second_loader = loaders.JsonStringLoader.load('{"Is it simple?": false, "Var": "value"}')
composite_loader = loaders.CompositeLoader.load(first_loader, second_loader)


class Config(BaseConfig):
    is_simple = variables.BoolVar("Is it simple?", first_loader)
    is_useful = variables.ConfigVar("useful?", first_loader, validator=lambda v: v == "maybe")
    pi = variables.FloatVar("pi", first_loader, default=3.14, constant=True, validator=lambda v: v == 3.14)

    class NestedConfig(BaseConfig):
        are_composite_loaders_simple = variables.BoolVar("Is it simple?", composite_loader)

        def __post_init__(self, *args, **kwargs):
            yes_or_no = 'Yes' if self.are_composite_loaders_simple.value else 'No'
            print(f"Is it simple to use composite loaders? {yes_or_no}")
            print("Nested config:", kwargs['phrase'])

    def __post_init__(self, *args, **kwargs):
        print(f"ConfigFramework is {'simple' if self.is_simple.value else 'hard'} and {self.is_useful.value} useful")
        print(f"Here's pi = {self.pi.value}")
        print("Main config:", kwargs['phrase'])


config = Config(phrase="Here's a way to pass variables")

try:
    print("pi is constant:", config.pi.is_constant)
    config.pi.value = 2.22

except NotImplementedError:
    print("You can not set value to constants on runtime")

See examples with explanation here

Supported formats

Config formats:

  • Yaml
  • Json (strings or files)
  • Environment variables
  • Composite loading from multiple simple loaders

Features

  • Loading configs from multiple sources
  • Creating custom loaders and variables types
  • Nested configs
  • Flexible configs definition
  • Config values validations
  • Casting variables values to specific types using functions
  • Casting to acceptable variable type before dumping variable to loader
  • Default values for per loader or per variable
  • Translating one config loaders data to other (with or without including default values for each one)
  • Composite loaders that allow you to define where to look up values using only one loader, that handles combining others

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

ConfigFramework-2.0.1.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ConfigFramework-2.0.1-py3-none-any.whl (26.5 kB view details)

Uploaded Python 3

File details

Details for the file ConfigFramework-2.0.1.tar.gz.

File metadata

  • Download URL: ConfigFramework-2.0.1.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for ConfigFramework-2.0.1.tar.gz
Algorithm Hash digest
SHA256 671775087e2f0f791cc598658539b24350092c2cccb7ed4f7fe7e288f04db351
MD5 c8d900c886702eb1f0162fdb5097647a
BLAKE2b-256 2f0a2a3a6cf2493a8814f527cde0b5e8e6b1c06b553f23b2517a2c05699ae23a

See more details on using hashes here.

File details

Details for the file ConfigFramework-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: ConfigFramework-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 26.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for ConfigFramework-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d6eefab42fe9a0fa96bfc926a3afe9a76d6ae570760bcd100a79fe84c067740b
MD5 87a5941817cf2e1b9debd2b254e32d64
BLAKE2b-256 8eff0011e5a120d6f19c475b5490ba9fdc6cc7782ee7292af0ba0bc6a2a2fe38

See more details on using hashes here.

Supported by

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