Powered by Tachyonic Project Luxon Framework v0.0.0

Luxon Framework for rapid application development. (luxon)

Version

Config

Luxon performs configuration by using a global settings file. The settings file can be used globaly and and localy on a per module basis.

Settings

Luxon will attempt to discover the route path when starting the handler e.g. Wsgi. You can place a settings.ini file in the same directory of your wsgi file which is loaded by Wsgi handler. The settings.ini file will be read by Luxon’s config parser.

settings.ini layout

# Main Application configuration
[application]

# Global Application name. Its seen in the logs output.
name = Application

# Log Level for Application root logger.
# Default is WARNING
log_level = WARNING

# Log to sys.stdout. for root logger.
log_stdout = True

# Log to syslog server for root logger.
# If not defined will not log to server.
log_server = 192.168.0.1

# Log Port for syslog server.
log_server_port = 514

# Log to file for root logger.
# If not defined will not log file.
log_file = /tmp/app.log

# Per Module configuration.
[package.module]

# Log level for specific module.
log_level = DEBUG

# Log Stdout for specific module.
log_stdout = False

# Log Server for specific module.
# If not defined will not log to server.
log_server = 192.168.0.1

# Log Port for syslog server.
log_server_port = 514

# Log to file for module.
# If not defined will not log file.
log_file = /tmp/package_module.log

Default settings.ini


defaults = {
    'DEFAULT': {
        'host': '127.0.0.1',
    },
    'application': {
        'name': 'Application',
        'static': '/static',
        'use_forwarded': 'false',
        'timezone': 'local',
        'default_theme': 'default',
        'log_stdout': 'True',
        'log_level': 'WARNING',
        'debug': 'False',
    },
    'restapi': {
        'url': 'http://127.0.0.1/infinitystone',
        'interface': 'public',
        'region': 'default',
        'connect_timeout': '2',
        'read_timeout': '8',
        'verify': 'True',
    },
    'tokens': {
        'expire': '3600',
    },
    'sessions': {
        'expire': '86400',
        'backend': 'luxon.core.session:Cookie',
        'session': 'luxon.core.session:TrackCookie',
    },
    'database': {
        'type': 'sqlite3',
    },
    'redis': {
        'db': '0',
    },
    'cache': {
        'backend': 'luxon.core.cache:Memory',

Configparser

The Python configparser implements a basic configuration language which provides a structure similar to what’s found in Microsoft Windows INI files. You can use this to write Python programs which can be customized by end users easily.

The configuration can be access globally from g.app.config which Luxon’s Python configparser that has been enhanced by adding more methods to the exisiting base Python configparser.

Config Class

class luxon.core.config.Config(config_file=None)[source]

Tachyonic Python ConfigParser extended.

You can find complete set of methods from Python ConfigParser documentation.

Alterations in behaviour:
  • Sections are case-insenstive too.
  • Addition can use attributes to get section, options without spaces.

However the methods within here only to provide extended functionality.

Parameters:config_file (str) – Optional config file or dict to load.
get(section, option, *, raw=False, vars=None, fallback=<object object>)[source]

Get an option value for a given section.

If vars is provided, it must be a dictionary. The option is looked up in vars (if provided), section, and in DEFAULTSECT in that order. If the key is not found and fallback is provided, it is used as a fallback value. None can be provided as a fallback value.

If interpolation is enabled and the optional argument raw is False, all interpolations are expanded in the return values.

The section DEFAULT is special.

getboolean(section, option, *, raw=False, vars=None, fallback=<object object>)[source]

Like get(), but convert value to a boolean (currently case insensitively defined as 0, false, no, off for False, and 1, true, yes, on for True). Returns False or True.

getfloat(section, option, *, raw=False, vars=None, fallback=<object object>)[source]

Like get(), but convert value to a float.

getint(section, option, *, raw=False, vars=None, fallback=<object object>)[source]

Like get(), but convert value to an integer.

getjson(section, option, fallback=None)[source]

Load JSON object from value.

Parameters:
  • section (str) – section name.
  • option (str) – option name.
Kwargs:
fallback: Dict or List.

Returns dict or list.

getlist(section, option, fallback=None)[source]

Get list from option value.

Example:

[Bar]
files_to_check =
    /path/to/file1,
    /path/to/file2,
    /path/to/another file with space in the name
Parameters:
  • section (str) – section name.
  • option (str) – option name.
Kwargs:
fallback (list): List of default values.

Returns list.

has_section(section)[source]

Return whether the given section exists.

items(section=None, *, raw=False, vars=None)[source]

If section is given, return a list of tuples with (name, value) for each option in the section. Otherwise, return a list of tuples with (section_name, section_proxy) for each section, including DEFAULTSECT.

kwargs(section)[source]

Get dict for kwargs for section.

Excludes all default values.

Convieniantly use with **kwargs from configuration as arguements.

Parameters:section (str) – section name.

Returns dict.

load(config_file, encoding=None)[source]

Load Configuration file.

Parameters:config_file (str) – Path / Location to configuration file.
options(section)[source]

Return list of configuration options for the named section.

read(filenames, encoding=None)[source]

Read and parse the list of named configuration files, given by name. A single filename is also allowed. Non-existing files are ignored. Return list of successfully read files.

read_dict(dictionary)[source]

Read configuration from a dictionary. Keys are section names, values are dictionaries with keys and values that should be present in the section. If the used dictionary type preserves order, sections and their keys will be added in order. Values are automatically converted to strings.

read_string(string)[source]

Read configuration from a given string.

remove_option(section, option)[source]

Remove the given option from the given section.

remove_section(section)[source]

Remove the given file section and all its options.

save(config_file)[source]

Save Configuration file.

Parameters:config_file (str) – Path / Location to configuration file.
sections()[source]

Return all the configuration section names, sans DEFAULT.

set(section, option, value)[source]

Set the given option.