wiki:Notes/PythonTornado

Python Tornado

A force to be reckoned in the web world ... more than an async server, an small micro-framework in itself.

See PythonMicroFramework#Tornado.

http://www.tornadoweb.org/en/stable/

Tornado is a Python web framework and asynchronous networking library, originally developed at FriendFeed.

By using non-blocking network I/O, Tornado can scale to tens of thousands of open connections, making it ideal for long polling, WebSockets, and other applications that require a long-lived connection to each user.

https://github.com/tornadoweb/tornado/wiki

https://github.com/tornadoweb/tornado/wiki/Links

Async Client Libraries built on tornado.ioloop

http://en.wikipedia.org/wiki/Tornado_%28web_server%29

Tornado is noted for its high performance. It tries to solve the C10k problem affecting other servers.

https://pypi.python.org/pypi/tornado

Some Tornado features may require one of the following optional libraries:

unittest2 is needed to run Tornado’s test suite on Python 2.6 (it is unnecessary on more recent versions of Python)
concurrent.futures is the recommended thread pool for use with Tornado and enables the use of tornado.netutil.ThreadedResolver. It is needed only on Python 2; Python 3 includes this package in the standard library.
pycurl is used by the optional tornado.curl_httpclient. Libcurl version 7.18.2 or higher is required; version 7.21.1 or higher is recommended.
Twisted may be used with the classes in tornado.platform.twisted.
pycares is an alternative non-blocking DNS resolver that can be used when threads are not appropriate.
Monotime adds support for a monotonic clock, which improves reliability in environments where clock adjustments are frequent. No longer needed in Python 3.3.

Google Groups - https://groups.google.com/forum/#!forum/python-tornado

Books

https://github.com/Introduction-to-Tornado/Introduction-to-Tornado

Addons

Redqueue GIT Page - Redqueue is a light weight queue server that speaks memcache protocol and provides persistent queue based on log.

Mongo DB as Core Function

Tornado drivers for Mongo ...

Tornado Sample

https://github.com/bootandy/tornado_sample

Simple Tornado & Mongodb app using authentication

Motor

http://motor.readthedocs.org/en/stable/

http://motor.readthedocs.org/en/stable/requirements.html

The current version of Motor requires:

CPython 2.6, 2.7, 3.3, or 3.4. PyMongo? 2.8.0 exactly. Tornado 3.1 or later. Greenlet

Greenlets on the Mac !''

https://github.com/mongodb/motor/

https://pypi.python.org/pypi/motor/

Unix, including Mac OS X. Windows is not supported. [ bummer ]

https://blog.openshift.com/day-25-tornado-combining-tornado-mongodb-and-angularjs-to-build-an-app/

See wiki:/Notes/Linux#OpenShift

See wiki:/Notes/PythonMongoDB and wiki:/Notes/MongoDB

Integration

http://www.tornadoweb.org/en/stable/integration.html

Integration with other services

 tornado.auth — Third-party login with OpenID and OAuth
     Common protocols
     Google
     Facebook
     Twitter
     FriendFeed
 tornado.wsgi — Interoperability with other Python frameworks and servers
     Running Tornado apps on WSGI servers
     Running WSGI apps on Tornado servers
 tornado.platform.asyncio — Bridge between asyncio and Tornado
 tornado.platform.caresresolver — Asynchronous DNS Resolver using C-Ares
 tornado.platform.twisted — Bridges between Twisted and Tornado
     Twisted on Tornado
     Tornado on Twisted
     Twisted DNS resolver

Authentication And Security

http://tornado.readthedocs.org/en/latest/auth.html

http://nullege.com/codes/search/tornado.auth

http://stackoverflow.com/questions/8339506/what-are-the-possible-ways-to-authenticate-user-when-websocket-connection-is-use

http://oauth.net/

The following examples from http://tornado.readthedocs.org/en/latest/guide/security.html

Cookies And Secure Cookies

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        if not self.get_secure_cookie("mycookie"):
            self.set_secure_cookie("mycookie", "myvalue")
            self.write("Your cookie was not set yet!")
        else:
            self.write("Your cookie was set!")

User Authentication

