Access dict values as attributes (works recursively).
Project Links
Meta
Author: Mathieu Leplatre
Classifiers
Topic
- Utilities
Natural Language
- English
Operating System
- OS Independent
Intended Audience
- Developers
Development Status
- 5 - Production/Stable
Programming Language
- Python :: 3
Easydict
EasyDict allows to access dict values as attributes (works recursively). A Javascript-like properties dot notation for python dicts.
INSTALL
pip install easydict
USAGE
>>> from easydict import EasyDict as edict
>>> d = edict({'foo':3, 'bar':{'x':1, 'y':2}})
>>> d.foo
3
>>> d.bar.x
1
>>> d = edict(foo=3)
>>> d.foo
3
Very useful when exploiting parsed JSON content !
>>> from easydict import EasyDict as edict
>>> from simplejson import loads
>>> j = """{
"Buffer": 12,
"List1": [
{"type" : "point", "coordinates" : [100.1,54.9] },
{"type" : "point", "coordinates" : [109.4,65.1] },
{"type" : "point", "coordinates" : [115.2,80.2] },
{"type" : "point", "coordinates" : [150.9,97.8] }
]
}"""
>>> d = edict(loads(j))
>>> d.Buffer
12
>>> d.List1[0].coordinates[1]
54.9
Can set attributes as easily as getting them :
>>> d = EasyDict() >>> d.foo = 3 >>> d.foo 3
It is still a dict !
>>> d = EasyDict(log=False)
>>> d.debug = True
>>> d.items()
[('debug', True), ('log', False)]
Instance and class attributes are accessed like usual objects…
>>> class Flower(EasyDict):
... power = 1
...
>>> f = Flower({'height': 12})
>>> f.power
1
>>> f['power']
1
LICENSE
Lesser GNU Public License
Similar tools
1.14
Nov 09, 2026
1.13
Mar 04, 2024
1.12
Feb 13, 2024
1.11
Oct 23, 2023
1.10
Sep 28, 2022
1.9
Oct 18, 2018
1.8
Aug 17, 2018
1.7
Apr 27, 2017
1.6
Jan 27, 2015
1.5
Aug 07, 2014
1.4
Mar 13, 2012
1.3
Dec 09, 2011
1.2
Jun 08, 2011
1.0
Apr 18, 2011
Wheel compatibility matrix
Files in release
No dependencies
