Git Product home page Git Product logo

meh's Introduction

Meh

Meh Banner

Python version support: 2.7, 3.4, 3.5 License: MIT

Meh is a Python configuration utility that uses Python as it's data format. It provides a pleasant and very "pythonic" interface to do all the things a configuration utility does, like default values, validators and comments.

Usage

from meh import Config, Option, ExceptionInConfigError

config = Config()
config.add(Option("food", ["Steak", "Pizza", "Burgers"],
	validator=lambda x: type(x) is list))
config.add(Option("ages", {"@snoato" : 18, "@PhilipTrauner" : 16},
	validator=lambda x: type(x) is dict))
config.add(Option("bytestring", b"test"))
config += Option("another_number", 42.0, comment="hihi")
config -= Option("another_number", 42.0, comment="hihi")
config += Option("another_number", 42.0, comment="hihi")

CONFIG_PATH = "awesome_config.cfg"

try:
	config = config.load(CONFIG_PATH)
except (IOError, ExceptionInConfigError):
	config.dump(CONFIG_PATH)
	config = config.load(CONFIG_PATH)

print(config.food)
print(config.ages)
print(config.bytestring)
print(config.another_number)

# Changing values during runtime
config.food = ["Baked Beans", "Ramen"]
print(config.food)

Outputs:

['Steak', 'Pizza', 'Burgers']
{'@PhilipTrauner': 16, '@snoato': 18}
test
42.0
['Baked Beans', 'Ramen']

Creates:

food = ['Baked Beans', 'Ramen']
ages = {'@PhilipTrauner': 16, '@snoato': 18}
bytestring = "test"
another_number = 42.0 # hihi

Tidbits

Config(options=[], validation_failed=None)

  • options: Provide a list of options instead of calling add for all of them.
  • validation_failed: Provide a function accepting two parameters (name and value) that's called when a validation fails (returns nothing). (Otherwise a ValidationError will be raised)

Option(name, default_value, validator=None, comment="")

  • validator: Provide a function accepting one parameter which checks if a value is correct (returns a boolean).
  • comment: A comment appended to the variable declaration in the config file itself.

Installation

Manual:

git clone https://github.com/PhilipTrauner/Meh
cd Meh
python setup.py install

pip:

pip install meh

Honorable Mentions

To-Do

  • More test cases

meh's People

Contributors

philiptrauner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

python3pkg

meh's Issues

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.