Python package that transforms flat or nested dictionaries into objects.
Project description
toobj: Transform a dictionary into an object
Python package that transforms flat or nested dictionaries into objects.
Installation
pip install toobj
ToObj
Transforms flat or nested dictionaries into objects.
Args
Parameter | Type | Description |
---|---|---|
d |
dict |
Dictionary to convert in Python object. |
from toobj import ToObj
d = dict(...)
obj = ToObj(d)
Usage
from toobj import ToObj
# Sample data
data = {
'name': 'Alice',
'age': 30,
'address': {
'city': 'Wonderland',
'zipcode': 12345,
'coordinates': {
'lat': 52.5200,
'long': 13.4050,
'meta': {
'continent': 'Europe',
'population': 3000000
}
}
},
'contacts': {
'email': 'alice@example.com',
'phones': [
{'type': 'home', 'number': '123-456'},
{'type': 'work', 'number': '789-101'}
]
},
'hobbies': ['reading', 'traveling', {'name': 'coding', 'level': 'advanced'}]
}
# Dictionary to object
data_obj = ToObj(data)
>>> data_obj.name
'Alice'
>>> data_obj.address.zipcode
12345
>>> data_obj.address.coordinates.meta.continent
'Europe'
>>> data_obj.contacts.phones[0].number
'123-456'
>>> data_obj.hobbies[2].name
'coding'
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
toobj-0.0.1.tar.gz
(14.5 kB
view details)
Built Distribution
toobj-0.0.1-py3-none-any.whl
(14.5 kB
view details)
File details
Details for the file toobj-0.0.1.tar.gz
.
File metadata
- Download URL: toobj-0.0.1.tar.gz
- Upload date:
- Size: 14.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b99e5db88635acb68fd38b60399521237d2a9fbad9545a50f1dbcb04b89b7a4 |
|
MD5 | b59cf16c2f47569ff03a6d096753f106 |
|
BLAKE2b-256 | 9d25debc9199acd2a5e46fcce3ca17000ebf2d8a1be1ab8cf2023da0dbee7c83 |
File details
Details for the file toobj-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: toobj-0.0.1-py3-none-any.whl
- Upload date:
- Size: 14.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e6fe1982e4f2a3a8b074503080fad4d3f761b2d1d3cb7ae32663e0285b63d5b9 |
|
MD5 | f47afdfaec4b6a17e9dd8fa838ddcc81 |
|
BLAKE2b-256 | b0def9f64a26d2a8f42d8434e4d761afb4357afe21d655aa5c27071f4f9aa9ca |