Registry / serialization / easydict

easydict

JSON →
library1.13pypypi✓ verified 30d ago

EasyDict is a Python library that enables accessing dictionary values as attributes, providing a JavaScript-like dot notation for Python dictionaries. It works recursively for nested structures, making dictionary manipulation more convenient and readable. The current version is 1.13, and the library receives updates periodically, with several releases each year to address bugs and introduce minor enhancements.

pip install easydict
INSTALL
IMPORT
SIG · EASYDICT
E
easydict
serializationpythonv1.13
Install
1.5s avg
Import
—
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v1.13 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

EasyDict
✓ from easydict import EasyDict
✗ from easydict import EasyDict as edict # Not 'wrong', but 'EasyDict' is the primary class name; 'edict' is a common alias.
The class is named `EasyDict`. `edict` is a popular alias used in many examples for brevity.

Demonstrates creating an EasyDict from a Python dictionary, accessing nested values with dot notation, modifying attributes, and showing that it retains dictionary-like behavior.

from easydict import EasyDict # Create an EasyDict from a dictionary data = EasyDict({ 'settings': { 'debug': True, 'api_key': 'abc123xyz' }, 'users': [ {'id': 1, 'name': 'Alice'}, {'id': 2, 'name': 'Bob'} ] }) # Access values using dot notation print(f"Debug mode: {data.settings.debug}") print(f"API Key: {data.settings.api_key}") print(f"First user's name: {data.users[0].name}") # Set new attributes or modify existing ones data.settings.debug = False data.new_feature = {'enabled': True} print(f"New debug mode: {data.settings.debug}") print(f"New feature enabled: {data.new_feature.enabled}") # EasyDict still behaves like a dict print(f"All keys: {list(data.keys())}")
Debug
Known issues
gotchaEasyDict is primarily designed for string keys when using dot notation. Attempting to access non-string keys (e.g., integers) as attributes will result in an AttributeError. You must use standard dictionary bracket notation for non-string keys.
fix
Access non-string keys using `my_easydict[123]` instead of `my_easydict.123`.
affects: All versions
gotchaEasyDict recursively converts nested dictionaries and lists of dictionaries into EasyDict instances. This can sometimes lead to unexpected behavior if strict Python dict/list types are expected at certain levels, or if dealing with self-referencing dictionary structures, which can cause `RecursionError`.
fix
Be aware of the recursive conversion. If you need a plain dictionary, convert explicitly using `dict(my_easydict)` (note: this might not recursively convert nested EasyDicts back to plain dicts in older versions, requiring manual deep conversion). For `RecursionError` with class members, upgrade to >=1.11.
affects: <= 1.10 for `RecursionError` with class members (fixed in 1.11), but recursive conversion applies to all versions.
breakingIn versions prior to 1.12, tuples assigned as values within an EasyDict could be incorrectly converted to lists. This could alter data structures unintentionally.
fix
Upgrade to EasyDict version 1.12 or newer to ensure tuples are preserved as tuples.
affects: < 1.12
breakingThe `.pop()` and `.update()` methods had incorrect behavior in versions prior to 1.9, particularly when dealing with EasyDict instances.
fix
Upgrade to EasyDict version 1.9 or newer to ensure correct functionality of `.pop()` and `.update()`.
affects: < 1.9
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'easydict'
The easydict library is not installed in the Python environment where the code is being executed.
fix
pip install easydict
AttributeError: 'EasyDict' object has no attribute 'some_key'
You are attempting to access a non-existent key as an attribute on an EasyDict object.
fix
Ensure the key 'some_key' actually exists in your EasyDict object. You can check its existence using `'some_key' in your_easydict` or safely retrieve its value using `your_easydict.get('some_key', default_value)` to avoid the error.
AttributeError: 'EasyDict' object has no attribute 'iteritems'
This error occurs when running Python 2 code in a Python 3 environment. The `iteritems()` method for iterating over dictionary items was removed in Python 3 and replaced by `items()`.
fix
Replace `.iteritems()` with `.items()` in your code.
KeyError: 'some_key'
When treating an EasyDict instance like a regular dictionary, you attempted to access a key using bracket notation (`my_easydict['some_key']`) that does not exist within the dictionary.
fix
Verify that 'some_key' exists before accessing it, or use the `.get()` method to provide a default value if the key is not found, e.g., `my_easydict.get('some_key', None)`.
Upgrade
Version history
1.13latest on PyPI · released Mar 4, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
17 hits · last 30 days
node
16
Resources