=============== LIBRARY RULES =============== From library maintainers: - Import from nestedutils: get_at, set_at, delete_at, exists_at, get_depth, count_leaves, get_all_paths, PathError. - In v2, get_at raises PathError for a missing path unless you pass default=...; see migration-v1-to-v2.md when upgrading from 1.x. - set_at needs create=True to build missing containers, and it never creates sparse lists (an index may be at most len(list)). - delete_at refuses to delete list items unless allow_list_mutation=True. ### Quick Start: Using nestedutils functions Source: https://github.com/ysskrishna/nestedutils/blob/main/README.md Demonstrates the main functions: set_at, get_at, exists_at, and delete_at on a nested structure. ```python from nestedutils import get_at, set_at, delete_at, exists_at, get_depth, count_leaves, get_all_paths # Create a nested structure data = {} # Set values using dot-notation set_at(data, "user.name", "John", create=True) set_at(data, "user.age", 30, create=True) set_at(data, "user.hobbies.0", "reading", create=True) set_at(data, "user.hobbies.1", "coding", create=True) # Access values name = get_at(data, "user.name") # "John" age = get_at(data, "user.age") # 30 first_hobby = get_at(data, "user.hobbies.0") # "reading" # Check if path exists if exists_at(data, "user.name"): print("User name exists!") # Delete values delete_at(data, "user.age") ``` -------------------------------- ### exists_at examples Source: https://github.com/ysskrishna/nestedutils/blob/main/README.md Shows exists_at returning True or False for existing and missing paths, including negative index support. ```python from nestedutils import exists_at data = {"a": {"b": {"c": 5}}} exists_at(data, "a.b.c") # True exists_at(data, "a.b.d") # False data = {"items": [{"name": "apple"}, {"name": "banana"}]} exists_at(data, "items.1.name") # True exists_at(data, "items.5.name") # False exists_at(data, "items.-1.name") # True (negative index) ``` -------------------------------- ### Install nestedutils with pip Source: https://github.com/ysskrishna/nestedutils/blob/main/README.md Install the nestedutils package using pip. ```bash pip install nestedutils ``` -------------------------------- ### set_at examples: create=True and list behavior Source: https://github.com/ysskrishna/nestedutils/blob/main/README.md Illustrates set_at with create=True for auto-creating containers, sequential list appending, and the restriction on sparse lists and negative indices. ```python from nestedutils import set_at, PathError # create=True - auto-create missing containers data = {} set_at(data, "user.profile.name", "Alice", create=True) # Creates: {"user": {"profile": {"name": "Alice"}}} data = {} set_at(data, "items.0.name", "Item 1", create=True) # Creates: {"items": [{"name": "Item 1"}]} # Sequential list appending (no gaps allowed) data = {} set_at(data, "items.0", "first", create=True) # Creates list with first item set_at(data, "items.1", "second", create=True) # Appends second item # Creates: {"items": ["first", "second"]} # Sparse lists are NOT allowed - this raises PathError data = [1, 2, 3] set_at(data, "5", 99, create=True) # Raises PathError: cannot create gap # Negative indices - modify existing only data = [1, 2, 3] set_at(data, "-1", 100) # Updates existing last element # Creates: [1, 2, 100] ``` -------------------------------- ### get_all_paths example Source: https://github.com/ysskrishna/nestedutils/blob/main/README.md Returns all paths to leaf values as lists of keys and indices. Only dict, list, and tuple are traversed; other containers are leaves. ```python from nestedutils import get_all_paths get_all_paths({"a": 1, "b": 2}) # [["a"], ["b"]] get_all_paths({"a": {"b": 1, "c": 2}}) # [["a", "b"], ["a", "c"]] get_all_paths({"users": [{"name": "Alice"}, {"name": "Bob"}]}) # [["users", 0, "name"], ["users", 1, "name"]] get_all_paths({}) # [] (no leaves) get_all_paths(42) # [[]] (primitive has empty path) ``` -------------------------------- ### v1.x vs v2.0 get_at with typo in path Source: https://github.com/ysskrishna/nestedutils/blob/main/migration-v1-to-v2.md Contrasts v1.x silent None with v2.0 raising PathError for a typo in the path. Shows how v2.0 exposes bugs immediately. ```python # v1.x - Bug hidden: typo in path returns None, not an error user_name = get_at(data, "usr.name") # None (typo: "usr" vs "user") # v2.0 - Bug exposed immediately user_name = get_at(data, "usr.name") # Raises PathError! ``` -------------------------------- ### v2.0 Sparse Data with Dict Integer Keys Source: https://github.com/ysskrishna/nestedutils/blob/main/migration-v1-to-v2.md For sparse data, use a dict with integer keys instead of a sparse list. This example shows storing values at keys 5 and 10. ```python # Instead of sparse list data = {"items": {5: "value", 10: "another"}} ``` -------------------------------- ### v1.x Sparse List Creation with FillStrategy.NONE Source: https://github.com/ysskrishna/nestedutils/blob/main/migration-v1-to-v2.md In v1.x, sparse lists could be created by specifying an index beyond the current length, with gaps filled by None. This example shows setting a value at index 5, resulting in a list with five None placeholders before the value. ```python from nestedutils import set_at data = {} set_at(data, "items.5", "value", fill_strategy=FillStrategy.NONE) # Result: {"items": [None, None, None, None, None, "value"]} ``` -------------------------------- ### v2.0 New Introspection Functions Source: https://github.com/ysskrishna/nestedutils/blob/main/migration-v1-to-v2.md v2.0 adds get_depth, count_leaves, and get_all_paths for inspecting nested structures. This example shows their usage and expected outputs. ```python from nestedutils import get_depth, count_leaves, get_all_paths data = {"a": {"b": 1, "c": 2}, "d": [3, 4]} get_depth(data) # 2 count_leaves(data) # 4 get_all_paths(data) # [["a", "b"], ["a", "c"], ["d", 0], ["d", 1]] ``` -------------------------------- ### v2.0 set_at with create parameter Source: https://github.com/ysskrishna/nestedutils/blob/main/migration-v1-to-v2.md Shows the new v2.0 API using the create boolean parameter. Sparse lists are no longer allowed; sequential building is required. The commented line demonstrates that attempting to create a sparse list raises PathError. ```python from nestedutils import set_at data = {} # v2.0: Simple create=True for auto-creation set_at(data, "user.name", "Alice", create=True) set_at(data, "items.0", "first", create=True) # Sparse lists are NO LONGER ALLOWED # set_at(data, "items.5", "sixth", create=True) # Raises PathError! # Must build sequentially set_at(data, "items.1", "second", create=True) # OK - appends ``` -------------------------------- ### v2.0 Migration: Remove FillStrategy, Use create=True Source: https://github.com/ysskrishna/nestedutils/blob/main/migration-v1-to-v2.md In v2.0, the FillStrategy enum is removed. Replace it with the create parameter in set_at. This example shows the new usage without the import. ```python # v2.0: No FillStrategy import needed from nestedutils import set_at set_at(data, "path", value, create=True) ``` -------------------------------- ### v2.0 Sequential List Building and Sparse Alternative Source: https://github.com/ysskrishna/nestedutils/blob/main/migration-v1-to-v2.md In v2.0, lists must be built sequentially using create=True for each index. For sparse or pre-sized lists, use plain Python to create the list with None placeholders, then set values at existing indices. ```python from nestedutils import set_at data = {} # Build lists sequentially set_at(data, "items.0", "first", create=True) set_at(data, "items.1", "second", create=True) set_at(data, "items.2", "third", create=True) # Result: {"items": ["first", "second", "third"]} # Or use plain Python for sparse/pre-sized lists data = {"items": [None] * 6} set_at(data, "items.5", "value") # OK - index exists ``` -------------------------------- ### get_at examples with default and negative index Source: https://github.com/ysskrishna/nestedutils/blob/main/README.md Shows get_at behavior: returns value, raises PathError when missing without default, returns default when provided, and supports negative indices. ```python from nestedutils import get_at, PathError data = {"a": {"b": {"c": 5}}} get_at(data, "a.b.c") # 5 get_at(data, "a.b.d") # Raises PathError (path doesn't exist) get_at(data, "a.b.d", default=99) # 99 (returns default) data = {"items": [{"name": "apple"}, {"name": "banana"}]} get_at(data, "items.1.name") # "banana" get_at(data, "items.-1.name") # "banana" (negative index) ``` -------------------------------- ### v2.0 get_at with try/except PathError Source: https://github.com/ysskrishna/nestedutils/blob/main/migration-v1-to-v2.md Catch PathError with try/except to handle missing paths explicitly. This is another alternative to the default parameter. ```python from nestedutils import get_at, PathError try: email = get_at(data, "user.email") except PathError: email = "default@example.com" ``` -------------------------------- ### v1.x get_at behavior with silent None and positional default Source: https://github.com/ysskrishna/nestedutils/blob/main/migration-v1-to-v2.md Shows v1.x behavior where get_at returns None for missing paths and allows positional default argument. Use this to understand the old behavior before migrating. ```python from nestedutils import get_at data = {"user": {"name": "Alice"}} # v1.x: Returns None silently - bugs can hide here! email = get_at(data, "user.email") # None age = get_at(data, "user.profile.age") # None # v1.x: default could be passed positionally value = get_at(data, "missing.path", None) # None (positional argument) ``` -------------------------------- ### v2.0 get_at with default parameter Source: https://github.com/ysskrishna/nestedutils/blob/main/migration-v1-to-v2.md Use the default parameter in v2.0 to provide a fallback value when the path is missing. The default must be passed as a keyword argument. ```python from nestedutils import get_at data = {"user": {"name": "Alice"}} # Explicit default - clear intent email = get_at(data, "user.email", default=None) # None email = get_at(data, "user.email", default="unknown@example.com") # fallback value ``` -------------------------------- ### v1.x FillStrategy Enum Usage Source: https://github.com/ysskrishna/nestedutils/blob/main/migration-v1-to-v2.md In v1.x, the FillStrategy enum was part of the public API. This example shows importing and using FillStrategy.AUTO. ```python from nestedutils import FillStrategy strategy = FillStrategy.AUTO ``` -------------------------------- ### v1.x set_at with fill_strategy Source: https://github.com/ysskrishna/nestedutils/blob/main/migration-v1-to-v2.md Shows the old v1.x API using the fill_strategy parameter with FillStrategy enum values and a positional string argument. Note that sparse list creation was allowed via FillStrategy.NONE. ```python from nestedutils import set_at, FillStrategy data = {} # v1.x: Various fill strategies set_at(data, "user.name", "Alice", fill_strategy=FillStrategy.AUTO) set_at(data, "items.0", "first", fill_strategy=FillStrategy.AUTO) set_at(data, "items.5", "sixth", fill_strategy=FillStrategy.NONE) # Sparse list! # v1.x: fill_strategy could be passed as string positionally set_at(data, "user.name", "Alice", "auto") # Positional argument ``` -------------------------------- ### delete_at example Source: https://github.com/ysskrishna/nestedutils/blob/main/README.md Deletes a value from a nested structure. List deletion requires allow_list_mutation=True; otherwise PathError is raised. Returns the deleted value. ```python from nestedutils import delete_at data = {"a": {"b": 1, "c": 2}} delete_at(data, "a.b") # Returns 1, data becomes {"a": {"c": 2}} data = {"items": [1, 2, 3]} delete_at(data, "items.1", allow_list_mutation=True) # Returns 2 # data becomes {"items": [1, 3]} ``` -------------------------------- ### get_depth example Source: https://github.com/ysskrishna/nestedutils/blob/main/README.md Returns the maximum nesting depth. Primitives return 0, empty containers return 1. Only dict, list, and tuple are traversed. ```python from nestedutils import get_depth get_depth(42) # 0 (primitive) get_depth({}) # 1 (empty container) get_depth({"a": 1}) # 1 (flat dict) get_depth({"a": {"b": 1}}) # 2 (nested) get_depth({"a": {"b": {"c": 1}}}) # 3 (deeper nesting) get_depth([1, [2, [3]]]) # 3 (nested lists) ``` -------------------------------- ### v2.0 get_at with exists_at check Source: https://github.com/ysskrishna/nestedutils/blob/main/migration-v1-to-v2.md Check for path existence with exists_at before calling get_at to avoid PathError. This is an alternative to using the default parameter. ```python from nestedutils import get_at, exists_at if exists_at(data, "user.email"): email = get_at(data, "user.email") else: email = "default@example.com" ``` -------------------------------- ### count_leaves example Source: https://github.com/ysskrishna/nestedutils/blob/main/README.md Counts leaf values (non-container). Empty containers return 0. Only dict, list, and tuple are traversed; other containers count as a single leaf. ```python from nestedutils import count_leaves count_leaves(42) # 1 (primitive is a leaf) count_leaves({}) # 0 (empty container) count_leaves({"a": 1, "b": 2}) # 2 (two leaf values) count_leaves({"a": {"b": 1, "c": 2}}) # 2 (nested, still 2 leaves) count_leaves([1, 2, [3, 4]]) # 4 (four leaf values) ``` -------------------------------- ### Using List Paths Source: https://github.com/ysskrishna/nestedutils/blob/main/README.md Shows how to use list paths to access keys that contain dots. This is useful when keys have special characters that would be misinterpreted in string paths. ```APIDOC ## Using List Paths ### Description Shows how to use list paths to access keys that contain dots. This is useful when keys have special characters that would be misinterpreted in string paths. ### Method Python function call ### Usage ```python from nestedutils import set_at data = {} set_at(data, ["user.name", "first"], "John", create=True) set_at(data, ["user.name", "last"], "Doe", create=True) # Creates: {"user.name": {"first": "John", "last": "Doe"}} ``` ``` -------------------------------- ### Handling None Values Source: https://github.com/ysskrishna/nestedutils/blob/main/README.md Demonstrates how nestedutils can navigate through None values when setting. None values are replaced with containers as needed. ```APIDOC ## Handling None Values ### Description Demonstrates how nestedutils can navigate through None values when setting. None values are replaced with containers as needed. ### Method Python function call ### Usage ```python from nestedutils import set_at data = {"a": None} set_at(data, "a.b.c", 10) # Replaces None with container: {"a": {"b": {"c": 10}}} ``` ``` -------------------------------- ### With nestedutils: Clean, safe, and readable Source: https://github.com/ysskrishna/nestedutils/blob/main/README.md Shows the clean, safe, and readable way to access nested data using nestedutils.get_at. ```python # With nestedutils: Clean, safe, and readable from nestedutils import get_at user_name = get_at(data, "users.0.profile.name") ``` -------------------------------- ### Using list paths to handle keys with dots Source: https://github.com/ysskrishna/nestedutils/blob/main/README.md Use list paths to set nested keys that contain dots, creating intermediate dictionaries when create=True. ```python from nestedutils import set_at data = {} set_at(data, ["user.name", "first"], "John", create=True) set_at(data, ["user.name", "last"], "Doe", create=True) # Creates: {"user.name": {"first": "John", "last": "Doe"}} ``` -------------------------------- ### Using negative list indices for reading and updating Source: https://github.com/ysskrishna/nestedutils/blob/main/README.md Negative indices work like Python list indexing for reading and updating existing elements. They cannot extend lists; out-of-bounds negative indices raise PathError. ```python from nestedutils import get_at, set_at data = {"items": [10, 20, 30]} get_at(data, "items.-1") # 30 (last item) set_at(data, "items.-1", 999) # Updates last item (must exist) ``` -------------------------------- ### Error Handling with PathError Source: https://github.com/ysskrishna/nestedutils/blob/main/README.md Demonstrates how to catch and handle PathError exceptions thrown by nestedutils functions. Shows accessing the error message and error code from the exception. ```APIDOC ## Error Handling with PathError ### Description Demonstrates how to catch and handle PathError exceptions thrown by nestedutils functions. Shows accessing the error message and error code from the exception. ### Method Python exception handling ### Usage ```python from nestedutils import set_at from nestedutils import PathError, PathErrorCode try: set_at(data, "invalid.path", 1) except PathError as e: print(e.message) # Error message print(e.code) # Error code (PathErrorCode enum) ``` ### Error Codes | Error Code | Description | |------------|-------------| | `INVALID_PATH` | Invalid path format or type | | `INVALID_INDEX` | Invalid list index | | `MISSING_KEY` | Key doesn't exist in dictionary | | `EMPTY_PATH` | Path is empty | | `IMMUTABLE_CONTAINER` | Attempted to modify a tuple | | `NON_NAVIGABLE_TYPE` | Attempted to navigate into a non-container type | | `OPERATION_DISABLED` | Operation is disabled by configuration (e.g., list deletion without `allow_list_mutation=True`) | ``` -------------------------------- ### Navigating through None values when setting Source: https://github.com/ysskrishna/nestedutils/blob/main/README.md When setting a path through a None value, the library replaces None with a container to hold the new value. ```python from nestedutils import set_at data = {"a": None} set_at(data, "a.b.c", 10) # Replaces None with container: {"a": {"b": {"c": 10}}} ``` -------------------------------- ### Negative List Indices Source: https://github.com/ysskrishna/nestedutils/blob/main/README.md Demonstrates using negative indices to access list elements from the end. Negative indices can only reference existing elements and cannot extend lists. ```APIDOC ## Negative List Indices ### Description Demonstrates using negative indices to access list elements from the end. Negative indices can only reference existing elements and cannot extend lists. ### Method Python function calls ### Usage ```python from nestedutils import get_at, set_at data = {"items": [10, 20, 30]} get_at(data, "items.-1") # 30 (last item) set_at(data, "items.-1", 999) # Updates last item (must exist) ``` ### Important Negative indices can only reference existing elements. They cannot extend lists - attempting to use a negative index that's out of bounds will raise a `PathError`. ``` -------------------------------- ### Standard Way: Verbose and hard to read Source: https://github.com/ysskrishna/nestedutils/blob/main/README.md Shows the verbose, error-prone boilerplate for accessing nested data without nestedutils. ```python # 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") ``` -------------------------------- ### Reading from and modifying tuples Source: https://github.com/ysskrishna/nestedutils/blob/main/README.md Tuples are read-only: reading works, but setting raises PathError because tuples are immutable. ```python from nestedutils import get_at, set_at, PathError data = {"items": (1, 2, 3)} get_at(data, "items.0") # 1 (works) set_at(data, "items.0", 9) # Raises PathError (tuples are immutable) ``` -------------------------------- ### set_at(data, path, value, *, create=False) Source: https://github.com/ysskrishna/nestedutils/blob/main/README.md Set a value in a nested data structure, optionally creating intermediate containers as needed. By default, raises PathError if any intermediate key is missing. With create=True, missing containers are automatically created. ```APIDOC ## set_at(data, path, value, *, create=False) ### Description Set a value in a nested data structure, optionally creating intermediate containers as needed. By default, raises PathError if any intermediate key is missing. With create=True, missing containers are automatically created. ### 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 set - `create`: If `True`, automatically creates missing intermediate containers (default: `False`) ### Note - By default (`create=False`), `set_at` raises `PathError` if any intermediate key is missing - With `create=True`, missing containers are automatically created: `{}` for dict keys, `[]` for list indices - Positive indices can append to lists (index == len(list)) but cannot create gaps (index > len(list)) - Negative indices can only modify existing elements ### Request Example ```python from nestedutils import set_at, PathError # create=True - auto-create missing containers data = {} set_at(data, "user.profile.name", "Alice", create=True) # Creates: {"user": {"profile": {"name": "Alice"}}} data = {} set_at(data, "items.0.name", "Item 1", create=True) # Creates: {"items": [{"name": "Item 1"}]} # Sequential list appending (no gaps allowed) data = {} set_at(data, "items.0", "first", create=True) # Creates list with first item set_at(data, "items.1", "second", create=True) # Appends second item # Creates: {"items": ["first", "second"]} # Sparse lists are NOT allowed - this raises PathError data = [1, 2, 3] set_at(data, "5", 99, create=True) # Raises PathError: cannot create gap # Negative indices - modify existing only data = [1, 2, 3] set_at(data, "-1", 100) # Updates existing last element # Creates: [1, 2, 100] ``` ``` -------------------------------- ### Working with Tuples Source: https://github.com/ysskrishna/nestedutils/blob/main/README.md Shows that tuples are read-only in nestedutils. You can read from them but attempting to modify them raises a PathError. ```APIDOC ## Working with Tuples ### Description Shows that tuples are read-only in nestedutils. You can read from them but attempting to modify them raises a PathError. ### Method Python function calls ### Usage ```python from nestedutils import get_at, set_at, PathError data = {"items": (1, 2, 3)} get_at(data, "items.0") # 1 (works) set_at(data, "items.0", 9) # Raises PathError (tuples are immutable) ``` ``` -------------------------------- ### get_at(data, path, *, default=...) Source: https://github.com/ysskrishna/nestedutils/blob/main/README.md Retrieve a value from a nested data structure. Returns the value at the path, or the provided default if the path doesn't exist. Raises PathError if the path doesn't exist and no default is provided. ```APIDOC ## get_at(data, path, *, default=...) ### Description Retrieve a value from a nested data structure. Returns the value at the path, or the provided default if the path doesn't exist. Raises PathError if the path doesn't exist and no default is provided. ### 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 (keyword-only). If you leave it out, a missing path raises `PathError` ### Returns The value at the path, or `default` if provided and path doesn't exist ### Raises `PathError` if the path doesn't exist and `default` is not provided ### Note By default, `get_at` raises `PathError` for missing paths. Use the `default` parameter for optional/nullable access. ### Request Example ```python from nestedutils import get_at, PathError data = {"a": {"b": {"c": 5}}} get_at(data, "a.b.c") # 5 get_at(data, "a.b.d") # Raises PathError (path doesn't exist) get_at(data, "a.b.d", default=99) # 99 (returns default) data = {"items": [{"name": "apple"}, {"name": "banana"}]} get_at(data, "items.1.name") # "banana" get_at(data, "items.-1.name") # "banana" (negative index) ``` ``` -------------------------------- ### get_all_paths(data) Source: https://github.com/ysskrishna/nestedutils/blob/main/README.md Returns all paths to leaf values in a nested structure as a list of paths, where each path is a list of keys (strings) and indices (integers). Only dict, list, and tuple are traversed. ```APIDOC ## get_all_paths(data) ### Description Get all paths to leaf values in a nested structure. ### Parameters - `data`: Any nested structure ### Returns List of paths, where each path is a list of keys (strings) and indices (integers). ### Request Example ```python from nestedutils import get_all_paths get_all_paths({"a": 1, "b": 2}) # [["a"], ["b"]] get_all_paths({"a": {"b": 1, "c": 2}}) # [["a", "b"], ["a", "c"]] get_all_paths({"users": [{"name": "Alice"}, {"name": "Bob"}]}) # [["users", 0, "name"], ["users", 1, "name"]] get_all_paths({}) # [] (no leaves) get_all_paths(42) # [[]] (primitive has empty path) ``` ``` -------------------------------- ### Catching PathError with error codes Source: https://github.com/ysskrishna/nestedutils/blob/main/README.md Wrap set_at calls in a try/except to catch PathError and access the message and code (PathErrorCode enum). ```python from nestedutils import set_at from nestedutils import PathError, PathErrorCode try: set_at(data, "invalid.path", 1) except PathError as e: print(e.message) # Error message print(e.code) # Error code (PathErrorCode enum) ``` -------------------------------- ### exists_at(data, path) Source: https://github.com/ysskrishna/nestedutils/blob/main/README.md Check if a path exists in a nested data structure. Returns True if the path exists, False otherwise. Raises PathError if the path format is invalid. ```APIDOC ## exists_at(data, path) ### Description Check if a path exists in a nested data structure. Returns True if the path exists, False otherwise. Raises PathError if the path format is invalid. ### Parameters - `data`: The data structure to navigate (dict, list, tuple, or nested combinations) - `path`: Path to check (string with dot notation or list of keys/indices) ### Returns `True` if the path exists, `False` otherwise ### Raises `PathError` if the path format is invalid ### Request Example ```python from nestedutils import exists_at data = {"a": {"b": {"c": 5}}} exists_at(data, "a.b.c") # True exists_at(data, "a.b.d") # False data = {"items": [{"name": "apple"}, {"name": "banana"}]} exists_at(data, "items.1.name") # True exists_at(data, "items.5.name") # False exists_at(data, "items.-1.name") # True (negative index) ``` ``` -------------------------------- ### delete_at(data, path, *, allow_list_mutation=False) Source: https://github.com/ysskrishna/nestedutils/blob/main/README.md Deletes a value from a nested data structure at the specified path. Returns the deleted value and raises PathError if the path doesn't exist or deletion is not allowed. ```APIDOC ## delete_at(data, path, *, allow_list_mutation=False) ### Description Delete a value from a nested data structure. ### Parameters - `data`: The data structure to modify - `path`: Path to the value to delete - `allow_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 ### Request Example ```python from nestedutils import delete_at data = {"a": {"b": 1, "c": 2}} delete_at(data, "a.b") # Returns 1, data becomes {"a": {"c": 2}} data = {"items": [1, 2, 3]} delete_at(data, "items.1", allow_list_mutation=True) # Returns 2 # data becomes {"items": [1, 3]} ``` ``` -------------------------------- ### get_depth(data) Source: https://github.com/ysskrishna/nestedutils/blob/main/README.md Returns the maximum nesting depth of a data structure. Primitives return 0, empty containers return 1, and only dict, list, and tuple are traversed. ```APIDOC ## get_depth(data) ### Description Get the maximum nesting depth of a data structure. ### Parameters - `data`: Any nested structure (dict, list, tuple, or primitive) ### Returns Integer depth. Primitives return 0, empty containers return 1. ### Request Example ```python from nestedutils import get_depth get_depth(42) # 0 (primitive) get_depth({}) # 1 (empty container) get_depth({"a": 1}) # 1 (flat dict) get_depth({"a": {"b": 1}}) # 2 (nested) get_depth({"a": {"b": {"c": 1}}}) # 3 (deeper nesting) get_depth([1, [2, [3]]]) # 3 (nested lists) ``` ``` -------------------------------- ### count_leaves(data) Source: https://github.com/ysskrishna/nestedutils/blob/main/README.md Counts the total number of leaf values (non-container values) in a nested structure. Empty containers return 0, and only dict, list, and tuple are traversed. ```APIDOC ## count_leaves(data) ### Description Count the total number of leaf values (non-container values) in a nested structure. ### Parameters - `data`: Any nested structure ### Returns Integer count of leaf values. Empty containers return 0. ### Request Example ```python from nestedutils import count_leaves count_leaves(42) # 1 (primitive is a leaf) count_leaves({}) # 0 (empty container) count_leaves({"a": 1, "b": 2}) # 2 (two leaf values) count_leaves({"a": {"b": 1, "c": 2}}) # 2 (nested, still 2 leaves) count_leaves([1, 2, [3, 4]]) # 4 (four leaf values) ``` ```