pydapt

Ruby's OpenStruct for python


License
MIT
Install
pip install pydapt==0.4

Documentation

License: MIT codecov Build Status Python 3.7

Flexible Object

Flexible objects coverts a dictionary into an object. It is similar to the OpenStruct of ruby.

Installation

Python Version Required >= 3
pip install flexible-object

Usage

Converting a dictionary to Object

from flexible_object.models import FlexibleObject

dictionary = {"test": 1, "test1": {"test2": 2}}
flexible_object = FlexibleObject(dictionary)

print(flexible_object.test) # 1
print(flexible_object.test1.test2) # 2

Converting a dictionary to Object with kwargs

from flexible_object.models import FlexibleObject

dictionary = {"test": 1, "test1": {"test2": 2}}
flexible_object = FlexibleObject(dictionary, test3=3, test4=4)

print(flexible_object.test) # 1
print(flexible_object.test1.test2) # 2
print(flexible_object.test3) # 3
print(flexible_object.test4) # 4

Deleting an attribute

from flexible_object.models import FlexibleObject

dictionary = {"test": 1, "test1": {"test2": 2}}
flexible_object = FlexibleObject(dictionary)

print(flexible_object.test) # 1
print(flexible_object.test1.test2) # 2

flexible_object.drop('test3') # None
flexible_object.drop('test') # 1

print(flexible_object.test) # AttributeError: 'FlexibleObject' object has no attribute 'test'