class MainHandler(BaseHandler):
    @tornado.web.authenticated
    def get(self):
        name = tornado.escape.xhtml_escape(self.current_user)
        self.write("Hello, " + name)

settings = {
    "cookie_secret": "__TODO:_GENERATE_YOUR_OWN_RANDOM_VALUE_HERE__",
    "login_url": "/login",
}
application = tornado.web.Application([
    (r"/", MainHandler),
    (r"/login", LoginHandler),
], **settings)

Third Party Authentication

class GoogleOAuth2LoginHandler(tornado.web.RequestHandler,
                               tornado.auth.GoogleOAuth2Mixin):
    @tornado.gen.coroutine
    def get(self):
        if self.get_argument('code', False):
            user = yield self.get_authenticated_user(
                redirect_uri='http://your.site.com/auth/google',
                code=self.get_argument('code'))
            # Save the user with e.g. set_secure_cookie
        else:
            yield self.authorize_redirect(
                redirect_uri='http://your.site.com/auth/google',
                client_id=self.settings['google_oauth']['key'],
                scope=['profile', 'email'],
                response_type='code',
                extra_params={'approval_prompt': 'auto'})

Cross-Site Request Forgery Protection

settings = {
    "cookie_secret": "__TODO:_GENERATE_YOUR_OWN_RANDOM_VALUE_HERE__",
    "login_url": "/login",
    "xsrf_cookies": True,
}
application = tornado.web.Application([
    (r"/", MainHandler),
    (r"/login", LoginHandler),
], **settings)

If xsrf_cookies is set, the Tornado web application will set the _xsrf cookie for all users and reject all POST, PUT, and DELETE requests that do not contain a correct _xsrf value. If you turn this setting on, you need to instrument all forms that submit via POST to contain this field. You can do this with the special UIModule xsrf_form_html(), available in all templates:

<form action="/new_message" method="post">
  {% module xsrf_form_html() %}
  <input type="text" name="message"/>
  <input type="submit" value="Post"/>
</form>

Templates

http://tornado.readthedocs.org/en/latest/guide/templates.html

<html>
   <head>
      <title>{{ title }}</title>
   </head>
   <body>
     <ul>
       {% for item in items %}
         <li>{{ escape(item) }}</li>
       {% end %}
     </ul>
   </body>
 </html>
class MainHandler(tornado.web.RequestHandler):
    def get(self):
        items = ["Item 1", "Item 2", "Item 3"]
        self.render("template.html", title="My title", items=items)

Control statements more or less map exactly to Python statements. We support if, for, while, and try, all of which are terminated with {% end %}. We also support template inheritance using the extends and block statements, which are described in detail in the documentation for the tornado.template.

http://tornado.readthedocs.org/en/latest/template.html#module-tornado.template

Amazingly similar to PythonBottle actually, except for pre-defined widgets in ui-modules.

Plugins

https://pypi.python.org/pypi?%3Aaction=search&term=tornado&submit=search

Result of above query in text format ....

