Skip to main content

Generic YAML/JSON configuration reader/writer

Project description

saiti - Generic YAML/JSON configuration handler

The saiti package convert a YAML or JSON config file into classes. To be used with our application. It performs validation on parameters and checks existence of parameters. The validation is to prevent typos in the configuration.

It currently supports to follwoing external packages;

  • Flask
  • Flask-JWT
  • Flask-JWT-Extended
  • Flask-SQLAlchemy
  • Flask-apscheduler

Concept

The concept is simple and straightforward to use start with a class that inherits the ConfigFile class and implement properies that are accessable at root file level. For primitive variable (str, int, bool and float) implement both propery getter and setter.

    class MyConfigurationFileObject( ConfigYamlFile ):
        def __init__( self, **kwargs )
            self.__property_name    = default value or None
            ... 
            ConfigFile.__init__( self, **kwargs )
            return

        @property
        def property_name( self ):
            return self.__property_name

        @property_name.setter
        def property_name( self, value )
            self.__property_name = value
            return

For complex properies only a getter needs to be implemented.

class MyConfigurationObject( ConfigProcessor ):
    def __init__( self, **kwargs )
        self.__list_property_name           = []
        self.__object_property_name         = DerivedConfigProcessor
        self.__list_objects_property_name   = DerivedConfigProcessorList
        ... 

    @property
    def list_property_name( self ):
        return self.__list_property_name

    @property
    def object_property_name( self ):
        return self.__object_property_name

    @property
    def list_object_property_name( self ):
        return self.__list_object_property_name

The internal variable maybe a simple list with primitive variables, or an object derived from the ConfigProcessor or ConfigListProcessor in case of the list of complex objects.

An object deriving from the ConfigProcess class looks like the following

from saiti import ConfigProcessor

class MyConfigurationObject( ConfigProcessor ):
    def __init__( self, **kwargs ):
        self.__property_name    = default value or None
        ConfigProcessor.__init__( self, '<name>', **kwargs )
        ... 

    @property
    def property_name( self ):
        return self.__property_name

    @property_name.setter
    def property_name( self, value )
        self.__property_name = value
        return

An list of complex object needs an implemetation as above as the object in the list. And an implementation of the ConfigListProcessor class like below.

from saiti import ConfigListProcessor   

class MyListConfigurationObject( ConfigListProcessor ):
    def __init__( self, **kwargs ):
        ConfigListProcessor.__init__( self, **kwargs )
        return

    def newObject( self, name, obj ):
        return MyConfigurationObject( name )

There are a number of configuration classes in the library available;

  • LoggingConfig; implementing the standard python logging.
  • DatabaseConfig: implementing standard configuration items for access to a database with the following properies:
  • engine
  • database
  • username
  • password
  • hostname
  • hostport
  • FlaskConfig:

There also a number of mixins they can be found in the mixins subpackage;

  • HostPortConfigMixin; with the following properties:
  • hostname
  • host same ase hostname
  • hostport
  • port same ase hostport
  • UserPassConfigMixin; with the following properties:
  • username
  • password

Special cases

Whenever a configuration contains keys for configuration objects that are variable, therefore not predefined.

In the derived ConfigProcessor class the variable 'wildcardObject' must be set to a class derived from ConfigProcessor.

Examples

See the example folder

Project details


Download files

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

Files for saiti, version 0.32.11rc1
Filename, size File type Python version Upload date Hashes
Filename, size saiti-0.32.11rc1-py3-none-any.whl (36.2 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size saiti-0.32.11rc1.tar.gz (32.0 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page