Skip to main content

**Deep Variable** is a lightweight, zero-dependency Python utility designed to eliminate `KeyError` and `TypeError` crashes when working with deeply nested data structures

Project description

Deep Variable 🚀

CI PyPI version License: MIT Python Versions

Deep Variable is a lightweight, zero-dependency Python utility designed to eliminate KeyError and TypeError crashes when working with deeply nested data structures.


✨ Features

  • Safe Traversal: Access deeply nested keys without worrying about missing parents.
  • Intelligent List Navigation: Treat string indices (e.g., "0") as list offsets automatically.
  • Zero Dependencies: Pure Python Standard Library implementation—fast and secure.
  • Fully Type-Hinted: Optimized for IDE IntelliSense and mypy strict mode.
  • Custom Separators: Use dots, slashes, or any delimiter that fits your data.

🚀 The Difference

The Old Way (Standard Python)

# 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")

The Deep Variable Way

from deep_variable import DeepVariable

# Flat, clean, and crash-proof
email = DeepVariable.get(data, "users.0.profile.email", default="default@site.com")

📦 Installation

Install the latest version using pip or uv:

pip install deep-variable
# OR
uv add deep-variable

🛠 Usage Examples

  1. Safe Reading (Getter)
Python
data = {"org": {"teams": [{"name": "Engineering"}]}}

Navigate through mixed Dicts and Lists

name = DeepVariable.get(data, "org.teams.0.name") # Returns "Engineering"

Safe default on missing path

role = DeepVariable.get(data, "org.teams.0.role", default="Developer") # Returns "Developer"

2. Existence Checking

Python
data = {"status": {"active": False}}

Returns True even if the value is Falsy

DeepVariable.has(data, "status.active") # True
DeepVariable.has(data, "status.missing") # False

3. Safe Writing (Setter)

Python
data = {}
Automatically creates intermediate dictionaries
DeepVariable.set(data, "meta.tags.primary", "python")
print(data) # {'meta': {'tags': {'primary': 'python'}}}

🛡 Performance & Safety

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

deep_variable-0.1.0.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

deep_variable-0.1.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file deep_variable-0.1.0.tar.gz.

File metadata

  • Download URL: deep_variable-0.1.0.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for deep_variable-0.1.0.tar.gz
Algorithm Hash digest
SHA256 04d23cd5a5bde34efa8fba0dd42a6d642b200f89bd102e9f90706a578334e08c
MD5 01d56bb03540c0f9056e9acd8ea888ef
BLAKE2b-256 4bb11407e931188b90a9c669dbe16d39f69bd5ad45b8658b4e57ad05ffabb9af

See more details on using hashes here.

File details

Details for the file deep_variable-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: deep_variable-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for deep_variable-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c398d0a5d2829f09d9ab2c6b8b6aea5febddcf26b6ece9a8c118e9004ed9de9b
MD5 6f22bc69cd3b448d049c06661c782041
BLAKE2b-256 2d6c5afed5b46db0666cd33a8e94cefbaa8bfb659d53d2eef97b32b7dcc1e22a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page