A custom object dictionary module that allows attribute-style access to dictionary items.
Project description
objdict
objdict
is a Python module that provides a class for conveniently manipulating dictionaries or dict-based JSON nested structures using attribute-like syntax. It is intended mostly to ease the manipulation of JSON data, web requests responses, configuration files, and more.
Features
- Attribute-style access to dictionary items (e.g.,
obj.key
instead ofobj['key']
). - Synchronization with the original dictionary if passed at instantiation.
- Utility methods for recursive conversion of nested structures to and from
objdict
anddict
. - JSON serialization and deserialization methods for both strings and files.
Installation
pip install objdict-bferrand
Usage
Here's a simple example of how to use objdict
:
from objdict import objdict
# Create an objdict with some initial data
data = objdict({'name': 'John', 'age': 30, 'location': 'New York'})
# Access data using attribute-style access
print(data.name) # Output: John
print(data.age) # Output: 30
# Modify data
data.age = 31
# Serialize to JSON string
json_string = data.dumps()
# Deserialize from JSON string
new_data = objdict.loads(json_string)
Methods
to_objdict()
: Convert a dictionary toobjdict
if keys are valid identifiers.to_dict()
: Convert anobjdict
to a dictionary, recursively.loads()
,dumps()
: Load from and dump to JSON strings.load()
,dump()
: Load from and dump to JSON files.
... and many more.
License
This project is licensed under the MIT License - see the LICENSE file for details.
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
objdict-bf-0.1.0.tar.gz
(5.7 kB
view hashes)
Built Distribution
Close
Hashes for objdict_bf-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c236d189572b7ce1fc2cb8e8f48948bafbd2c211fc215cfd9c80fad9ae75e38f |
|
MD5 | d6c7352c4c331b21b193952e255dd0d7 |
|
BLAKE2b-256 | 26029cf1ec333c9d75e131b4071e494857ede26bba8deb933f52ab25a30efd22 |