Skip to main content

Parser for configuration from multiple sources

Project description

multiconfparse

multiconfparse is a Python3 library for specifying and reading configuration data from multiple sources.

Installation

python -m pip install git+https://github.com/jonathanhaigh/multiconfparse

Quickstart

  1. Import the multiconfparse module:

    import multiconfparse.multiconfparse as mcp
    
  2. Create a ConfigParser object:

    import multiconfparse.multiconfparse as mcp
    
    config_parser = mcp.ConfigParser()
    

    ConfigParsers:

    • contain the specifications of your configuration items;
    • have sources - objects that can obtain configuration values from different sources;
    • coordinate the parsing done by sources;
    • merge configuration values from sources into a single set of values.
  3. Add specifications of your config items:

    # Add config items
    config_parser.add_config("config_item1", required=True)
    config_parser.add_config("config_item2", default="default_value")
    
  4. Add sources:

     config_parser.add_source(mcp.SimpleArgparseSource)
     config_parser.add_source(mcp.JsonSource, "/path/to/config/file.json")
    
  5. Parse config from all sources:

    config = config_parser.parse_config()
    

    ConfigParser.parse_config() returns a multiconfparse.Namespace object which is essentially just a plain object with attributes for each config item.

  6. Use the config

    item1 = config.config_item1
    item2 = config.config_item2
    

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

multiconfparse-0.0.1.tar.gz (8.9 kB view hashes)

Uploaded Source

Built Distribution

multiconfparse-0.0.1-py3-none-any.whl (9.1 kB view hashes)

Uploaded Python 3

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