Deep Variable is a lightweight, zero-dependency Python utility designed to eliminate KeyError and TypeError crashes when working with deeply nested data structures.
"0") as list offsets automatically.mypy strict mode.# This is fragile and hard to read
email = None
if data and "users" in data and len(data["users"]) > 0:
profile = data["users"][0].get("profile")
if profile:
email = profile.get("email", "default@site.com")
from deep_variable import DeepVariable
# Flat, clean, and crash-proof
email = DeepVariable.get(data, "users.0.profile.email", default="default@site.com")
Install the latest version using pip or uv:
pip install deep-variable
# OR
uv add deep-variable
Python
data = {"org": {"teams": [{"name": "Engineering"}]}}
name = DeepVariable.get(data, "org.teams.0.name") # Returns "Engineering"
role = DeepVariable.get(data, "org.teams.0.role", default="Developer") # Returns "Developer"
Python
data = {"status": {"active": False}}
DeepVariable.has(data, "status.active") # True
DeepVariable.has(data, "status.missing") # False
Python
data = {}
DeepVariable.set(data, "meta.tags.primary", "python")
print(data) # {'meta': {'tags': {'primary': 'python'}}}
Iterative Logic: Unlike recursive utilities, deep-variable uses loops, making it safe for exceptionally deep JSON structures without risking a RecursionError.
Strict Typing: Built with mypy –strict compliance