Skip to main content
Help us improve Python packaging – donate today!

Fast and flexible object mapping (serialization, marshalling)

Project Description

.. sourcecode :: python

Lion is a very flexible yet fast library for mapping objects to
dictionaries. It uses a declarative API and supports a query language
similar to GraphQL. Unlike other serialization libraries it also
allows to skip entire fields instead of having a ``null`` value
in the dictionary.

It is inspired by libraries like serpy_, marshmallow_,
`Django REST Framework`_ and Kim_.


import lion

class UserMapper(lion.Mapper):
id = lion.UUIDField()
email = lion.StrField(condition=lion.skip_empty)
first_name = lion.StrField()
last_name = lion.StrField()

user = User(

# Dump all fields to a dictionary
assert UserMapper().dump(user) == {
'id': 'ad94d0e8-2526-4d9b-ad76-0fbffcf41033',
'email': '',
'first_name': 'John',
'last_name': 'Doe'

# Dump a subset of fields
assert UserMapper('{id,email}').dump(user) == {
'id': 'ad94d0e8-2526-4d9b-ad76-0fbffcf41033',
'email': ''

The query language also supports subfields::


The performance is somewhat slower than serpy_ but still far ahead of
marshmallow_ and `Django REST Framework`_

Right now only ``dumping`` (aka. serialization, marshalling) is supported
but future versions will also introduce ``loading`` (aka. deserialization,
unmarshalling) of data.

.. _serpy:
.. _marshmallow:
.. _Kim:
.. _`Django REST Framework`:

Release history Release notifications

This version
History Node


History Node


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
lion-0.1.1-py3-none-any.whl (8.2 kB) Copy SHA256 hash SHA256 Wheel 3.6 Nov 14, 2017
lion-0.1.1.tar.gz (5.2 kB) Copy SHA256 hash SHA256 Source None Nov 14, 2017

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page