Skip to main content

Multi-profile supported, flexible config library

Project description

Logo

octoconf

Python Package Build Status Server Dependency Status Code Quality Server Test Coverage License

Multi-profile supported, flexible config library for Python 2 & 3.

Features

  • Allow multiple config profiles in one YAML file

  • Overridable profile selection from code for special use-cases (e.g. config for testing)

  • Inheritable config profiles, what makes profile merges by dictionaries. (the native YAML bookmarking is also available)

  • Can use variables in the config file

Installation

pip install octoconf

Config format

An octoconf YAML file have two restricted keywords:

  • USED_CONFIG>: <node_name> in the file root

    you can specify the name of default config profile

  • <BASE: <node_name> in the 2nd level

    this will used for making (merge based) inheritance between profiles

The profile nodes should be on 1st level!

Usage

There is an example YAML for demonstration

USED_CONFIG>: Fruits

Fruits:
  RED: 1
  YELLOW: $VAR1/2

SmallFruits:
  <BASE: Fruits
  RED: 3

ExtraSmallFruits:
  <BASE: SmallFruits
  RED: 4

Basic case

Read a multiple config contained YAML, and get profile which was selected by default.

  • Example YAML:
    USED_CONFIG>: Fruits
    
    Fruits:
      Small:
        RED: 1
        YELLOW: 2
    
    Vegetables:
      Big:
        RED: 3
        YELLOW: 4
  • Reader code:
    import octoconf
    
    yaml = octoconf.read('/test/foo.yaml')
    print(yaml)
  • Results:
    {
        'Small': {
            'RED': 1,
            'YELLOW': 2
        }
    }

Variables

Read a YAML file which contains variables.

  • Example YAML:
    USED_CONFIG>: Fruits
    
    Fruits:
      Small:
        RED: 1
        YELLOW: XXX${VAR1}XXX
    
    Vegetables:
      GREEN: 2
  • Reader code:
    import octoconf
    
    yaml = octoconf.read('/test/foo.yaml', variables={'VAR1': '/test1'})
    print(yaml)
  • Results:
    {
        'Small': {
            'RED': 1,
            'YELLOW': 'XXX/test1XXX'
        }
    }

Inheritance

Read a multiple config contained YAML, where the selected config is inherited from another config.

ExtraSmallFruits >> SmallFruits >> Fruits

  • Example YAML:
    USED_CONFIG>: ExtraSmallFruits
    
    Fruits:
      Small:
        RED: 1
        YELLOW: 2
        GREEN: 3
    
    SmallFruits:
      <BASE: Fruits
      Small:
        RED: 4
        YELLOW: 5
    
    ExtraSmallFruits:
      <BASE: SmallFruits
      Small:
        RED: 6
  • Reader code:
    import octoconf
    
    yaml = octoconf.read('/test/foo.yaml')
    print(yaml)
  • Results:
    {
        'Small': {
            'RED': 6,
            'YELLOW': 5
            'GREEN': 3,
        }
    }

More example

Please check the examples directory.

Bugs

Bugs or suggestions? Visit the issue tracker.

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

octoconf-0.1.0.tar.gz (17.1 kB view hashes)

Uploaded source

Built Distributions

octoconf-0.1.0-py3-none-any.whl (6.8 kB view hashes)

Uploaded 3 4

octoconf-0.1.0-py2-none-any.whl (6.8 kB view hashes)

Uploaded 2 7

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page