The tool for creating notes
Project description
Simple and beautiful library for data formatting/convert/serialize
pip install reformer
Why
There are many great python libraries for validation, serialization and data formatting search as marshmallow, DRF etc. Usually they base on data validation.
Otherwise reformer design only for data formatting, and in a schema you need to define type of transformation and data source.
How to use
To define schema you need to create Reformer base class:
from reformer import Reformer, Field, MapField, MethodField class Schema(Reformer): _fields_ = ('name', 'surname') fullname = Field('name').replace('_', '-') + ' ' + Field('surname') admin = Field('username').at(['admin', 'root']) welcome = MapField('username', { 'admin': 'Hi bro', 'root': 'God?' }) posts_titles = Field('posts').iter(['title']) status = ('http://api.com/get_user_status/' + Field('id', to=str)).handle(requests.get) target = { 'id': 353, 'name': 'John', 'surname': 'Black', 'username': 'admin', 'posts': [ {'title': 'New', 'id': 10}, {'title': 'My first post', 'id': 11}, ] } print(Schema.transform(target)) # OrderedDict([ # ('name', 'John'), # ('surname', 'Black'), # ('fullname', 'John Black'), # ('admin', True), # ('welcome', 'Hi bro'), # ('posts_titles', ['New', 'My first post']), # ('status', 'INIT'), # ])
FUTURE
errors
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
reformer-0.1.3.tar.gz
(4.4 kB
view details)
Built Distribution
File details
Details for the file reformer-0.1.3.tar.gz
.
File metadata
- Download URL: reformer-0.1.3.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.11.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.5.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c844e31355ca005fd945f8e3d69896a1ce8690e9b0b26c554156cf2e2bab801a |
|
MD5 | c1333cabe7646a36ccbb003041ed9ae8 |
|
BLAKE2b-256 | 747610d1e95186ffc6a77db09ceba0f237623f3aad6452a7058d224de47cb016 |
File details
Details for the file reformer-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: reformer-0.1.3-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.11.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.5.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c2e21768c30d4f9f20b1ddb6242803cd3557c5122847714bfdfad3642afea6c |
|
MD5 | bf0d8b3eddc19990c9593572ff056c2e |
|
BLAKE2b-256 | 0fa551e22a24f48550c1b977cbc755261094dc42c090f294d023d5542feed83c |