SQLAlchemy helpers for working in Tornado
Project description
Python helpers for using SQLAlchemy with Tornado.
Installation
$ pip install tornado-sqlalchemy
Usage
from tornado.gen import coroutine
from tornado.web import Application, RequestHandler
from tornado_sqlalchemy import as_future, make_session_factory, SessionMixin
class NativeCoroutinesRequestHandler(SessionMixin, RequestHandler):
async def get(self):
with self.make_session() as session:
count = await as_future(session.query(UserModel).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(UserModel).count)
self.write('{} users so far!'.format(count))
class SynchronousRequestHandler(SessionMixin, RequestHandler):
def get(self):
with self.make_session() as session:
count = session.query(UserModel).count()
self.write('{} users so far!'.format(count))
handlers = (
(r'/native-coroutines', NativeCoroutinesRequestHandler),
(r'/gen-coroutines', GenCoroutinesRequestHandler),
(r'/sync', SynchronousRequestHandler),
)
app = Application(
handlers,
session_factory=make_session_factory('postgres://user:password@host/database')
)
Documentation
Documentation is available at Read The Docs.
Development
To work on this package, please make sure you have Python 3.5+ and pipenv installed.
Git clone the repository -
git clone https://github.com/siddhantgoel/tornado-sqlalchemy
Install the packages required for development -
pipenv install --dev
That’s basically it. You should now be able to run the test suite -
py.test tests/
.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for tornado_sqlalchemy-0.5.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e781d8eeb044151f970eb70ab8eb09b215c1fc2b416abcdc32f4cdb6f4b4b692 |
|
MD5 | cc434a5dc520059321592b7a4316ea9e |
|
BLAKE2b-256 | 21fa8389ba4c5a090f4a9aa4e9f207d20b91ef3f4c2d3392df5dedfa9b2629e1 |