data2objects

raw JSON →
0.1.0 verified Mon Apr 27 auth: no python

A lightweight library for transforming nested dictionaries, JSON, or similar data structures into Python objects with attribute-style access. Current version 0.1.0, released in 2023. Release cadence is sporadic.

pip install data2objects
error AttributeError: 'DataObject' object has no attribute 'some-key'
cause Accessing attribute that is not a valid Python identifier (e.g., contains hyphen)
fix
Use getattr(obj, 'some-key') or obj['some-key'] if available.
error TypeError: from_data() missing 1 required positional argument: 'data'
cause Calling from_data without arguments
fix
Pass a dictionary or list as the first argument: from_data(data)
gotcha Keys that are not valid Python identifiers (e.g., with spaces, starting with digits) will raise AttributeError when accessed as attributes.
fix Use dictionary-style access (obj['key']) or sanitize keys before conversion.
gotcha Nested lists of dicts are not recursively converted; each dict remains a dict inside a list.
fix Manually map list items with from_data if needed.

Convert a nested dict into an object with dot-access.

from data2objects import from_data

data = {'name': 'Alice', 'age': 30, 'address': {'city': 'Wonderland', 'zip': '12345'}}
obj = from_data(data)
print(obj.name)
print(obj.address.city)