A small library aimed to help cleaning input json data, and allowing a more centered source of truth.
Project description
model_transformer
A small library aimed to help cleaning input json data, and allowing a more centered source of truth.
Installation
pip install model-transformer
Usage
This basic sample will show how to extract field name
from input data, and how to create a calculated field age
also from input data.
from datetime import datetime
from model_transformer import Transformer, Field
class SampleTransformer(Transformer):
name = Field("name") # This field will extract name from input data.
def get_age(self, row: dict) -> int:
birth = datetime.fromisoformat(row.get("birth"))
diff = datetime.now() - birth
return diff.days // 365
data = [
{
"name": "John Doe",
"birth": "1998-05-01T00:00:00",
"email": "john@company.com",
}
]
transformer = SampleTransformer()
transformer.transform(data)
#... [
#... {
#... "name": "John Doe",
#... "age": 25
#... }
#... ]
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
Close
Hashes for model_transformer-0.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8239c800326f94d03381ade569746ac746594c759ab7cfa45ac7d91407b63a76 |
|
MD5 | 4c03ede7d383cacbe3b201b7fabf8250 |
|
BLAKE2b-256 | 9a7a942b797bf0d78a4bd38c91ddcad50513e4c9a027b6ac0a00afbb2b236c81 |