Need help with tornado-sqlalchemy?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

siddhantgoel
113 Stars 21 Forks MIT License 316 Commits 3 Opened issues

Description

SQLAlchemy support for Tornado

Services available

!
?

Need anything else?

Contributors list

# 96,576
unix
npm
entrepr...
bootstr...
190 commits
# 2,435
civic-t...
Qt
python-...
prose
63 commits
# 235,974
HTML
Shell
explora...
eda
3 commits
# 360,497
keyboar...
HTML
angular...
phodal
1 commit
# 740,448
Python
sqlalch...
tornado
1 commit
# 607,481
Python
sqlalch...
tornado
1 commit

tornado-sqlalchemy

.. image:: https://travis-ci.org/siddhantgoel/tornado-sqlalchemy.svg?branch=stable :target: https://travis-ci.org/siddhantgoel/tornado-sqlalchemy

.. image:: https://badge.fury.io/py/tornado-sqlalchemy.svg :target: https://pypi.python.org/pypi/tornado-sqlalchemy

.. image:: https://readthedocs.org/projects/tornado-sqlalchemy/badge/?version=latest :target: https://tornado-sqlalchemy.readthedocs.io/en/latest/

.. image:: https://img.shields.io/pypi/pyversions/tornado-sqlalchemy.svg :target: https://pypi.python.org/pypi/tornado-sqlalchemy

Python helpers for using SQLAlchemy_ with Tornado_.

Installation

.. code-block:: bash

$ pip install tornado-sqlalchemy

In case you prefer installing from the Github repository, please note that :code:

master
is the development branch so :code:
stable
is what you should be installing from.

Usage

.. code-block:: python

from tornado.gen import coroutine
from tornado.web import Application, RequestHandler
from tornado_sqlalchemy import as_future, SessionMixin, SQLAlchemy

class NativeCoroutinesRequestHandler(SessionMixin, RequestHandler): async def get(self): with self.make_session() as session: count = await as_future(session.query(User).count)

    self.write('{} users so far!'.format(count))

class GenCoroutinesRequestHandler(SessionMixin, RequestHandler): @coroutine def get(self): with self.make_session() as session: count = yield as_future(session.query(User).count)

    self.write('{} users so far!'.format(count))

class SynchronousRequestHandler(SessionMixin, RequestHandler): def get(self): with self.make_session() as session: count = session.query(User).count()

    self.write('{} users so far!'.format(count))

handlers = ( (r'/native-coroutines', NativeCoroutinesRequestHandler), (r'/gen-coroutines', GenCoroutinesRequestHandler), (r'/sync', SynchronousRequestHandler), )

app = Application( handlers, db=SQLAlchemy('postgres://user:[email protected]/database') )

Documentation

Documentation is available at

Read The Docs
_.

Development

Please make sure you have Python 3.5+ and Poetry_ installed.

Since we run tests against multiple databases (currently MySQL, PostgreSQL, and SQLite), we use

docker-compose
_ to make our lives easier.
  1. Git clone the repository - :code:

    git clone https://github.com/siddhantgoel/tornado-sqlalchemy
  2. Install the packages required for development - :code:

    poetry install
  3. Ensure that the MySQL and PostgreSQL services (containers) are up - :code:

    docker-compose up -d
  4. That should basically be it. You should now be able to run the test suite - :code:

    poetry run py.test tests/
    .

.. _docker-compose: https://docs.docker.com/compose/ .. _Poetry: https://poetry.eustace.io/ .. _Read The Docs: https://tornado-sqlalchemy.readthedocs.io/en/stable/ .. _SQLAlchemy: http://www.sqlalchemy.org/ .. _tornado: https://www.tornadoweb.org/en/stable/

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.