Package 	Weight* 	Description
tornado 4.0.2 	11 	Tornado is a Python web framework and asynchronous networking library, originally developed at FriendFeed.
mutornadomon 0.1.7 	9 	Library of standard monitoring hooks for the Tornado framework
pyspectator_tornado 1.1.0 	9 	pyspectator_tornado is a web-monitoring tool ported onTornado with pyspectator as a main monitoring module.
tornado-alf 0.4.1 	9 	OAuth Client For Tornado
tornado-api-kit 0.0.1 	9 	('A collection of routines for building web APIs on top of Tornado web server. ',)
tornado-botocore 0.1.5 	9 	Use tornado AsyncHTTPClient inside botocore.
tornado-exts 0.0.3 	9 	A python module that contain common definitions for Django and Tornado game project
tornado-redis-sentinel 0.1.1 	9 	Tornado redis library based in toredis that supports sentinel connections.
tornado-smtp 0.1.0 	9 	An asynchronous SMTP client for Tornado
tornado-smtpclient 0.1.4 	9 	A non-blocking smtp client to work with tornado-based application. Package changed to tornado_smtpclient
tornado_angular 0.2.1 	9 	tornado-angular is an opinionated way of distributing angular applications with tornado web server as api handler.
tornado_eventsource 0.1.3 	9 	EventSource handler for tornado
tornadoez 0.9.11 	9 	tornado improved package,currently it is experimental,with less document help.
tornadohttp 0.1.1-2 	9 	Generic Tornado Server
tornadoist 0.5.2 	9 	mixins for tornado
tornadokick 0.3.0 	9 	Web toolkit to make Tornado Web Framework-based developments a little easier.
tornadomail 0.1.2 	9 	Asynchronous email sending library for Tornado. Port of django.mail.
wtforms-tornado 0.0.2 	9 	WTForms extensions for Tornado.
tornado-pyojo 0.01 	8 	Tornado even easier!
tornado-redis 2.4.18 	8 	Asynchronous Redis client for the Tornado Web Server.
tornado-rest-handler 0.0.7 	8 	A simple Python Tornado handler that manage Rest requests automatically.
tornado-routes 0.0.2 	8 	URL routings for tornado web server
tornado-stripe 1.0.3 	8 	Tornado client library for accessing Stripe API
tornado_content_negotiation 0.2.2 	8 	Content Negotiation module for Tornado.
tornado_subprocess 0.1.5-1 	8 	A module which allows you to spawn subprocesses from a tornado web application in a non-blocking fashion.
userapp.tornado 0.3.2dev 	8 	UserApp support for Tornado.
airbrake-tornado 0.0.2 	7 	Airbrake notifier for Tornado web framework.
django-sockjs-tornado 0.0.1 	7 	Makes it easy to run a SockJS server in Django through Tornado
GitTornado 0.1.0 	7 	Tornado-based implementation of the git HTTP protocol supporting gzip and chunked transfers
greenlet_tornado 1.0.0 	7 	An easy way to seamlessly use Greenlet with Tornado
open-humans-tornado-oauth2 1.0.0 	7 	An Open Humans OAuth2 authentication provider for Tornado
sockjs-tornado 1.0.1 	7 	SockJS python server implementation on top of Tornado framework
Tornado-Backbone 0.2.2 	7 	backbone models from sqlalchemy orm for tornado-restless
tornado-bedframe 3.2.0 	7 	Tornado is a Python web framework and asynchronous networking library, originally developed at FriendFeed.
tornado-celery 0.3.4 	7 	Celery integration with Tornado
tornado-cli 0.1 	7 	A command line interface helper for Tornado
tornado-couchdb 0.2.3 	7 	Blocking and non-blocking (asynchronous) clients for CouchDB using Tornado's httpclient
tornado-encookie 0.0.1 	7 	Encrypted cookie support for the Tornado Web Framework
tornado-expects 0.1.0 	7 	Expects matchers for Tornado request and response objects
tornado-facebook-sdk 0.1.0 	7 	A tornado based facebook graph api wrapper
tornado-foursquare 0.0.3 	7 	A tornado based foursquare api wrapper
tornado-geopy 0.1.0 	7 	tornado-geopy is an asynchronous version of the awesome geopy library.
Tornado-JSON 1.0.1 	7 	A simple JSON API framework based on Tornado
Tornado-Menumaker 0.1.2 	7 	simple tornado menus
Tornado-MySQL 0.2 	7 	Pure Python MySQL Driver for Tornado
tornado-pgsql 0.5 	7 	Asynchronous PostgreSQL client for the Tornado Web Server.
tornado-pyuv 0.3.1 	7 	Tornado IOLoop implementation with pyuv
Tornado-Restless 0.4.1 	7 	flask-restless adopted for tornado
tornado-slacker 0.1 	7 	This package provides an easy API for moving the work out of the tornado process / event loop.
tornado-stub-client 0.1 	7 	Stubs out tornado AsyncHTTPClient.fetch with a nice interface, for testing code that relies on async code
tornado-torexpress 0.1.5 	7 	A RESTful extention on Tornado. Mingcai SHEN <archsh@gmail.com>
tornado-utils 1.6 	7 	Utility scripts for a Tornado site
Tornado-WeRoBot 0.2.0 	7 	Writing WeChat Robot by WeRoBot in Tornado.
tornado_circus 0.0.1 	7 	A tornado application compatible with circus socket
tornado_elasticsearch 0.2.0 	7 	Extends the official Elasticsearch Python API adding Tornado AsyncHTTPClient support
tornado_pyvows 0.5.2 	7 	tornado_pyvows are pyvows extensions to tornado web framework.
tornado_systemd 1.0.1 	7 	Use socket activation with tornado
tornado_testing 0.2.1 	7 	tornado testlayer for use with zope.testrunner
tornado_thumbor_url 0.1.1 	7 	tornado-thumbor-url is a python extension to tornado for encrypted thumbor url generation
tornado_xstatic 0.1 	7 	Utilities for using XStatic in Tornado applications
tornadoes 2.3.1 	7 	A tornado-powered python library that provides asynchronous access to elasticsearch.
TornadoPack 0.1.1 	7 	Serve a PipeStack application using Tornado
tornadorpc 0.1.1 	7 	TornadoRPC is a an implementation of both JSON-RPC and XML-RPC handlers for the Tornado framework.
tornadotools 0.2.2 	7 	A set of tools for working with tornado
aspen-tornado 0.3 	6 	tornado plugin for Aspen
botornado 0.0.3 	6 	boto on tornado - an asynchronous Amazon Web Service (AWS) client
dj-tornado 0.1.1 	6 	UNKNOWN
django-tornado 1.1.6 	6 	Django/Tornado integration made easy.
redis-tornado 0.2 	6 	Async redis client built on the Tornado IOLoop.
SimpleTornadoServer 1.0 	6 	better SimpleHTTPServer using tornado
Tornado-Babel 0.2 	6 	Babel localisation support for Torando
tornado-cors 0.4.0 	6 	UNKNOWN
tornado-jsmixin 0.2 	6 	Mixins for using commonjs libs (browserify, react, ...) features within tornado.web.Application.
tornado-logging-app 0.1 	6 	Base logging tornado app
tornado-smack 1.0.4 	6 	Syntactic sugar for tornado
tornado-smtpserver 0.0.1 	6 	A framework for SMTP servers built on Tornado's IOLoop
tornado-webservices 0.9.4.4 	6 	Tornado SOAP Web Services
tornado_data_uri 0.0.3 	6 	Tornado Data-URI Encoder Template Tag
tornado_rest 1.0 	6 	Utilitary classes used for tornado-based REST proyects.
tornado_template_gen 1.1.0 	6 	Generate static HTML files using the Tornado template module
tornado_template_server 0.0.5 	6 	Tornado Template Server for dynamically serving template data (includes data-uri uimodule)
tornado_tools 0.3.0 	6 	Classes and functions for extending Tornado
tornadocnauth 1.3 	6 	providing similar interfaces as tornado.auth for popular websites OAuth in China
tornadopush 0.5.8 	6 	Push and presence server built with Tornado and Redis
tornadotoad 0.3 	6 	Provides integration of hoptoad's exception notification service into a tornado app.
asyncdynamo 0.2.8 	5 	async Amazon DynamoDB library for Tornado
asyncgridfs 0.2.1.dev 	5 	async mongodb gridfs with tornado IOLoop
asyncmongo 1.3 	5 	Asynchronous library for accessing mongodb built upon the tornado IOLoop.
bonzo 0.1.2 	5 	Bonzo is a minimalistic SMTP Proxy built on top of Tornado.
bottle-tornado-websocket 0.13 	5 	WebSockets for bottle
bottle-tornadosocket 0.13 	5 	WebSockets for bottle
cow-framework 1.0.4 	5 	cow is a quick-start for tornado-powered applications (specially for apis).
holmesalf 0.1.3 	5 	holmes-alf is a wrapper for OAuth 2 synchronous (based on alf) and asynchronous (based on the tornado-alf) clients 
      that can bu used in holmes.
