{"id":1467,"library":"dpath","title":"dpath: Filesystem-like Pathing for Dictionaries","description":"dpath-python provides filesystem-like pathing and searching capabilities for nested dictionary and list structures. It allows you to get, set, delete, and search data within complex Python objects using a simple string path syntax. The current version is 2.2.0, and the library maintains an active release cadence with regular updates and bug fixes.","status":"active","version":"2.2.0","language":"en","source_language":"en","source_url":"https://github.com/dpath-maintainers/dpath-python","tags":["dictionary","path","json","data-manipulation","nested-data"],"install":[{"cmd":"pip install dpath","lang":"bash","label":"Install dpath"}],"dependencies":[],"imports":[{"note":"All primary functions are available directly under the 'dpath' module.","symbol":"dpath","correct":"import dpath"}],"quickstart":{"code":"import dpath\n\n# Sample data\ndata = {\n    \"user\": {\n        \"profile\": {\n            \"name\": \"Alice\",\n            \"age\": 30,\n            \"interests\": [\"coding\", \"photography\"]\n        },\n        \"settings\": {\n            \"theme\": \"dark\"\n        }\n    },\n    \"items\": [\n        {\"id\": 1, \"name\": \"itemA\"},\n        {\"id\": 2, \"name\": \"itemB\"}\n    ]\n}\n\nprint(\"Original data:\")\nprint(data)\nprint(\"-\" * 20)\n\n# Get a value\nname = dpath.get(data, '/user/profile/name')\nprint(f\"User name: {name}\")\n\n# Set a value (creates path if it doesn't exist)\ndpath.set(data, '/user/profile/age', 31)\nprint(f\"Updated age: {dpath.get(data, '/user/profile/age')}\")\ndpath.set(data, '/user/profile/city', 'New York')\nprint(f\"Added city: {dpath.get(data, '/user/profile/city')}\")\n\n# Get all values matching a pattern (returns a generator)\nprint(\"\\nAll item names:\")\nfor item_name in dpath.values(data, '/items/*/name'):\n    print(f\"- {item_name}\")\n\n# Merge data (default is to update/replace)\nnew_settings = {\"user\": {\"settings\": {\"notifications\": True}}}\ndpath.merge(data, new_settings)\nprint(\"\\nData after merge:\")\nprint(data)\n\n# Delete a path\ndpath.delete(data, '/user/settings/notifications')\nprint(\"\\nData after deleting notifications:\")\nprint(data)\n","lang":"python","description":"This example demonstrates how to use `dpath.get`, `dpath.set`, `dpath.values`, `dpath.merge`, and `dpath.delete` to manipulate a nested dictionary and list structure. It shows getting a value, setting/creating new paths, iterating through matching values with wildcards, merging dictionaries, and deleting paths."},"warnings":[{"fix":"Ensure your project runs on Python 3.7 or newer. This version also introduced type hinting.","message":"dpath dropped support for Python 2.x. Any projects relying on older Python versions will need to upgrade to Python 3.7+.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"If you intend to create lists, explicitly initialize them (e.g., `data['path'] = []`) before setting values with integer indices, or ensure your paths are unambiguous for list creation.","message":"Behavior for interpreting integer-like path segments when creating new paths was changed to resolve ambiguity. This may lead to dictionary keys being created (e.g., `{'0': ...}`) instead of list indices (e.g., `[..., ...]`) if the target path is not an existing list or explicitly initialized as one.","severity":"breaking","affected_versions":">=2.1.4"},{"fix":"To get a list, consume the generator: `list(dpath.values(data, '*/name'))` or iterate directly: `for val in dpath.values(data, '*/name'): ...`.","message":"`dpath.values()` and `dpath.search()` return generators, not immediate lists. If you expect a list, you must explicitly convert the generator.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Understand the `merge_types` parameter (e.g., `dpath.merge(data, src, merge_types=dpath.MERGE_ADDITIVE)`) to control how lists and dicts are combined, particularly to extend lists instead of replacing them.","message":"The `dpath.merge()` function's default behavior can replace entire lists or dictionaries. For more granular control over merging, especially for lists, the `merge_types` parameter should be used.","severity":"gotcha","affected_versions":"All versions (clarified with Enum in >=2.1.0)"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}