Data serialization and validation library
Project description
Data serialization and validation library
from lollipop.types import Object, String, Date
from lollipop.validators import Length
from collections import namedtuple
from datetime import date
Person = namedtuple('Person', ['name'])
Book = namedtuple('Book', ['title', 'publish_date', 'author'])
PersonType = Object({
'name': String(validate=Length(min=1)),
}, constructor=Person)
BookType = Object({
'title': String(),
'publish_date': Date(),
'author': PersonType,
}, constructor=Book)
BookType.dump(
Book(
title='Harry Potter and the Philosopher\'s Stone',
publish_date=date(1997, 06, 26),
author=Person(name='J. K. Rowling')
)
)
# => {'title': 'Harry Potter and the Philosopher\'s Stone',
# 'publish_date': '1997-06-26',
# 'author': {'name': 'J. K. Rowling'}}
BookType.load({'title': 'Harry Potter and the Philosopher\'s Stone',
'publish_date': '1997-06-26',
'author': {'name': 'J. K. Rowling'}})
# => Book(title='Harry Potter and the Philosopher\'s Stone',
# publish_date=date(1997, 06, 26),
# author=User(name='J. K. Rowling'))
BookType.validate({
'title': 'Harry Potter and the Philosopher\'s Stone',
'author': {'name': ''},
})
# => {'author': {'name': 'Length should be at least 1'},
# 'publish_date': 'Value is required'}
Installation
$ pip install lollipop
Documentation
Documentation is available at http://lollipop.readthedocs.io/ .
Requirements
Python >= 2.6 or <= 3.5
Project Links
Documentation: http://lollipop.readthedocs.io/
License
MIT licensed. See the bundled LICENSE file for more details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
lollipop-0.2.tar.gz
(53.6 kB
view hashes)
Built Distribution
lollipop-0.2-py2.py3-none-any.whl
(14.9 kB
view hashes)
Close
Hashes for lollipop-0.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbcb8a30d9696b97c7677e01230fd4a2ccbd9b86d99d56d7412b72bd271c02dd |
|
MD5 | 8223e4d48bd70573cd64ce38fc27e5dc |
|
BLAKE2b-256 | f57ff9d891674f4ff2d6c615c84dfee67a6dff63c012fa6b9813269dad18a0ef |