Skip to main content

Multi-format configuration assembler

Project description

https://badge.fury.io/py/figtree.svg https://travis-ci.org/skippyprime/configs.svg?branch=master https://coveralls.io/repos/github/skippyprime/configs/badge.svg?branch=master Requirements Status

Figtree is a multi-format configuration file loader that normalizes all values into dictionaries and supports merging multiple configuration files into a single source. The later can be useful if you have multiple configuration sources and either want to load the first found or override default settings (such as having a system wide and per user configuration file).

Figtree supports the following configuration file formats:

  • YAML

  • JSON

  • XML (Currently ignores attributes)

  • INI (Currently does not support dictionaries within lists)

The Figtree API is also easily extensible to support new structured file formats through automatic registration of format handlers.

Simple Example

Configuration source: /etc/myproject/settings.yml

section:
  debug: on
  complex:
    structure:
      value: 100
      multi:
        - 1
        - 2
        - 3
flag: off

Loading and access data.

import figtree

conf = figtree.load_config('@/etc/myproject/settings.yml')

# configuration instances are dictionary like
flag_set = conf['flag']

# nested structures are also dictionary like
is_debugging = conf['section']['debug']

# easier lookups to avoid intermediate key checks
is_debugging = conf['section.debug']
is_debugging = conf.get('section.debug', False)

# sub-dictionaries can be accessed the same way
conf_section = conf['section']
value = conf_section['complex.structure.value']

Loading Options

Configuration files can be loaded from the following sources:

  • Files (Local and HTTP accessible)

  • String Literals

  • Dictionary Objects

Merge Settings

Load in order and merge settings. The last item has overrides others.

import figtree

conf = figtree.load_config(
    (
        {
            'section': {
                'debug': True
            },
            'flag': False
        },
        '/etc/myproject/settings.yml',
        'https://mydomain.test/settings',
        figtree.LiteralConfigSource('flag: off', hint='yaml')
    )
)

First Found

Load the first found source. Mostly useful for file based sources.

import figtree

conf = figtree.load_first_found_config(
    (
        'settings.yml',
        '~/.settings.yml',
        '/etc/myproject/settings.yml'
    )
)

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

figtree-0.2.2.tar.gz (7.7 kB view details)

Uploaded Source

File details

Details for the file figtree-0.2.2.tar.gz.

File metadata

  • Download URL: figtree-0.2.2.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for figtree-0.2.2.tar.gz
Algorithm Hash digest
SHA256 df764785c4fae7cfe7fef3158be7d527ef951788c76d518b56b7739fa917a352
MD5 9249e837db4b401fb5ad3bd97151d7bb
BLAKE2b-256 05e2818e3d2cec249fb38f7c2d58bbc2373024a0f55c46568e630e1396c4cf1f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page