
Security News
Deno 2.6 + Socket: Supply Chain Defense In Your CLI
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.
nestedutils
Advanced tools
The lightweight Python library for safe, simple, dot-notation access to nested dicts and lists. Effortlessly get, set, and delete values deep in your complex JSON, API responses, and config files without verbose error-checking or handling KeyError exceptions.
The lightweight Python library for safe, simple, dot-notation access to nested dicts and lists. Effortlessly get, set, and delete values deep in your complex JSON, API responses, and config files without verbose error-checking or handling KeyError exceptions.

Working with deeply nested data (like JSON API responses) often leads to verbose, error-prone boilerplate:
# The Standard Way: Verbose and hard to read
user_name = None
if data and "users" in data and len(data["users"]) > 0:
user = data["users"][0]
if "profile" in user:
user_name = user["profile"].get("name")
# With nestedutils: Clean, safe, and readable
from nestedutils import get_path
user_name = get_path(data, "users.0.profile.name")
"a.b.c") or lists (["a", "b", "c"]) to navigate nested structuresget_path and set_path.pip install nestedutils
from nestedutils import get_path, set_path, del_path
# Create a nested structure
data = {}
# Set values using dot-notation
set_path(data, "user.name", "John")
set_path(data, "user.age", 30)
set_path(data, "user.hobbies.0", "reading")
set_path(data, "user.hobbies.1", "coding")
# Access values
name = get_path(data, "user.name") # "John"
age = get_path(data, "user.age") # 30
first_hobby = get_path(data, "user.hobbies.0") # "reading"
# Delete values
del_path(data, "user.age")
get_path(data, path, default=None)Retrieve a value from a nested data structure.
Parameters:
data: The data structure to navigate (dict, list, tuple, or nested combinations)path: Path to the value (string with dot notation or list of keys/indices)default: Value to return if path doesn't exist (default: None)Returns: The value at the path, or default if not found
Examples:
data = {"a": {"b": {"c": 5}}}
get_path(data, "a.b.c") # 5
get_path(data, "a.b.d", default=99) # 99
data = {"items": [{"name": "apple"}, {"name": "banana"}]}
get_path(data, "items.1.name") # "banana"
get_path(data, "items.-1.name") # "banana" (negative index)
set_path(data, path, value, fill_strategy="auto")Set a value in a nested data structure, creating intermediate containers as needed.
Parameters:
data: The data structure to modify (must be mutable: dict or list)path: Path where to set the value (string with dot notation or list of keys/indices)value: The value to setfill_strategy: How to fill missing containers (default: "auto")
"auto": Intelligently creates {} for dicts, [] for lists"none": Fills missing list items with None"dict": Always creates dictionaries"list": Always creates listsExamples:
data = {}
set_path(data, "user.profile.name", "Alice")
# Creates: {"user": {"profile": {"name": "Alice"}}}
data = {}
set_path(data, "items.0.name", "Item 1")
# Creates: {"items": [{"name": "Item 1"}]}
data = {}
set_path(data, "items.5", "Item 6", fill_strategy="none")
# Creates: {"items": [None, None, None, None, None, "Item 6"]}
del_path(data, path, allow_list_mutation=False)Delete a value from a nested data structure.
Parameters:
data: The data structure to modifypath: Path to the value to deleteallow_list_mutation: If True, allows deletion from lists (default: False)Returns: The deleted value
Raises: PathError if the path doesn't exist or deletion is not allowed
Examples:
data = {"a": {"b": 1, "c": 2}}
del_path(data, "a.b") # Returns 1, data becomes {"a": {"c": 2}}
data = {"items": [1, 2, 3]}
del_path(data, "items.1", allow_list_mutation=True) # Returns 2
# data becomes {"items": [1, 3]}
The library uses PathError exceptions with error codes for different failure scenarios:
from nestedutils import PathError, PathErrorCode
try:
set_path(data, "invalid.path", 1)
except PathError as e:
print(e.message) # Error message
print(e.code) # Error code (PathErrorCode enum)
Error Codes:
INVALID_PATH: Invalid path format or typeINVALID_INDEX: Invalid list indexMISSING_KEY: Key doesn't exist in dictionaryEMPTY_PATH: Path is emptyIMMUTABLE_CONTAINER: Attempted to modify a tupleINVALID_FILL_STRATEGY: Invalid fill strategy valueList paths are useful when keys contain dots:
data = {}
set_path(data, ["user.name", "first"], "John")
set_path(data, ["user.name", "last"], "Doe")
# Creates: {"user.name": {"first": "John", "last": "Doe"}}
Negative indices work like Python list indexing:
data = {"items": [10, 20, 30]}
get_path(data, "items.-1") # 30 (last item)
set_path(data, "items.-1", 999) # Updates last item
Tuples are read-only. You can read from them but cannot modify:
data = {"items": (1, 2, 3)}
get_path(data, "items.0") # 1 (works)
set_path(data, "items.0", 9) # Raises PathError (tuples are immutable)
The library can navigate through None values when setting:
data = {"a": None}
set_path(data, "a.b.c", 10)
# Replaces None with container: {"a": {"b": {"c": 10}}}
For development setup, building, and contributing, see DEVELOPMENT.md.
See CHANGELOG.md for a detailed list of changes and version history.
MIT License - see LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
If you find this library useful, please consider:
Become a Sponsor on GitHub | Support on Patreon
Y. Siva Sai Krishna
FAQs
The lightweight Python library for safe, simple, dot-notation access to nested dicts and lists. Effortlessly get, set, and delete values deep in your complex JSON, API responses, and config files without verbose error-checking or handling KeyError exceptions.
We found that nestedutils demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.

Security News
New DoS and source code exposure bugs in React Server Components and Next.js: whatâs affected and how to update safely.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.