Schematics

Structured Data for Humans
Download

Schematics Ranking & Summary

Advertisement

  • Rating:
  • License:
  • BSD License
  • Price:
  • FREE
  • Publisher Name:
  • James Dennis
  • Publisher web site:
  • http://j2labs.net

Schematics Tags


Schematics Description

Schematics is a Python module that provides an easy way to model data. It provides mechanisms for structuring data, initializing data, serializing data, formatting data and validating data against type definitions, like an email address.The library provides data types, in the form of fields. Each field controls the details of how its data should look in various formats. It also provides a validate() function which is responsible for determining if the data looks correct.Schematics' main goal is to provide similar functionality to a type system along with a way to generate the schematics we send to the Internet, or store in a database, or send to some Java process, or basically any use case with structured data.A blog model might look like this:from schematics.models import Documentfrom schematics.types import StringTypeclass BlogPost(Model): title = StringType(max_length=40) body = StringType(max_length=4096)Schematics objects serialize to JSON by default. Store them in Memcached, MongoDB, Riak, whatever you need.>>> from schematics.models import Document>>> from schematics.types import StringField>>> class Comment(Model):... name = StringType(max_length=10)... body = StringType(max_length=4000)...>>> data = {'name':'a hacker', 'body':'schematics makes validation easy'}>>> Comment(**data).validate()TrueLet's see what happens if we try using invalid data.>>> data = 'a hacker with a name that is too long'>>> Comment(**data).validate()Traceback (most recent call last): File "< stdin >", line 1, in < module > File "/path/to/site-packages/schematics/models.py", line 280, in validate field._validate(value) File "/path/to/site-packages/schematics/fields/base.py", line 99, in _validate self.validate(value) File "/path/to/site-packages/schematics/fields/base.py", line 224, in validate self.field_name, value)schematics.base.TypeException: String value is too long - name:a hacker with a name who is too longCombining schematics with JSON coming from a web request is quite natural as well. Say we have some data coming in from an iPhone:json_data = request.post.get('data')data = json.loads(json_data)Validating the data then looks like this: Comment(**data).validate().Easy.Product's homepage


Schematics Related Software