Simple way to cast your data.
Project description
Datacast is a Python package that validates and converts your data.
Basic Usage
Install with pip:
pip install datacast
Define schema (can be any class with annotations) and use cast function.
from datacast import cast
class SimpleSchema:
zero: bool
one: int
two: str
three: float = 0.3
four: None = 'four'
cast({'zero': 0, 'one': 1, 'two': 2, 'four': 5}, SimpleSchema)
# {'zero': False, 'one': 1, 'two': '2', 'three': 0.3, 'four': 5}
Rules are simple:
Annotation is a caster, which will be called with the provided value, eg. bool(0).
If no default value is provided, the RequiredFieldError will be raised.
None in annotation means no casting.
Settings
To be added.
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
datacast-0.2.1.tar.gz
(5.5 kB
view hashes)