Giter VIP home page Giter VIP logo

conflib's Introduction

conflib

Latest Version Build Status Coverage Status Code Quality MIT Licensed

Simplifies configuration stacking. Primarily, this was written to allow stacking of default, global, and local settings. It allows for validation so that you can enforce contraints on supplied options.

Usage

Using conflib is just a matter of importing it and giving it some dictionaries to stack:

>>> import conflib
>>> Default = {'hello': 'world', 'alpha': 5}
>>> Global = {'wat': 'wut', 'fancy': (20, 'fish')}
>>> Local = {'hello': 'everybody', 'beta': 'qwerty'}
>>> Config = conflib.Config(Default, Global, Local)
>>> print(Config.options)
{'alpha': 5, 'wat': 'wut', 'beta': 'qwerty', 'hello': 'everybody', 'fancy': (20, 'fish')}

If you need to stack on new configs later, go for it:

>>> Config.stack({'wat': 'new_value', 'extra': 10})
>>> print(Config.options)
{'alpha': 5, 'wat': 'new_value', 'beta': 'qwerty', 'hello': 'everybody', 'fancy': (20, 'fish'), 'extra': 10}

Pass in a validation dictionary if you want to check the provided arguments:

Validator = {
    'alpha': lambda x: x < 10,
    'fancy': tuple,
    'beta': [('asdf', 'qwerty'), ('fizz','buzz')]
}
Config.validate(Validator)

Alternately, you can pass in a validation_dict when creating a Config object. Validation failures raise ValueError with a message indicating the specific failure. There are several available options for the Validation dictionary:

  • bool: Converts 'y', 'yes', '1', 1, and True to True, and 'n', 'no', '0', 0 and False to False
  • int: Casts provided value as an integer
  • A list of tuples: looks for the provided value as a member of any of the tuples, and returns the first item in that tuple
  • A list: looks for the provided value in the list
  • Any type (str, float, etc): validates that the provided value is of the specified type (does not try to cast it)
  • A callable: Runs the provided function, which should either return the validated value or raise TypeError

Installation

pip install conflib

License

conflib is released under the MIT License. See the bundled LICENSE file for details.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.