Dotmap is a Python library that provides a dot-access dictionary, allowing dictionary keys to be accessed as object attributes (e.g., `m.key` instead of `m['key']`). It supports dynamic hierarchy creation, ordered iteration, and can be initialized from or converted back to standard Python dictionaries. The current stable version is 1.3.30, and it maintains an active release cadence with regular updates.
pip install dotmapVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to initialize a DotMap, assign values using dot notation, dynamically create nested dictionaries and lists, and convert the DotMap instance back to a standard Python dictionary.
To check for key existence without creating a new DotMap, use `key in dotmap_instance` or `dotmap_instance.get('key_name', default_value)` methods, similar to a regular dictionary.Ensure you explicitly remove any unwanted keys after `toDict()` if they interfere with downstream processes. Always inspect the output of `toDict()` to confirm it matches expectations. For deeply nested structures, consider a custom deep-copy or serialization approach if `toDict()` causes issues.
Avoid using Python keywords or built-in dictionary method names as keys if you plan to access them via dot notation. If such keys are unavoidable, access them using standard dictionary bracket notation: `m['key_name']`.
If subclassing, be cautious with `super().__init__()` and nested dicts. You might need to manually convert nested dictionaries to `DotMap` instances within your subclass's `__init__` or rely on `DotMap`'s dynamic creation for subsequent assignments rather than initial bulk population.
pip install dotmap
Upgrade dotmap to the latest version using `pip install --upgrade dotmap`. If the data structure is truly recursive, you may need to manually manage the conversion or redesign the data to avoid infinite recursion.
Upgrade the dotmap library to a compatible version (1.3.9 or newer) using `pip install --upgrade dotmap`.
Ensure the key exists before accessing it (e.g., `if 'some_key' in m:`) or initialize the DotMap without `_dynamic=False` if you intend for non-existent keys to be dynamically created. If it's a debugger-related 'shape' error, it's often benign, or you can disable dynamic creation if unwanted: `m = DotMap(_dynamic=False)`.
No dependency data recorded yet.