S
smisk

config

JSON-compliant YAML-based configuration file loading with support for includes, symbol substitution, and live reloading.

Configuration file syntax

The configuration syntax is JSON-compliant YAML. Top-level keys map to smisk.config.config attributes:

smisk:
  autoreload: True
  mvc:
    template_dir: templates/

myapp:
  db_url: "sqlite:///myapp.db"

Includes

Use @include to split configuration across files:

@include: base.yaml

Paths can be expanded using glob, so you can include multiple files with a glob pattern:

@include: conf.d/*.yaml

@inherit

Use @inherit to extend configuration from another file, merging keys recursively.

Logging

Logging (the standard library logging module) is configured automatically. Supported handlers: StreamHandler, FileHandler, SysLogHandler. You can also configure a custom Formatter.

logging:
  root:
    level: DEBUG
    handlers: [stderr]
  handlers:
    stderr:
      class: StreamHandler
      stream: ext://sys.stderr

Symbols

Use ${SYMBOL} in string values to substitute predefined or custom symbols.

Predefined symbols

SymbolDescription
${APPDIR}Absolute path to the application directory
${HOSTNAME}Current machine hostname

Practical use

from smisk.config import config
config.load("myapp.yaml")
print(config.myapp.db_url)

Attributes

smisk.config.config

The global Configuration instance.

smisk.config.config_locations

List of directories searched for configuration files. Defaults include the application directory and /etc.

smisk.config.LOGGING_FORMAT

Default log format string.

smisk.config.LOGGING_DATEFMT

Default log date format string.

Functions

smisk.config.configure_logging()

Apply the logging section of the current configuration using Python's logging subsystem.

Classes

class smisk.config.Configuration

A lazy-loading configuration object. Attributes are created dynamically from YAML keys.

defaults

A dict of default values applied before loading from files.

default_symbols

Predefined symbol substitutions.

sources

List of loaded source file paths.

filters

List of filter callables applied after loading.

filename_ext

Recognised configuration file extensions. Defaults to [".yaml", ".json"].

logging_key

The key in config used for logging setup. Defaults to "logging".

input_encoding

Character encoding of configuration files. Defaults to "utf-8".

max_include_depth

Maximum nesting depth for @include directives. Defaults to 8.

__init__()

Initialise an empty configuration object.

__call__()

Shorthand for loading the default configuration file.

set_default(key, value)

Set a default value for key that is used if the key is not found in any loaded file.

load(filename)

Load and apply a configuration file.

loads(string)

Load configuration from a string.

reload()

Reload all configuration sources from disk.

reset()

Reset to a blank state, clearing all loaded values.

add_filter(fn)

Register a filter callable to be called after each load.