Data serialization and validation library
Project description
Data serialization and validation library
Features
flexible schema definition API with powerful type combinators
data validation
serialization/deserialization
in-place deserialization
Example
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)
harryPotter1 = Book(
title='Harry Potter and the Philosopher\'s Stone',
publish_date=date(1997, 6, 26),
author=Person(name='J. K. Rowling')
)
# Dumping
BookType.dump(harryPotter1)
# => {'title': 'Harry Potter and the Philosopher\'s Stone',
# 'publish_date': '1997-06-26',
# 'author': {'name': 'J. K. Rowling'}}
# Loading
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'))
# Partial inplace loading
BookType.load_into(harryPotter1, {'publish_date': '1997-06-27'})
# => Book(title='Harry Potter and the Philosopher\'s Stone',
# publish_date=date(1997, 06, 27),
# author=User(name='J. K. Rowling'))
# Loading list of objects
List(BookType).load([
{'title': 'Harry Potter and the Philosopher\'s Stone',
'publish_date': '1997-06-26',
'author': {'name': 'J. K. Rowling'}},
{'title': 'Harry Potter and the Chamber of Secrets',
'publish_date': '1998-07-02',
'author': {'name': 'J. K. Rowling'}},
])
# => [Book(...), Book(...)]
# Validation
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.6
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lollipop-1.1.8.tar.gz.
File metadata
- Download URL: lollipop-1.1.8.tar.gz
- Upload date:
- Size: 78.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf4897800ca6272377bff02d6cab6c50fcdda9763b38030851c34dc84a357f7b
|
|
| MD5 |
c918eca92f36c49c00b2c0ce1a14c243
|
|
| BLAKE2b-256 |
b4a20802ee33aed913fa0d1ef8a81615d28748a09c8878caa2d4c8f9fc58adad
|
File details
Details for the file lollipop-1.1.8-py3-none-any.whl.
File metadata
- Download URL: lollipop-1.1.8-py3-none-any.whl
- Upload date:
- Size: 23.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9801cb0fd45056112b99969b6866d777738c02dee6ad8ffc9e609bc6e768b303
|
|
| MD5 |
0fff1cb25b4b8d7b762a4e739b93956d
|
|
| BLAKE2b-256 |
0549d58d63f9566de914853f67182ef836a0d03369a6fd07e343ec4c07330511
|