Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:AIScientists Dev WorldSeed nested dict path access

From Leeroopedia
Knowledge Sources
Domains Utilities, Data_Structures
Last Updated 2026-10-26 18:00 GMT

Overview

Concrete nested dict utilities for reading and writing values at dot-separated paths, provided by the WorldSeed library.

Description

The nested module provides two pure functions with no DSL or engine dependencies. `nested_get(d, dotpath)` reads a value from a nested dict using a dot-separated path (e.g. `"a.b"` → `d["a"]["b"]`), returning `None` if any key is missing or a non-dict is encountered. `nested_set(d, dotpath, value)` writes a value into a nested dict, creating intermediate dicts as needed, and returns the old value (or `None` if the key didn't exist). These are used by the state store (engine layer) and DSL functions (DSL layer) as the shared dict-path interface.

Usage

Import these utilities when you need to read or write nested dict values by dot-path — e.g., traversing entity `data` dicts for DSL property access, or setting deeply nested state fields.

Code Reference

Source Location

  • Repository: WorldSeed
  • File: src/worldseed/utils/nested.py

Signature

def nested_get(d: dict[str, Any], dotpath: str) -> Any:
    """Read a value from a nested dict using a dot-separated path."""

def nested_set(d: dict[str, Any], dotpath: str, value: Any) -> Any:
    """Write a value into a nested dict using a dot-separated path. Returns old value."""

Import

from worldseed.utils.nested import nested_get, nested_set

I/O Contract

Inputs

Name Type Required Description
d dict[str, Any] Yes Root dict to traverse
dotpath str Yes Dot-separated path (e.g. `"a.b.c"`)
value Any Yes (set) Value to write

Outputs

Name Type Description
nested_get returns Any Value at path, or None if not found
nested_set returns Any Previous value at path (or None)

Usage Examples

from worldseed.utils.nested import nested_get, nested_set

data = {"player": {"inventory": {"gold": 100}}}

# Read nested value
gold = nested_get(data, "player.inventory.gold")
# gold = 100

# Read missing path
missing = nested_get(data, "player.health")
# missing = None

# Write nested value (creates intermediate dicts)
old = nested_set(data, "player.inventory.gems", 5)
# old = None, data["player"]["inventory"]["gems"] = 5

# Overwrite existing value
old = nested_set(data, "player.inventory.gold", 200)
# old = 100, data["player"]["inventory"]["gold"] = 200

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment