Skip to content
Data validation, serialization, deserialization & form rendering. πŸ”’
Python HTML Shell
Branch: master
Clone or download

Latest commit

polyrand update alternatives (#100)
Also mentioned in #34.
Latest commit 2b93b4a Apr 7, 2020

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs Document strict validation (#81) Jul 1, 2019
examples Docs, examples, template tweaks Mar 5, 2019
scripts Type annotations Feb 28, 2019
tests Array serialization (#77) Jul 1, 2019
typesystem Version 0.2.4 Jul 1, 2019
.codecov.yml Add codecov config Feb 27, 2019
.gitignore Progress Feb 22, 2019
.travis.yml Version 0.2.3 (#82) Jun 21, 2019
LICENSE.md Update LICENSE.md Mar 8, 2019
README.md update alternatives (#100) Apr 7, 2020
mkdocs.yml
requirements.txt Positional error messages Mar 6, 2019
setup.py Include form templates into package (#99) Apr 1, 2020

README.md

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.
  • Marshaling validators to/from JSON schema.
  • Tokenizing JSON or YAML to provide positional error messages.
  • 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

If you'd like you use the YAML tokenization you'll also want to install pyyaml.

$ pip3 install pyyaml

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.Reference(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'}}

Alternatives

There are plenty of other great validation libraries for Python out there, including Marshmallow, Schematics, Voluptuous, Pydantic and many others.

TypeSystem exists because I want a data validation library that offers first-class support for:

  • Rendering validation classes into HTML forms.
  • Marshaling to/from JSON Schema.
  • Obtaining positional errors within JSON or YAML documents.

β€” β­?οΈ? β€”

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

You can’t perform that action at this time.