Skip to main content
https://img.shields.io/pypi/v/easydict.svg https://img.shields.io/pypi/dm/easydict.svg

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

Similar tools

CHANGELOG

1.12 (2024-03-04)

  • Fix #46: Fix handling of optional default value for .pop() (#47)

1.12 (2024-02-13)

  • Fix #22: Do not convert tuple attributes to list (#44)

1.11 (2023-10-24)

  • Fix #39: RecursionError when dict in class member (#41)

  • Minor changes in README

1.10 (2022-09-28)

  • Make tests compatible with python2 and python3 (thanks @JackLangerman)

  • Dictify input

  • Fix license metadata

1.9 (2018-10-18)

  • Fix issue #3 that update and pop now work correctly on EasyDicts.

1.8 (2018-08-17)

  • Update package classifiers.

1.7 (2017-04-27)

  • Prevent copying sub-EasyDicts on assignment to fix unpickling (#7, thanks @Chronos-Sk)

1.6 (2015-01-27)

  • Allow setting attributes via setting items (thanks phivos)

1.5 (2014-08-07)

  • Allow subclassing using self instead of class name (thanks Steve Engledow)

1.4 (2011-03-13)

  • Access class attributes like instance attributes

1.3 (2012-02-08)

  • Better documentation and tests

1.2 (2011-06-08)

  • Fix inclusion of README

1.1 (2012-04-21)

  • Switch to distutils2

1.0 (2011-04-18)

  • Initial working version

Release files for easydict 1.13

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for easydict 1.13
File Size Uploaded
easydict-1.13.tar.gz 6.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for easydict 1.13
File Interpreter ABI Platform
easydict-1.13-py3-none-any.whl Python 3 none any Details

Total release size: 13.6 kB

Release files / easydict-1.13.tar.gz

Download URL easydict-1.13.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
b1135dedbc41c8010e2bc1f77ec9744c7faa42bce1a1c87416791449d6c87780
BLAKE2b-256 checksum
How to use checksums
249fd18d6b5e19244788a6d09c14a8406376b4f4bfcc008e6d17a4f4c15362e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.6

Release files / easydict-1.13-py3-none-any.whl

Download URL easydict-1.13-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6b787daf4dcaf6377b4ad9403a5cee5a86adbc0ca9a5bcf5410e9902002aeac2
BLAKE2b-256 checksum
How to use checksums
05ecfa6963f1198172c2b75c9ab6ecefb3045991f92f75f5eb41b6621b198123
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.6

Release history Release notifications | RSS feed

This release

1.13 This release

2 release files

1.12

2 release files

1.11

1 release file

1.10

1 release file

1.9

1 release file

1.8

1 release file

1.7

1 release file

1.6

1 release file

1.5

1 release file

1.4

1 release file

1.3

1 release file

1.2

1 release file

1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page