Tornado Auth Sessions
Simple, secure Redis-backed session mixin for Tornado.
Installation
pip install tornado-auth-sessions
Setup
Configure Redis via Tornado application settings:
import tornado.web
app = tornado.web.Application(
handlers,
redis_host={
"host": "localhost",
"port": 6379,
"db": 0,
"password": None,
"decode_responses": True,
},
cookie_secret="YOUR_SECRET_KEY",
)
Usage
Create a base handler:
import tornado
from tornado_auth_sessions import TornadoSessionsMixin
class BaseHandler(
TornadoSessionsMixin,
tornado.web.RequestHandler,
):
pass
Example
Login
class LoginHandler(BaseHandler):
def post(self):
# authenticate user...
self.set_session(user.id)
self.redirect("/dashboard")
Protected route
class DashboardHandler(BaseHandler):
def get(self):
user_id = self.get_session()
if not user_id:
self.redirect("/login")
return
self.write(f"Welcome user {user_id}")
Logout
class LogoutHandler(BaseHandler):
def post(self):
self.remove_session(user.id)
self.redirect("/")
Authentication (Tornado Native)
This library integrates seamlessly with Tornado’s built-in authentication system via get_current_user.
Add this to your base handler:
def get_current_user(self):
return self.get_session()
Authentication (Tornado Native)
This library integrates seamlessly with Tornado’s built-in authentication system via get_current_user.
Add this to your base handler:
import tornado
class DashboardHandler(BaseHandler):
@tornado.web.authenticated
def get(self):
user_id = self.current_user
self.write(f"User: {user_id}")
def get_current_user(self):
return self.get_session()
---
## Security notes
- Uses Tornado set_secure_cookie (signed, tamper-proof)
- Always use HTTPS in production
- Set secure=True for cookies
- Use strong cookie_secret
- Pair with CSRF protection for forms
Metadata
Release files for tornado-auth-sessions 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| tornado_auth_sessions-0.0.3.tar.gz | 3.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tornado_auth_sessions-0.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.9 kB
Release files / tornado_auth_sessions-0.0.3.tar.gz
| Download URL | tornado_auth_sessions-0.0.3.tar.gz |
|---|---|
| Size | 3.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0718021a21541c0069b62e644c7f93cd3aa942148b4a2864e2c0fc1bcec47a75
|
|
BLAKE2b-256 checksum How to use checksums |
62de7531944c2f456347bc0b5eb9d8156669e1966b401f2542f1c26ed08ad610
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.13.5 Darwin/25.2.0
|
Release files / tornado_auth_sessions-0.0.3-py3-none-any.whl
| Download URL | tornado_auth_sessions-0.0.3-py3-none-any.whl |
|---|---|
| Size | 4.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9b8f547668f3ea97e16badccacff145054eb5ed99b09a8e621fe62cef104a4f1
|
|
BLAKE2b-256 checksum How to use checksums |
f72cf8f33ce4291177c6303eba1b1bc1efa2d50ce58884d53a44aacdac3b4d87
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.13.5 Darwin/25.2.0
|