The py-jsonapi extension for flask. Binding the API to a flask application is dead simple:

import flask
import jsonapi
import jsonapi.flask

app = flask.Flask(__name__)
api = jsonapi.flask.FlaskAPI("/api", db=..., flask_app=app)

# You can also initialize the API with the flask application using the
# *init_app()* method:

You can add the models to the API as usual. They will be available under /api.


You can access the current APi via the extensions dictionary of the flask application:


or you use the global variable current_api:

from jsonapi.flask import current_api

The API instance is also added to the jinja environment:

    You can download your profile
    <a href="{{ jsonapi.reverse_url('User', 'resource', id=current_user.id) }}">


class jsonapi.flask.FlaskAPI(uri, db, settings=None, flask_app=None)[source]

Bases: jsonapi.base.api.API

Implements the API for flask. You can provide the flask application later via init_app().


This is a proxy for the flask_app debug attribute. This means, that you must enable the debug mode on the flask application.


The flask application, this API is registered on.


Registers this API on the flask application app.

Parameters:app (flask.Flask) –

Handles a request to the API.

jsonapi.flask.current_api = <LocalProxy unbound>

Acts as a proxy for a werkzeug local. Forwards all operations to a proxied object. The only operations not supported for forwarding are right handed operands and any kind of assignment.

Example usage:

from werkzeug.local import Local
l = Local()

# these are proxies
request = l('request')
user = l('user')

from werkzeug.local import LocalStack
_response_local = LocalStack()

# this is a proxy
response = _response_local()

Whenever something is bound to l.user / l.request the proxy objects will forward all operations. If no object is bound a RuntimeError will be raised.

To create proxies to Local or LocalStack objects, call the object as shown above. If you want to have a proxy to an object looked up by a function, you can (as of Werkzeug 0.6.1) pass a function to the LocalProxy constructor:

session = LocalProxy(lambda: get_current_request().session)

Changed in version 0.6.1: The class can be instantiated with a callable as well now.