kpages 0.8.7.dev 	5 	kpages is api-centric web application framework for the Tornado and Mongodb
mingus-rest-framework 0.1 	5 	Mingus is a small and flexible restful framework on top of Tornado. It provides a simpler way to create RESTful API's.
mongotor 0.1.0 	5 	(MongoDB + Tornado) is an asynchronous driver and toolkit for working with MongoDB inside a Tornado app
mongotor-skd 0.1.5 	5 	(MongoDB + Tornado) is an asynchronous driver and toolkit for working with MongoDB inside a Tornado app
monguo 0.2.2 	5 	Asynchronous MongoDB ORM for Tornado
motor 0.3.4 	5 	Non-blocking MongoDB driver for Tornado
pycket 0.3.0 	5 	Redis/Memcached sessions for Tornado
SwampDragon 0.3.8 	5 	SwampDragon is a powerful platform making it easy to build real time web applications,
        combining the power of Django and Tornado
tapioca 0.1.28 	5 	Tapioca is a small and flexible micro-framework on top of Tornado. It provides a simpler way to create RESTful API's.
tinman 0.10.0p3 	5 	Tornado application wrapper and toolset for Tornado development
tomako 0.1.0 	5 	Tomako is the easiest way to use Mako as a template engine for Tornado
tor_access 0.2.1.dev 	5 	User role access for tornado
torgen 0.2.5 	5 	This package contains Django's CBVs adapted to use with Tornado framework.
torminify 0.1.3 	5 	Automatic css and js minification with async loading for tornadoweb
TorMySQL 0.0.5 	5 	Tornado asynchronous MySQL Driver
tornado_msgpack 0.4 	5 	ore ore MessagePack RPC
tornadohttpclient 0.3.2 	5 	Asynchronous http client.
torndown 0.0.1 	5 	(Tornado + Markdown) Markdown template generator w/opt foreign repo
torndsession 1.1.2 	5 	Session extensions for Tornado
torneira 0.3.3 	5 	Torneira is a lightweight web framework build on top of Tornado
tornfoursquare 0.0.1 	5 	Foursquare auth wrapper for Tornado Web
TornRPC 1.0.4 	5 	A tornado RPC framework
toro 0.7 	5 	Synchronization primitives for Tornado coroutines.
torsession 0.1.3 	5 	An asynchronous session backend with mongodb for tornado
trickle 0.1 	5 	IOStream wrapper for use with Tornado coroutines.
twork 2.0.0.7 	5 	twork is a Tornado Application FrameWork, it supports plug-in module injection, the module called TworkApp.
yieldpoints 0.1 	5 	Simple extensions to Tornado's gen module.
aero 0.3.6a 	4 	aero adds django-like apps support to tornado and automates common actions
authbox_tornado 0.4 	4 	UNKNOWN
BitTornado T-0.3.4 (BitTornado) 	4 	UNKNOWN
brukva 0.0.1 	4 	Asynchronous Redis client that works within the Tornado IO loop
cyclone 1.1 	4 	Non-blocking web server. A facebook's Tornado on top of Twisted.
dorothy 0.1.10 	4 	Boilerplate code for a web and/or API application written using Tornado.
netcall 0.4.2 	4 	A simple Python RPC system (ZeroMQ + Threading/Tornado/Gevent/Eventlet/Greenhouse)
TorCast 0.1.1.4 	4 	Broadcast messages to all tornado process subcribed on Redis asynchronously Or Block on Redis Queue asynchronously
tornado_conf 0.1.3 	4 	UNKNOWN
tornpsql 1.0.1 	4 	PostgreSQL handler for Tornado Web
tornwrap 0.2.6 	4 	tornado decorators and wrappers
tsunami 0.3 	4 	Web framework based tornado
abacus 0.1.1 	3 	Helper Library for Tornado Web Framework
autoreload_prime 1.0 	3 	An auto reload module that should work with most servers (patched from Tornado)
blackhole 1.8.1 	3 	Tornado powered MTA for accepting all incoming emails without any disk I/O, although no messages  
      get delivered. Mainly for testing huge send rates, for making sure developers don't accidentally send emails to real users,
      email integration testing and things like that.
