/typesystem

🔢 Data validation, serialization, deserialization & form rendering.

Primary LanguagePython

TypeSystem

Build Status Coverage Package version


Documentation: https://www.encode.io/typesystem/


TypeSystem is a comprehensive data validation library that gives you:

  • Data validation.
  • Object serialization & deserialization.
  • Form rendering.
  • 100% type annotated codebase.
  • 100% test coverage.
  • Zero hard dependencies.

Requirements

Python 3.6+

Installation

$ pip3 install typesystem

If you'd like you use the form rendering you'll also want to install jinja2.

$ pip3 install jinja2

Quickstart

import typesystem

class Artist(typesystem.Schema):
    name = typesystem.String(max_length=100)

class Album(typesystem.Schema):
    title = typesystem.String(max_length=100)
    release_date = typesystem.Date()
    artist = typesystem.Nested(Artist)

album = Album.validate({
    "title": "Double Negative",
    "release_date": "2018-09-14",
    "artist": {"name": "Low"}
})

print(album)
# Album(title='Double Negative', release_date=datetime.date(2018, 9, 14), artist=Artist(name='Low'))

print(album.release_date)
# datetime.date(2018, 9, 14)

print(album['release_date'])
# '2018-09-14'

print(dict(album))
# {'title': 'Double Negative', 'release_date': '2018-09-14', 'artist': {'name': 'Low'}}

— ⭐️ —

TypeSystem is BSD licensed code. Designed & built in Brighton, England.