Object Document Mapping for convenient python-to-json and json-to-python conversions
Usage example:
class SimpleContainer(BaseDocument):
field_string = StringField()
field_integer = IntegerField()
field_boolean = BooleanField()
field_datetime = DateTimeField()
field_decimal = DecimalField()
class HostContainer(BaseDocument):
nested_document = NestedDocumentField(SimpleContainer)
field_list = ListField()
field_dict = DictField()
... somewhere in the code ...
model = HostContainer()
model.field_dict['aaa'] = 'bbb'
model.field_list.append('ccc')
model.nested_document.field_boolean = True
model.nested_document.field_string = 'a short string description'
model.nested_document.field_datetime = datetime.now()
model.nested_document.field_decimal = 123.123
model.nested_document.field_integer = 123
json_document = model.to_json()
assert isinstance(json_data, dict)
m2 = HostContainer.from_json(json_document)
Inspired by:
BSD 3-Clause License.
Refer to LICENSE for details.
/tests/ folder contains unit test
/odm/ folder contains Object-Document Mapping modules
To run all tests from the tests directory, run following from the command line:
$> python -m unittest discover tests
- python 3.7+