Skip to main content

A way to define configuration files through classes, save it and load configuration from json/yaml

Project description

#pyConfObject

Define configuration files from classes and its relations

It allows to load/export configuration from classes to json/yaml files easily It allows to have code completion on your configuration objects and not depend on dictionaries

Example

from numbers import Number
from confObj import ConfObj

class PgServerConf(ConfObj):
    ip: str = ""
    port: Number = 5432
    username:str = ""
    password:str = ""

class MainConf(ConfObj):
    pgconf: PgServerConf = PgServerConf()
    timezone:str = "UTC"


if __name__ == "__main__":
    conf = MainConf()
    print("Default configuration:")
    print(conf.as_json())
    conf.pgconf.username = "admin"
    print("Modified configuration for pg: ")
    print(conf.pgconf.as_json())

Usage

The idea behind this module is to create a configuration object that can be organized as a tree and IDE's code completion features can be used.

It should be used as:

  • Define the structure of the whole configuration defining classes that inherit from `confObj``
  • [optional] Assign default values to configuration items on code
  • Output the defined configuration tree as a file (either yaml or json)
    • [optional] Fix default values on the generated file
  • On runtime, either load configuration or use default hardcoded values.
    • [optional] On runtime, values can be changed and saved to file if necessary

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

pyconfobj-0.1.2.tar.gz (4.6 kB view hashes)

Uploaded Source

Built Distribution

pyconfobj-0.1.2-py3-none-any.whl (3.6 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