Skip to main content

Easy composition of configuration files

Project description

Layer-Loader

CircleCI

Layer-loader is a Python library designed to allow easy composition of configuration files.

This project was inspired by hiera, though intends to be somewhat simpler.

Usage

The primary interface is a Python API:

import json
import layer_loader

data = layer_loader.load_files(
    ['dev.json', 'main.json'],
    loader=json.load,
)

This will load the data from dev.json and main.json, interpreting it as JSON, combine it into a single object and then any placeholders are expanded.

For convenience you can also run layer_loader as a module:

$ cat dev.json
{
    "url": "http://localhost:8000"
}
$ cat main.json
{
    "endpoints": [
        "{url}/abc",
        "{url}/def",
        "{url}/ghi"
    ],
    "url": "https://production.system"
}
$ python -m layer_loader --loader=json.load dev.json main.json
{
    "endpoints": [
        "http://localhost:8000/abc",
        "http://localhost:8000/def",
        "http://localhost:8000/ghi"
    ],
    "url": "http://localhost:8000"
}

Layers

Layers are specified in order from most important (top) to least important (bottom). When combining layers, layer-loader uses the following rules:

  • Mappings can be merged, combining the entries from several layers
  • Scalar values and lists replace entries in the lower layers
  • Keys in more important layers override those in lower layers
  • Where keys are present in multiple layers, it is an error for those keys to have values of different types. The exception to this is that keys can explicitly be set to null in a higher layer in order to remove a value set in a lower layer.

Placeholders

Placeholders are specified similarly to python format strings and may appear anywhere inside a string value, for example 'foo {place.holder} bar'. Placeholders should not appear in keys -- they will not be found there.

Placeholders are expanded by walking the flattened data structure, using dots in the placeholder to separate names at each level of nesting.

There is no mechanism to specify which layer a placeholder should be looked up within -- all placeholder expansion happens after the layers have been flattened.

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

layer-loader-0.0.1.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

layer_loader-0.0.1-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file layer-loader-0.0.1.tar.gz.

File metadata

  • Download URL: layer-loader-0.0.1.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.5.2

File hashes

Hashes for layer-loader-0.0.1.tar.gz
Algorithm Hash digest
SHA256 064fa86c5ecf2d2e1f9bc635225e58e9c2f6a8f916491b501ff5430ab441b5d6
MD5 4c66025222e56756aa104548580c1462
BLAKE2b-256 06e7ce9f3976be13a98e5d05954ccec4ecf56a27a76c837c858d078858275eff

See more details on using hashes here.

File details

Details for the file layer_loader-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: layer_loader-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.5.2

File hashes

Hashes for layer_loader-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 db85853256904db07f055ce44cc55b4ad75c76a51efc30f5af97661966ee9c0e
MD5 c131c98f43155c31b118e5e2fc80c324
BLAKE2b-256 4bdba29830f4de76d1125cd6e5eff02bbfae78fe2b487383437ed0001a6b4f38

See more details on using hashes here.

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