Fast and flexible object mapping (serialization, marshalling)
Project description
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.
Example:
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( id=UUID('ad94d0e8-2526-4d9b-ad76-0fbffcf41033'), email='john.doe@example.com', first_name='John', last_name='Doe' ) # Dump all fields to a dictionary assert UserMapper().dump(user) == { 'id': 'ad94d0e8-2526-4d9b-ad76-0fbffcf41033', 'email': 'john.doe@example.com', 'first_name': 'John', 'last_name': 'Doe' } # Dump a subset of fields assert UserMapper('{id,email}').dump(user) == { 'id': 'ad94d0e8-2526-4d9b-ad76-0fbffcf41033', 'email': 'john.doe@example.com' }
The query language also supports subfields:
UserMapper('{id,email,groups{id,name}}).dump(user)
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.
Project details
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
File details
Details for the file lion-0.2.0.tar.gz
.
File metadata
- Download URL: lion-0.2.0.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Python-urllib/3.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0263eb5dbb41a77ae2bc918201b57caf8fad26208e3554fdfa7026746e8540b5 |
|
MD5 | 97fd8e0a1de45188b476eba43bce10be |
|
BLAKE2b-256 | 8bc0fa3bbbf0d544733476520737b383830aaf27ccc704cc4d824daf7f549781 |
File details
Details for the file lion-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: lion-0.2.0-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: Python-urllib/3.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5a1176b4c6ca58ecd92dfaf35bdf9e162601c8c058365fa6a9edd5640a51f38 |
|
MD5 | 9a228570da0707f0e7d16382e81d919f |
|
BLAKE2b-256 | 089e4c4128ede544cd18385776378c54f885dc30e7b2f4d0e22b79d2110e3b3e |