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.1.tar.gz (4.1 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.1-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: deep_variable-0.1.1.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for deep_variable-0.1.1.tar.gz
Algorithm Hash digest
SHA256 dd5c839dbb3aff4759d9df87f7fa5f9f788bb05318b9575f5786dc627c237ef1
MD5 20233aad64cf2811e2b7950b8caf079d
BLAKE2b-256 efade7370a284a14796c655a8eecf0a1fe2c239b0b84b18a965d6a854121750c

See more details on using hashes here.

Provenance

The following attestation bundles were made for deep_variable-0.1.1.tar.gz:

Publisher: publish.yml on CreativeCubicle/deep-variable

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: deep_variable-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for deep_variable-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6403975e65564c461d01223a7d43bad4a7be71f140e6df33199e8779908d8fa4
MD5 95552c130df2fc6a814273f36a0d0aca
BLAKE2b-256 26725905db14636bdfa386645f766c7363e0aade8b7263918e7aa31a468885a3

See more details on using hashes here.

Provenance

The following attestation bundles were made for deep_variable-0.1.1-py3-none-any.whl:

Publisher: publish.yml on CreativeCubicle/deep-variable

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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