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.3.0.tar.gz
.
File metadata
- Download URL: lion-0.3.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 | bc6fbaa539925ed96fbc90cbb1b1a58e3e39b0a8c9ad9d795213b0e7458c4073 |
|
MD5 | 0a29ebd83af4db2ede57994788d0c390 |
|
BLAKE2b-256 | bf32d1e2b3b648e7b4b3b5f306cd91f5374f9e1f46daf5d8cc4e7c41f3079e24 |
File details
Details for the file lion-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: lion-0.3.0-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: Python-urllib/3.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d79178a05035339eb3fb76dd8f8c1c712c5b7d2a9603b3db9ebe6ce38351411b |
|
MD5 | 55758dab3dc5ab37c021b6e40e740ec0 |
|
BLAKE2b-256 | c1bf7da31b6b8152b1c9337433bc173d9f4d1467417c8123cdc00006dbd97c26 |