{"id":2939,"library":"dotty-dict","title":"Dotty Dict","description":"Dotty Dict is a Python library that provides a dictionary-like object for quick access to deeply nested keys using dot notation. It wraps standard Python dictionaries and supports various dictionary operations including creation, reading, updating, and deleting nested keys. The current stable version is 1.3.1, released in July 2022, suggesting a moderate release cadence.","status":"active","version":"1.3.1","language":"en","source_language":"en","source_url":"https://github.com/pawelzny/dotty_dict","tags":["dictionary","nested","dot notation","utility","data access"],"install":[{"cmd":"pip install dotty-dict","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"Recommended factory function for creating Dotty instances.","symbol":"dotty","correct":"from dotty_dict import dotty"},{"note":"The class constructor, used for custom separators or escape characters.","symbol":"Dotty","correct":"from dotty_dict import Dotty"}],"quickstart":{"code":"from dotty_dict import dotty\n\n# Create a new dotty dict\ndata = dotty()\ndata['user.address.street'] = 'Main St'\ndata['user.address.city'] = 'Anytown'\ndata['items.0.name'] = 'Laptop'\ndata['items.0.price'] = 1200\n\nprint(f\"Street: {data['user.address.street']}\")\nprint(f\"First item name: {data['items.0.name']}\")\n\n# Wrap an existing dictionary\nexisting_dict = {'product': {'details': {'id': 'P101', 'stock': 50}}}\ndot_wrapper = dotty(existing_dict)\nprint(f\"Product ID: {dot_wrapper['product.details.id']}\")\n\ndot_wrapper['product.details.stock'] = 45\nprint(f\"Updated existing dict: {existing_dict}\") # The underlying dict is modified","lang":"python","description":"Demonstrates creating a new Dotty instance, setting deeply nested values, accessing them, and wrapping an existing dictionary to modify its contents using dot notation and list indexing."},"warnings":[{"fix":"Ensure your dictionary keys are strings if they should not be interpreted as list indices, or structure your data accordingly. There is no direct mechanism to force an integer in a dot-separated string path to be a dictionary key if it's numerically parsed.","message":"Integer keys in string paths are automatically treated as list indices. For example, `dot['items.0.name']` accesses the 'name' key of the first item in the 'items' list. If you intend to use an integer as a dictionary key, it will be interpreted as a list index.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Initialize `Dotty` with a custom separator (e.g., `Dotty(separator='_')`) or use the escape character (backslash `\\`) to explicitly include a dot in a key (e.g., `dot['my\\.key.with\\.dots']`).","message":"Dictionary keys cannot contain dots (`.`) by default. If a key genuinely contains a dot, it will be interpreted as a path separator, leading to unexpected nested dictionary structures.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always use `['dot.separated.path']` syntax for accessing values, even for deeply nested structures.","message":"Dotty Dict does not support attribute-style access (e.g., `data.user.address.street`). All access to nested keys must be done using dictionary-style item access with string paths (e.g., `data['user.address.street']`).","severity":"gotcha","affected_versions":"All versions"},{"fix":"Avoid using boolean values within dot-notation string paths. If you need to store boolean data, consider using string representations (e.g., 'true', 'false') if they are part of a dot-separated path.","message":"Boolean type keys are only partially supported. Accessing boolean keys directly (e.g., `dot[True]`) works, but using them within a dot-notation string path might lead to unexpected behavior or errors.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure consistent key typing within your nested dictionaries, especially avoiding ambiguous cases where different types could represent the same value.","message":"In very rare edge cases, when a nested dictionary contains two keys of different types but with the same value (e.g., an integer key and a string key both representing '1'), `dotty-dict` might return a dict or list under a 'random' key with the passed value, leading to inconsistent behavior.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}