jsonapi.motorengine

This package contains the database adapter and schema for motorengine documents. It will detect and add motorengine fields to the jsonapi schema automatic.

motorengine is an asynchronous database driver for mongodb and requires therefore an asynchronous web framework like tornado.

Using motorengine models with py-jsonapi is quite straightforward:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python3

import motorengine

import jsonapi
import jsonapi.motorengine
import jsonapi.tornado

class User(motorengine.Document):

    name = motorengine.StringField()
    email = motorengine.EmailField()
    posts = motorengine.ListField(motorengine.ReferenceField("__main__.Post"))

class Post(motorengine.Document):

    text = motorengine.StringField()
    author = motorengine.ReferenceField(User)

# Use the motorengine schema for the models.
user_schema = jsonapi.motorengine.Schema(User)
post_schema = jsonapi.motorengine.Schema(Post)

# Create the motorengine database adapter.
db = jsonapi.motorengine.Database()

# Create the API
api = jsonapi.tornado.TornadoAPI("/api", db)
api.add_type(user_schema)
api.add_type(post_schema)

API

class jsonapi.motorengine.schema.Schema(resource_class, typename=None)[source]

Bases: jsonapi.base.schema.Schema

This Schema subclass also finds motorengine attributes and relationships.

Parameters:
  • resource_class – The motorengine document (class)
  • typename (str) – The typename of the resources in the JSONapi. If not given, it is derived from the resource class.
find_motorengine_markers()[source]

Finds all motorengine attributes and relationships.

class jsonapi.motorengine.database.Database(api=None)[source]

Bases: jsonapi.base.database.Database

This adapter must be chosen for motorengine models. We assume that the database connection has been created with motorengine.connect().

This adapter only works with asynchronous apis.

session()[source]