Skip to main content

A dictionary that supports dot notation access

Project description

dotmapdict

dotmapdict is a Python package that enhances the standard dictionary with dot notation access. This makes it easier to work with nested dictionaries by allowing you to access and modify their elements using attribute-style access.

Features

  • Dot Notation Access: Access dictionary keys as attributes.
  • Nested Dictionary Handling: Automatically converts nested dictionaries into DotDict instances.
  • Merge Support: Merge another dictionary into the existing DotDict.
  • Flexible Updates: Update dictionary keys with dot notation.
  • Convert to Standard Dictionary: Easily convert DotDict instances back to standard Python dictionaries.
  • Full Unit Test Coverage: Comprehensive tests ensure the robustness of dotmapdict.

Installation

Install dotmapdict via pip:

pip install dotmapdict

Usage Here's a basic example of how to use dotmapdict:

from dotmapdict import DotDict

# Initialize a DotDict instance with nested dictionaries
config = DotDict({"database": {"host": "localhost", "port": 5432}}, debug=True)

# Access values using dot notation
print(config.database.host)  # Output: localhost
print(config.debug)  # Output: True

# Update values using dot notation
config.database.username = "admin"
print(config.database.username)  # Output: admin

# Convert back to a standard dictionary
# Output: {'database': {'host': 'localhost', 'port': 5432, 'username': 'admin'}, 'debug': True}
print(config.to_dict())
print(type(config.to_dict()))  # Output: <class 'dict'>

# Merge another dictionary into the existing DotDict
config.merge({"database": {"password": "secret"}})
print(config.database.password)  # Output: secret

# Update the DotDict with another dictionary
config.update({"database": {"port": 5433, "ssl": False}})
print(config.database.port)  # Output: 5433
print(config.database.ssl)  # Output: False

# Delete a value using dot notation
del config.database.username
del config.database.port
print(config.database.username)  # Output: None
print(config.database)  # Output: {'host': 'localhost', 'password': 'secret', 'ssl': False}

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contact

For any inquiries or issues, create an issue

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

dotmapdict-1.0.0.tar.gz (4.1 kB view hashes)

Uploaded Source

Built Distribution

dotmapdict-1.0.0-py3-none-any.whl (4.4 kB view hashes)

Uploaded Python 3

Supported by

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