Skip to main content

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 of obj['key']).
  • Synchronization with the original dictionary if passed at instantiation.
  • Utility methods for recursive conversion of nested structures to and from objdict and dict.
  • 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 to objdict if keys are valid identifiers.
  • to_dict(): Convert an objdict 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


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)

Uploaded Source

Built Distribution

objdict_bf-0.1.0-py3-none-any.whl (6.2 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