Skip to main content

data transfer objects with Python

Project description

Python DTO

rogervila/py_dto

Coverage Quality Gate Status Maintainability Rating

Data Transfer Objects (DTO) with Python.

Install

pip install py_dto

Usage

Define your object properties with types defined.

You can use custom objects and the Any type.

Example

We will create a User DTO with some properties.

from py_dto import DTO

# This DTO will be used as a type definition
class UserProfile(DTO):
    avatar: str

# The DTO with the properties defined
class User(DTO):
    profile: UserProfile
    name: str
    email: str
    age: int
    tags: list

# Create the DTO instance
user = User({
    'profile': UserProfile({'avatar': 'https://i.pravatar.cc/300'}),
    'name': 'John',
    'email': 'john@example.com',
    'age': 42,
    'tags': ['developer', 'python']
})

print(user.name) # 'John'
print(user.profile.avatar) # https://i.pravatar.cc/300

License

This project is open-sourced software licensed under the MIT license.

Original idea comes from spatie/data-transfer-object package for PHP.

Icons made by Pixel perfect from www.flaticon.com

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

py_dto-0.2.0.tar.gz (3.2 kB view hashes)

Uploaded Source

Built Distribution

py_dto-0.2.0-py3-none-any.whl (3.3 kB view hashes)

Uploaded 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