Skip to main content

data validation and conversion library

Project description

PyDTO is a data conversion library. It can validate data, that comes from various data serialization formats like JSON, YAML, etc. and convert it to native Python datatypes. It can also convert native Python objects to described DTO.

A taste of this library:

>>> from decimal import Decimal
>>> from pydto import Schema, Required, List, Enum
>>> SCHEMA = Schema(List({
...     Required('price'): Decimal,
...     Required('category'): Enum('laptops', 'tablets', 'phones'),
...     Required('quantity'): int,
...     Required('serial'): (str, int)
... }))
>>> result = SCHEMA([
... {'price': '399.99', 'category': 'tablets', 'quantity': '2', 'serial': ['ta', '237']},
... {'price': '899.99', 'category': 'laptops', 'quantity': '1', 'serial': ['ag', '863']},
... {'price': '199.99', 'category': 'phones', 'quantity': '3', 'serial': ['lz', '659']}
])
>>> assert result == [
... {'price': Decimal('399.99'), 'category': 'tablets', 'quantity': 2, 'serial': ['ta', 237]},
... {'price': Decimal('899.99'), 'category': 'laptops', 'quantity': 1, 'serial': ['ag', 863]},
... {'price': Decimal('199.99'), 'category': 'phones', 'quantity': 3, 'serial': ['lz', 659]}
]

Check out documentation for more detailed review at Github repo.

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

pydto-0.4.1.tar.gz (8.4 kB view details)

Uploaded Source

File details

Details for the file pydto-0.4.1.tar.gz.

File metadata

  • Download URL: pydto-0.4.1.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pydto-0.4.1.tar.gz
Algorithm Hash digest
SHA256 f6ea35828a7a714364b795ab6647ac70ef4a97c7d4045eaa12f1aa3fcf1ea4f7
MD5 e2b2817add488947c62513b17fa5cd23
BLAKE2b-256 569bf809df2617d2839fb35a8f2d6fa24b2d8bf62e4ca6eb3684f9b1111874ea

See more details on using hashes here.

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