Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/maximkulkin/lollipop
Python data serialization/validation library
https://github.com/maximkulkin/lollipop
json python serialization validation
Last synced: 8 days ago
JSON representation
Python data serialization/validation library
- Host: GitHub
- URL: https://github.com/maximkulkin/lollipop
- Owner: maximkulkin
- License: mit
- Created: 2016-07-19T18:10:50.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-04-26T12:11:50.000Z (6 months ago)
- Last Synced: 2024-05-01T23:18:53.758Z (6 months ago)
- Topics: json, python, serialization, validation
- Language: Python
- Size: 300 KB
- Stars: 36
- Watchers: 7
- Forks: 8
- Open Issues: 4
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGELOG.rst
- License: LICENSE
Awesome Lists containing this project
- starred-awesome - lollipop - Python data serialization/validation library (Python)
README
********
lollipop
********.. image:: https://img.shields.io/pypi/l/lollipop.svg
:target: https://github.com/maximkulkin/lollipop/blob/master/LICENSE
:alt: License: MIT.. image:: https://img.shields.io/travis/maximkulkin/lollipop.svg
:target: https://travis-ci.org/maximkulkin/lollipop
:alt: Build Status.. image:: https://readthedocs.org/projects/lollipop/badge/?version=latest
:target: http://lollipop.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status.. image:: https://img.shields.io/pypi/v/lollipop.svg
:target: https://pypi.python.org/pypi/lollipop
:alt: PyPIData serialization and validation library
Features
========
* flexible schema definition API with powerful type combinators
* data validation
* serialization/deserialization
* in-place deserializationExample
=======
.. code-block:: pythonfrom lollipop.types import Object, String, Date
from lollipop.validators import Length
from collections import namedtuple
from datetime import datePerson = 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/
- PyPI: https://pypi.python.org/pypi/lollipop
- Issues: https://github.com/maximkulkin/lollipop/issuesLicense
=======MIT licensed. See the bundled `LICENSE `_ file for more details.