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
Release history Release notifications | RSS feed
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 details)
Built Distribution
File details
Details for the file dotmapdict-1.0.0.tar.gz
.
File metadata
- Download URL: dotmapdict-1.0.0.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ce282c529a951b490676cb709c0a211d9d8cbb470215d21b6354adbf890c913 |
|
MD5 | abfc82a14ab4f2a6d29d169174679e87 |
|
BLAKE2b-256 | 82d4ec880c1fd0257e4bba341704be34c50019cfb7e83abcf3a9dc1da1337a8d |
File details
Details for the file dotmapdict-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: dotmapdict-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4207bf78cc287060b7b14dcddb96c5b0f7f6c2f1f80a911a81b1d8eabeea1c67 |
|
MD5 | 94d85fb1a0080caed1f4e37bbfcf69da |
|
BLAKE2b-256 | b9e25ab01a0570a7082fce4cdd022926b5bfb688b7753c6662c661ac9bf3c46d |