from teleport import t, Undefined
TODO = t({"Struct": {
"required": {"text": "String"},
"optional": {"deadline": "DateTime",
"tags": {"Array": "String"}}}})
>>> TODO.from_json({
... 'text': 'Return videotapes',
... 'deadline': '2014-10-14T21:17:00Z',
... 'tags': ['movies']
... })
{'deadline': datetime.datetime(2014, 10, 14, 21, 17, tzinfo=<UTC>),
'tags': [u'movies'],
'text': u'Return videotapes'}
def add_todo(request):
try:
todo = TODO.from_json(request.json)
except Undefined:
raise BadRequest("Invalid JSON data")
Todo.create(**todo)
def add_todo(**todo):
payload = json.dumps(TODO.to_json(todo))
requests.post('http://api.example.com/todos', data=payload)
Teleport is a tiny JSON type system. You can use it for:
Principles:
Source code, specification as well as this site are all in a single git repository.
Use the issue tracker to report bugs and offer suggestions. Join the discussion or email the author directly.
Teleport is very new and needs all kinds of help: from reviewing the specification, to suggesting features, to porting it to new programming languages.