Tornado web server with Tryton

I am running a tornado webserver. Also, I have a flask-based an “API”-like web app.
I want to switch from flask to the tornado as well.
Tornado — is the same as Django but much faster, simpler, and more straightforward.
So I have:

# __init__.py
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
from tornado.options import define, options
from tornado.web import Application
from my_api.views import APIendpoint  ## here are my views.py 
import os

########### WEB SERVER INITIALIZATION #############
define('port', default=8888, help='port to listen on')

PATH = os.path.dirname(os.path.realpath(__file__))

settings = {'debug': True, 
            'static_path': os.path.join(PATH, 'static')}

## here I set the routes — what classes will be called 
handlers = [
        # ('/', HelloWorld),
        (r'/api/v2/(.*)', APIendpoit),
    ]

engine = ?????? # here I am looking for a DB engine from Tryton

class Config(object):
    DEBUG = False
    TESTING = False
    CSRF_ENABLED = True
    TRYTON_DATABASE = 'my_tryton_database' # Data base I use in Tryton
    SECRET_KEY = '<TOP SECRET KEY>'
    DATABASE_URI = os.environ['DATABASE_URL'] # postgres driver


################ Start Server ###############
def main():
    """Construct and serve the tornado application."""

    app = Application(handlers=handlers,
                        session_factory=engine,
                        **settings)

    http_server = HTTPServer(app)
    http_server.listen(options.port)
    logger.info('Now listening on http://localhost:%i' % options.port)
    IOLoop.current().start()

I cannot understand what I need to pass to views.py to have an access to all features of Tryton. In Flask I simply used the flask_tryton module:
my_beloved_tryton = Tryton(app, **somekwargs)
and happily could do almost anything I want.
But not here. I cannot understand how to get access to all these my model classes with all methods in them from the tornado server.

views.py consists of classes that respond to web requests but what I need to import to have the total access to DB like in SQLAlchemy?

I decided to switch to proteus client as a way to get access to DB and models.

You need to implement something similar to flask_tryton but for tornado.

proteus less performant than a direct access like flask_tryton because:

  • proteus read always all the fields
  • each request is a new transaction
  • if used with XML-RPC it has to do the login for each request

Thank you for clarifying about Proteus limitations. Understand.

You need to implement something similar to flask_tryton but for Tornado.

Good point. I think I will try to do that. Hope, it would help others.
If you aware of any attempts for Django? I searched a little but to no avail.

Created a tornado-tryton connector:

1 Like

Wow, nice work!

We have a deciated category for third-party plugins it will be great if you can include your tornado connector there.

I’ve already given the required permissions to post there so you should be able to write there without any issues. Feel free to DM me if you have any doubt or problems.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.