Skip to main content

Gata is data validation and transformation library for python

Project description

Gata

CI Coverage Maintainability License: MIT

Gata is a toolbox library for python's dataclasses which allows to serialise/deserialise/validate complex dataclasses.

Installation

pip install gata

Features

  • non-intrusive interface
  • dataclasses validation mechanism
  • support for complex datatypes
  • serialisation/deserialisation mechanism
  • easy to use field mapping
  • Full IDE support with Dataclass class

Example

from typing import List
from gata import Dataclass


class Pet(Dataclass, frozen=True):
    tags: List[str]
    name: str = "Boo"
    age: int = 0


try:
    pet = Pet()
except ValueError:
    pass  # tags are required and undefined, so error will be thrown


pet = Pet(**{"tags": ["dog"]})

assert pet.serialise() == {'tags': ['dog'], 'name': 'Boo', 'age': 0}  # serialise object

# exclude `age` field from serialisation, and rename `name` field to `pet_name`
assert pet.serialise(age=False, name="pet_name") == {'tags': ['dog'], 'pet_name': 'Boo'}

Non intrusive example

from typing import List
from gata import validate_dataclass, asdict
from dataclasses import dataclass


@dataclass
class Pet:
    tags: List[str]
    name: str = "Boo"
    age: int = 0


try:
    pet = Pet()
    validate_dataclass(pet)
except ValueError:
    pass  # tags are required and undefined, so error will be thrown


pet = Pet(**{"tags": ["dog"]})

assert asdict(pet) == {'tags': ['dog'], 'name': 'Boo', 'age': 0}  # serialise object

# exclude `age` field from serialisation, and rename `name` field to `pet_name`
assert asdict(pet, {"age": False, "name": "pet_name"}) == {'tags': ['dog'], 'pet_name': 'Boo'}

More examples are available under examples directory

Documentation

Introduction

Defining dataclass

Field types

Validation

Deserialisation

Serialisation

Detailed schema

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for gata, version 3.3.2
Filename, size File type Python version Upload date Hashes
Filename, size gata-3.3.2-py3-none-any.whl (20.7 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size gata-3.3.2.tar.gz (18.1 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page