{"id":2938,"library":"dotmap","title":"Dotmap","description":"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.","status":"active","version":"1.3.30","language":"en","source_language":"en","source_url":"https://github.com/drgrib/dotmap","tags":["dictionary","dot-access","configuration","ordered","dynamic"],"install":[{"cmd":"pip install dotmap","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"DotMap","correct":"from dotmap import DotMap"}],"quickstart":{"code":"from dotmap import DotMap\n\n# Initialize an empty DotMap\nm = DotMap()\n\n# Assign values using dot notation\nm.name = 'Joe'\n\n# Dynamically create nested structures\nm.people.john.age = 32\nm.people.john.job = 'coder'\n\n# Append to lists (dynamically created)\nm.list.append(1)\nm.list.append(2)\nm.list.append(3)\n\n# Access values\nprint(f\"Name: {m.name}\")\nprint(f\"John's Age: {m.people.john.age}\")\nprint(f\"List: {m.list}\")\n\n# Convert back to a standard dictionary\nregular_dict = m.toDict()\nprint(f\"Converted to dict: {regular_dict}\")","lang":"python","description":"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."},"warnings":[{"fix":"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.","message":"Accessing a non-existent key in a DotMap (e.g., `m.non_existent_key`) will dynamically create an empty DotMap for that key, rather than raising a KeyError or returning None. This is a core feature for dynamic expansion but can be unexpected if you intend to check for key existence without modification.","severity":"gotcha","affected_versions":"All versions"},{"fix":"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.","message":"When converting a DotMap initialized from a nested dictionary back to a regular dictionary using `toDict()`, some internal DotMap instances might persist as values, or unexpected 'size'/'shape' keys might be added if they were implicitly created or managed by DotMap's internal mechanisms, leading to inconsistencies.","severity":"gotcha","affected_versions":"Versions prior to 1.3.x (and potentially some newer versions based on GitHub issues)"},{"fix":"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']`.","message":"Dictionary keys that conflict with Python's reserved keywords or built-in object attributes (e.g., 'items', 'keys', 'values', 'clear', 'copy', or leading with special characters) can lead to unexpected behavior or errors when accessed via dot notation. For instance, `m.items` would access the DotMap's `items()` method, not a key named 'items'.","severity":"gotcha","affected_versions":"All versions"},{"fix":"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.","message":"When subclassing `DotMap`, initializing `super().__init__(...)` with nested dictionaries might not always behave as expected, sometimes failing to properly convert nested dictionaries into DotMap instances within the subclass.","severity":"gotcha","affected_versions":"All versions, specifically noted in issue #77"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}