Skip to main content

provides DTO object for object-like experience with dicts

Project description

License Release Supported versions Code Coverage Build Status Travis CI

python-simple-dto

Dict, that behaves like an object.

To achieve this BasicDTO and DTO were introduced. They brings object-like attribute access appearance to dicts. BasicDTO more suits for “flat” dict and DTO - for more complex.

This Package doesn’t provides validation(there are more suitable tools today) and “fromstring” functionality (single responsibility, you should load data by your own)

Example of usage

DTO

>>> from src.python_simple_dto.dto import DTO
>>> test_dict = {
...     "users": [{"name": "Alex", "age": 29}, {"name": "Russel", "age": 19}]
... }
>>> test_dto
{'users': [{'name': 'Alex', 'age': 29}, {'name': 'Russel', 'age': 19}]}
>>> test_dto.users
[{'name': 'Alex', 'age': 29}, {'name': 'Russel', 'age': 19}]
>>>test_dto.roles = ["guest", "user", "moderator"]
>>>test_dto
{'users': [{'name': 'Alex', 'age': 29}, {'name': 'Russel', 'age': 19}], 'roles': ['guest', 'user', 'moderator']}
>>>test_dto.roles
['guest', 'user', 'moderator']
>>>test_dto["roles"]
['guest', 'user', 'moderator']

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

python-simple-dto-0.0.2.tar.gz (3.3 kB view hashes)

Uploaded Source

Built Distribution

python_simple_dto-0.0.2-py2.py3-none-any.whl (3.3 kB view hashes)

Uploaded Python 2 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