chembl_beaker 0.5.34 	3 	RDKit in the Bottle on Tornado
django-fujita 0.3 	3 	A web based console for Django's development server built using Tornado
djazator 0.2.5 	3 	A simple django plugin for sending push notifications from django server to sockjs clients
dorthy 0.4.5 	3 	a micro web framework for Tornado
gale 0.0.9 	3 	Sugar for Tornado Asynchrous HTTP client
greenado 0.1.8 	3 	Greenlet-based coroutines for tornado
july 0.9.2 	3 	July Tornado: a better way to organize your tornado project
lastfmclient 0.0.4 	3 	Python client for the Last.fm API with a pythonic interface to all methods, including auth, etc.
              An async, Tornado-based client included as well.
leoproj 0.0.1 	3 	Framework under tornado, jinja2 and wtforms
maproxy 0.0.12 	3 	My first attempt to create a simple and awesome TCP proxy using Tornado
metriquet 0.2.7-1a 	3 	Metrique - Generic Tornado Server
Momoko 1.1.5 	3 	Momoko wraps Psycopg2's functionality for use in Tornado.
obelus 0.1 	3 	Protocol implementation of the Asterisk Manager Interface and Asterisk Gateway Interface
oboe 1.5.8 	3 	AppNeta TraceView Oboe libraries, instrumentation, and web middleware components for WSGI, Django, and Tornado.
OpenCoweb 1.0 	3 	Tornado-based Python server for the Open Cooperative Web Framework
pilbox 1.1.2 	3 	Pilbox is an image resizing application server built on the Tornado web framework using the Pillow Imaging Library
pseud 0.0.5 	3 	Bidirectionnal RPC Api on top of pyzmq
pyaas 0.4.3 	3 	Python-as-a-Service is a set of utilities for quickly creating Tornado applications.
pyjade 3.0.0 	3 	Jade syntax template adapter for Django, Jinja2, Mako and Tornado templates
pyrestful 0.3.2.alpha 	3 	simple and useful Restful API for Tornado Web Server
pyrocumulus 0.4.5 	3 	Glue-code to make (even more!) easy and fun work with mongoengine and tornado
rainfall 0.8.3 	3 	Micro web framework around asyncio (ex tulip)
ramen 0.0.2 	3 	Tornado based simple web framework
rdlm 0.4.2 	3 	RDLM (Restful Distributed Lock Manager) is a lock manager over HTTP build on Tornado
SocketTornad.IO 0.1.3 	3 	Python implementation of the Socket.IO protocol for the Tornado webserver/framework.
sockjsroom 0.0.3 	3 	Sockjs-tornado multi room system
solr 0.4 	3 	Client library for working with Solr. Includes async client version for Tornado.
sparts 0.7.1 	3 	Build services in python with as little code as possible
terminado 0.3.1 	3 	Terminals served to term.js using Tornado websockets
thunderpush 0.9.7 	3 	Tornado and SockJS based, complete Web push solution.
TMiddleware 0.0.1 	3 	tornado middleware
toradbapi 0.1.3 	3 	Wrapper for twisted.enterprise.adbapi.ConnectionPool to use with tornado
tord 0.4.0 	3 	Asynchronous Websocket + Pubsub based web framework built over Tornado, Redis, ZMQ, SockJS
tordjango 0.1 	3 	Simple management command to serve Django via Tornado
toredis-fork 0.1.4 	3 	Really simple async Redis client for Tornado
torext 0.9.4-r5 	3 	The missing tornado mate
TornadIO 0.0.5 	3 	Socket.io server implementation on top of Tornado framework
TornadIO2 0.0.4 	3 	Socket.io 0.7+ server implementation on top of Tornado framework
TornadIO2Go 1.0.3 	3 	Seamlessly run your Django and TornadIO2 project inside Tornado. Like.A.Boss.
tornform 0.1 	3 	# tornform is a form-wrapper with voluptuous for tornado
torque 0.4.5 	3 	A web hook task queue based on tornado and redis
torthrift 0.0.3 	3 	Thrift Tornado server
tortik 0.1.10 	3 	Tortik - python tornado framework
trequests 0.9.5 	3 	A Tornado async HTTP/HTTPS client adaptor for python-requests
twqq 0.2.12 	3 	An asynchronous webqq client library based on tornado
vortex 0.0.5 	3 	An experimental resource-based web framework built on Tornado's IOLoop
webargs 0.8.1 	3 	A utility library for parsing HTTP request arguments, with built-in support for popular web frameworks,
        including Flask and Django.
webtail 0.1b16 	3 	Tornado-based log viewer

Also See

Search wiki for 'tornado'

Last modified 3 years ago Last modified on 04/15/2015 02:45:15 PM