Object class and decorator for dynamic class props from dict, JSON or command-line input


Keywords
mutable, class, dynamic, json, python
License
MIT
Install
pip install mutable==0.1.3

Documentation

Mutable

pip install mutable

This library provides a powerful class abstraction for Python that allows dynamic rewriting of class properties based on dictionary, JSON or even command-line input. You can easily decorate your own class to convert it to mutable, allowing you to very flexibly control its properties.

How to?

You can install this library via pip:

pip install mutable

What is it actually?

Looking for examples? Here.

Mutable allows you to decorate your class converting its properties automatically into dynamic mutables. Look at this example:

from mutable import mutable

@mutable
class MyClass:
  def __init__(self, a=1, b="foo"):
    self.a = a
    self.b = b

You can now pass dictionary input as dynamic props

obj = MyClass({"b": "bar", "c": "baz"})

And then access them how you like

obj.a           # 1
obj.b           # bar
obj["c"]        # baz

You can assign a new value to a prop based on dict input:

obj.a = {"b": {"c": 1}}

They will be automatically converted into mutables:

obj.a.b.c       # 1
obj["a.b.c"]    # 1

View the full documentation.

Examples?

Full documentation and examples available here.

Develop?

To run all unit tests use:

python -m unittest discover -s test -p test_*

To deploy new version of the package use:

# Tag new version
git tag 0.2.0 -m "Version 0.2.0"
# the above will generate https://github.com/{username}/{package}/archive/{tag}.tar.gz
# automatically after git push

# Push tags
git push --tags origin master

# Deploy to pypi test
python setup.py sdist upload -r pypitest

# Deploy to pypi live
python setup.py sdist upload -r pypi

You need to have .pypirc configured for this to work.