Skip to main content

backbone models from sqlalchemy orm for tornado-restless

Project description


Create backbone models from sqlalchemy models.

Backbone allows to represent your data as models in JavaScript.
However you may not want to do your modeling twice in sqlalchemy aswell in backbone.
Tornado-Backbone approaches to generate the JavaScript models from your sqlalchemy orm.

It's main intention is to work with tornado-restless (and is compatible with flask-restless as api backend),
so there are some specific 'hacks' for them.

Development Status

The implementation is currently still a bleeding edge without many documentation,
but I hope to provide a meaningful documentation soon.


Tornado Backbone uses require.js for his depencies and for loading required models.

The shim we use in production looks like:

baseUrl: '/static/',
paths: {
underscore: "{{ handler.request.protocol }}://",
backbone: "{{ handler.request.protocol }}://",
"backbone-forms": "{{ handler.request.protocol }}://",
"backbone-relational": "{{ handler.request.protocol }}://"
shim: {
underscore: {
exports: '_'
backbone: {
deps: ["underscore", "jquery"],
exports: "Backbone"
"backbone-forms": {
deps: ["backbone"]
"backbone-relational": {
deps: ["backbone"]


A version of Backbone-Forms is included in the distribution folder, a copy of it can be
obtained from . Note that you must include the list
editor as soon as you use relationship properties.

If you want to have support for backbone-forms include the `form.js`.
Tornado Backbone exposes all information of the `info` dict as schema attribute in the backbone model
and falls back on some defaults if there is no information (like for integer).
For interaction with backbone-forms you can define for example your column like:

class User(Base):
email = Column(String, info={'type': 'Text', 'dataType': 'email', 'validators': ['email']})

And then create a form like:

require(['/api/js/user'], function () {
var user = new UserModel();

var form = new Backbone.Form({
model: user

Or directly use a bootstrap similiar approach:

<form data-require="/api/js/user" data-model="UserModel">
<legend>User Form</legend>

<!-- Form content will be injecked here, any existing content is preserved -->
<div data-fields="email"></div>

All options for Backbone.Form can be passed as data-\* attributes.
If you have relations in your model that you want to use, it may require to load the depencies:

class UserTitle(Base):
id: Column(Integer)
title: Column(String)

class User(Base):
title_id = Column(ForeignId(
title = relationship(UserTitle)
email = Column(String, info={'type': 'Text', 'dataType': 'email', 'validators': ['email']})

Leads to displaying a form with email and title:

<form data-require="/api/js/user_title /api/js/user" data-model="UserModel">
<legend>User Form</legend>

<div data-fields="title"></div> <!-- Select Box with Title -->
<div data-fields="email"></div> <!-- Text Box with Validator for email -->


Tornado Backbone exposes relations in a backbone-relations compatible way.
If you include `relations.js` in your project all models will be based on Backbone.RelationalModel

Copyright license

tornado-backbone is licensed under the GNU Affero General Public License, for more information see the LICENSE.txt.


tornado-backbone was developed under python3.3, sqlalchemy0.9 and tornado3.1

It may work with sqlalchemy 0.8 and older tornado releases but I did not test it at all.

To install this libary as an egg use:

python install

Project details

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page