munch

Convert Python dicts to dot-notation objects for cleaner code access.

pipmacoslinuxwindows
Try with needOr install directly
Source

About

A dot-accessible dictionary (a la JavaScript objects)

Examples

access dictionary values using dot notation instead of brackets$ python3 -c "from munch import munchify; d = munchify({'name': 'John', 'age': 30}); print(d.name)"
convert nested dictionary to dot-accessible object$ python3 -c "from munch import munchify; config = munchify({'db': {'host': 'localhost', 'port': 5432}}); print(config.db.host)"
convert object back to regular dictionary$ python3 -c "from munch import munchify, unmunchify; obj = munchify({'a': 1}); d = unmunchify(obj); print(type(d))"
work with JSON data using dot notation$ python3 -c "import json; from munch import munchify; data = munchify(json.loads('{\"user\":{\"email\":\"test@example.com\"}}')); print(data.user.email)"
create object with default values using Munch class$ python3 -c "from munch import Munch; m = Munch(name='Alice', role='admin'); m.status = 'active'; print(m.toDict())"