Skip to main content

Simple way to cast your data.

Project description

Datacast is a Python package that validates and converts your data.


Latest version released on PyPI Test coverage Package license


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.1.0.tar.gz (5.5 kB view hashes)

Uploaded Source

Built Distribution

datacast-0.1.0-py3-none-any.whl (7.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page