๐Ÿ“ฆ encode / typesystem

Data validation, serialization, deserialization & form rendering. ๐Ÿ”ข

โ˜… 540 stars โ‘‚ 42 forks ๐Ÿ‘ 540 watching โš–๏ธ BSD 3-Clause "New" or "Revised" License
deserializationformshtmlpythonserializationvalidation
๐Ÿ“ฅ Clone https://github.com/encode/typesystem.git
HTTPS git clone https://github.com/encode/typesystem.git
SSH git clone git@github.com:encode/typesystem.git
CLI gh repo clone encode/typesystem
Ethon Ethon Update README (#125) 7decd48 3 years ago ๐Ÿ“ History
๐Ÿ“‚ master View all commits โ†’
๐Ÿ“ .github
๐Ÿ“ docs
๐Ÿ“ examples
๐Ÿ“ scripts
๐Ÿ“ tests
๐Ÿ“ typesystem
๐Ÿ“„ .codecov.yml
๐Ÿ“„ .gitignore
๐Ÿ“„ LICENSE.md
๐Ÿ“„ mkdocs.yml
๐Ÿ“„ README.md
๐Ÿ“„ requirements.txt
๐Ÿ“„ setup.cfg
๐Ÿ“„ setup.py
๐Ÿ“„ 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 using jinja2:

$ pip3 install typesystem[jinja2]

If you'd like you use the YAML tokenization using pyyaml:

$ pip3 install typesystem[pyyaml]

Quickstart

import typesystem

artist_schema = typesystem.Schema(
    fields={
        "name": typesystem.String(max_length=100)
    }
)

definitions = typesystem.Definitions()
definitions["Artist"] = artist_schema

album_schema = typesystem.Schema(
    fields={
        "title": typesystem.String(max_length=100),
        "release_date": typesystem.Date(),
        "artist": typesystem.Reference("Artist", definitions=definitions)
    }
)

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

print(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.