Skip to main content

lollipop

License: MIT Build Status Documentation Status PyPI

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

License

MIT licensed. See the bundled LICENSE file for more details.

Release files for lollipop 1.1.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lollipop 1.1.8
File Size Uploaded
lollipop-1.1.8.tar.gz 78.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lollipop 1.1.8
File Interpreter ABI Platform
lollipop-1.1.8-py3-none-any.whl Python 3 none any Details

Total release size: 102.2 kB

Release files / lollipop-1.1.8.tar.gz

Download URL lollipop-1.1.8.tar.gz
Size 78.6 kB
Tags Source
SHA-256 checksum
How to use checksums
bf4897800ca6272377bff02d6cab6c50fcdda9763b38030851c34dc84a357f7b
BLAKE2b-256 checksum
How to use checksums
b4a20802ee33aed913fa0d1ef8a81615d28748a09c8878caa2d4c8f9fc58adad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release files / lollipop-1.1.8-py3-none-any.whl

Download URL lollipop-1.1.8-py3-none-any.whl
Size 23.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9801cb0fd45056112b99969b6866d777738c02dee6ad8ffc9e609bc6e768b303
BLAKE2b-256 checksum
How to use checksums
0549d58d63f9566de914853f67182ef836a0d03369a6fd07e343ec4c07330511
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release history Release notifications | RSS feed

This release

1.1.8 This release

2 release files

1.1.7

2 release files

1.1.6

2 release files

1.1.5

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1

1 release file

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0

1 release file

0.3

2 release files

0.2

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page