easydict

Access dict values as attributes (works recursively)

Latest version: 1.13 registry icon
Maintenance score
0
Safety score
0
Popularity score
29
Check your open source dependency risks. Get immediate insight about security, stability and licensing risks.
Security
  Vulnerabilities
Version Suggest Low Medium High Critical
1.13 0 0 0 0 0
1.12 0 0 0 0 0
1.11 0 0 0 0 0
1.10 0 0 0 0 0
1.9 0 0 0 0 0
1.8 0 0 0 0 0
1.7 0 0 0 0 0
1.6 0 0 0 0 0
1.5 0 0 0 0 0
1.4 0 0 0 0 0
1.3 0 0 0 0 0
1.2 0 0 0 0 0
1.0 0 0 0 0 0

Stability
Latest release:

1.13 - This version may not be safe as it has not been updated for a long time. Find out if your coding project uses this component and get notified of any reported security vulnerabilities with Meterian-X Open Source Security Platform

Licensing

Maintain your licence declarations and avoid unwanted licences to protect your IP the way you intended.

LGPL-3.0-only   -   GNU Lesser General Public License v3.0 only

Not a wildcard

Not proprietary

OSI Compliant



.. image:: https://img.shields.io/pypi/v/easydict.svg :target: https://pypi.python.org/pypi/easydict

.. image:: https://img.shields.io/pypi/dm/easydict.svg :target: https://pypi.python.org/pypi/easydict

======== 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

AUTHORS

|makinacom|_

.. |makinacom| image:: http://depot.makina-corpus.org/public/logo.gif .. _makinacom: http://www.makina-corpus.com

Similar tools

  • TreeDict <http://pypi.python.org/pypi/treedict>_, a fast and full-featured dict-like tree container.
  • addict <https://github.com/mewwts/addict>_