Dotty Dict

1.3.1 · active · verified Sat Apr 11

Dotty Dict is a Python library that provides a dictionary-like object for quick access to deeply nested keys using dot notation. It wraps standard Python dictionaries and supports various dictionary operations including creation, reading, updating, and deleting nested keys. The current stable version is 1.3.1, released in July 2022, suggesting a moderate release cadence.

Warnings

Install

Imports

Quickstart

Demonstrates creating a new Dotty instance, setting deeply nested values, accessing them, and wrapping an existing dictionary to modify its contents using dot notation and list indexing.

from dotty_dict import dotty

# Create a new dotty dict
data = dotty()
data['user.address.street'] = 'Main St'
data['user.address.city'] = 'Anytown'
data['items.0.name'] = 'Laptop'
data['items.0.price'] = 1200

print(f"Street: {data['user.address.street']}")
print(f"First item name: {data['items.0.name']}")

# Wrap an existing dictionary
existing_dict = {'product': {'details': {'id': 'P101', 'stock': 50}}}
dot_wrapper = dotty(existing_dict)
print(f"Product ID: {dot_wrapper['product.details.id']}")

dot_wrapper['product.details.stock'] = 45
print(f"Updated existing dict: {existing_dict}") # The underlying dict is modified

view raw JSON →