Tinman
Tinman is a Tornado support package including an application wrapper/runner and a set of handy decorators.
Install / Use
/learn @gmr/TinmanREADME
Tinman
Tinman adds a little more stack to Tornado. It is designed to speed development of Tornado applications. It includes an application wrapper and a toolbox of decorators and utilities.
0.9+ Version Warning
The configuration file syntax has changed and the structure of the package has changed. Please test your applications if you are upgrading from 0.4 or previous.
Features
- A full featured application wrapper
- Standard configuration for applications
- Built-in configurable session management
- Lightweight model system for NoSQL systems
- Authentication Mixins for Github and StackExchange
- A command-line tool, tinman-init that will create a skeleton app structure with the initial package and setup.py file.
- Network address whitelisting decorator
- Method/Function debug logging decorator
- Handlers with automated connection setup for PostgreSQL, RabbitMQ and Redis
- Support for a External Template Loaders including Tinman's CouchDB Template Loader
- Flexible logging configuration allowing for custom formatters, filters handlers and setting logging levels for individual packages.
- Built in support for NewRelic's Python agent library
- RequestHandler output caching/memoization
Installation
Install via pip or easy_install:
pip install tinman
Module Descriptions
- tinman
- application: Application extends tornado.web.Application, handling the auto-loading of configuration for routes, logging, translations, etc.
- auth: Authentication Mixins for GitHub, StackExchange, and HTTP Digest Authentication.
- controller: Core tinman application controller.
- couchdb: A CouchDB based template loader module
- decorators: Authentication, memoization and whitelisting decorators.
- exceptions: Tinman specific exceptions
- handlers: Request handlers which may be used as the base handler or mix-ins.
- base: Base request handlers including the SessionRequestHandler
- mixins: Request Handlers mixins including support for Redis, RabbitMQ and Model API Request Handlers
- model: Model system with base model class and various base model classes for supported storage backends.
- process: Invoked by the controller, each Tinman process is tied to a specific HTTP server port.
- session: Session object and storage mixins
- utilities: Command line utilities
Requirements
- helper
- ipaddr
- pyyaml
Optional Dependencies
- Heapy: guppy,
- LDAP: python-ldap,
- MsgPack Sessions: msgpack,
- NewRelic: newrelic>=1.12.0',
- PostgreSQL: psycopg2,
- RabbitMQ: pika>=0.9.13,
- Redis: tornado-redis,
- Redis Sessions: redis
Installing optional Dependencies
Use pip to install dependencies:
pip install 'tinman[Dependency Name]'
For example:
pip install 'tinman[RabbitMQ]'
Application Runner
The tinman application runner works off a YAML configuration file format and provides a convenient interface for running tornado applications interactively or as a daemon.
Command Line Syntax:
Usage: usage: tinman -c <configfile> [options]
Tinman adds a little more stack to Tornado
Options:
-h, --help show this help message and exit
-c CONFIGURATION, --config=CONFIGURATION
Path to the configuration file
-f, --foreground Run interactively in console
-p PATH, --path=PATH Path to prepend to the Python system path
Example Handlers
Session
Sessions will automatically load on prepare and save on finish. If you extend the SessionHandler and need to use prepare or finish, make sure to call super(YourClass, self).prepare() and super(YourClass, self).on_finish() in your extended methods. By using the session mixins you can change the default session behavior to use different types of storage backends and serializers.
from tinman.handlers import session
from tornado import web
class Handler(session.SessionHandler):
@web.asynchronous
def get(self, *args, **kwargs):
# Set a session attribute
self._session.username = 'foo'
self._session.your_variable = 'bar'
self.write({'session_id': self._session.id,
'your_variable': self._session.your_variable})
self.finish()
def prepare(self):
super(Handler, self).on_finished()
# Do other stuff here
def prepare(self):
super(Handler, self).prepare()
# Do other stuff here
Heapy
The Heapy handler uses the guppy library to inspect the memory stack of your running Tinman application, providing a JSON document back with the results. It is very slow and blocking and can take many MINUTES to complete so it should be used very sparingly and if used on a production application, with the whitelist decorator.
To use the Heapy handler, just add the route to your configuration:
- [/heapy, tinman.handlers.heapy.HeapyRequestHandler]
Example Output
The following is a very abbreviated repport:
{
"rows": [
{
"count": {
"percent": 40,
"value": 45068
},
"cumulative": {
"percent": 29,
"value": 4159016
},
"item": "types.CodeType",
"referrers": {
"rows": [
{
"count": {
"percent": 96,
"value": 7290
},
"cumulative": {
"percent": 96,
"value": 874800
},
"item": "function",
"size": {
"percent": 96,
"value": 874800
}
}
],
"title": "Referrers by Kind (class / dict of class)",
"total_bytes": 911160,
"total_objects": 7593
},
"size": {
"percent": 29,
"value": 4159016
}
}
],
"title": "Referrers by Kind (class / dict of class)",
"total_bytes": 14584240,
"total_objects": 113444
}
Configuration
Application Options
The following are the keys that are available to be used for your Tinman/Tornado application.
- cookie_secret: A salt for signing cookies when using secure cookies
- debug: Toggle tornado.Application's debug mode
- login_url: Login URL when using Tornado's @authenticated decorator
- newrelic_ini: Path to newrelic Python .ini file for enabling newrelic support
- paths:
- base: The root of the files for the application
- static: The path to static files
- templates: The path to template files
- translations: The path to translation files
- redis: If using tinman.handlers.redis.RedisRequestHandler to auto-connect to redis.
- host: The redis server IP address
- port: The port number
- db: The database number
- rabbitmq:
- host: the hostname
- port: the server port
- virtual_host: the virtual host
- username: the username
- password: the password
- session: Configuration if using tinman.handlers.session.SessionRequestHandler
- adapter:
- class: The classname for the adapter. One of FileSessionAdapter, RedisSessionAdapter
- configuration: SessionAdapter specific configuration
- cookie:
- name: The cookie name for the session ID
- duration: The duration in seconds for the session lifetime
- adapter:
- template_loader: The python module.Class to override the default template loader with
- transforms: A list of transformation objects to add to the application in module.Class format
- ui_modules: Module for the UI modules classes, can be a single module, a mapping of modules (dict) or a list of modules.
- xsrf_cookies: Enable xsrf_cookie mode for forms
- whitelist: List of IP addresses in CIDR notation if whitelist decorator is to be used
Notes
The tinman-init script will create a skeleton Tinman directory structure for your project and create a setup.py that will put the static and template files in /usr/share/<project-name>.
If you are not going to install your app as a python package, you should set a base_path so that tinman knows what directory to insert into the Python path to be able to load your request handlers and such.
HTTP Server Options
Configure the tornado.httpserver.HTTPServer with the following options:
- no_keep_alive: Enable/Disable keep-alives
- ports: Ports to listen to, one process per port will be spawned
- ssl_options: SSL Options to pass to the HTTP Server
- certfile: Path to the certificate file
- keyfile: Path to the keyfile
- cert_reqs: Certificicate required?
- ca_certs: One of none, optional or required
- xheaders: Enable X-Header support in tornado.httpserver.HTTPServer
Logging Options
Logging uses the dictConfig format as specified at
http://docs.python.org/library/logging.config.html#dictionary-schema-details
But is able to do a minimal logging config thanks to clihelper defaults. The following is the minimal logging configuration required:
Logging:
tinman:
handlers: [console]
propagate: True
formatter: verbose
level: DEBUG
tornado:
handlers: [console]
propagate: True
formatter: verbose
level: INFO
Route List
The route list is specified using the top-level R
Related Skills
openhue
354.0kControl Philips Hue lights and scenes via the OpenHue CLI.
sag
354.0kElevenLabs text-to-speech with mac-style say UX.
weather
354.0kGet current weather and forecasts via wttr.in or Open-Meteo
casdoor
13.3kAn open-source AI-first Identity and Access Management (IAM) /AI MCP & agent gateway and auth server with web UI supporting OpenClaw, MCP, OAuth, OIDC, SAML, CAS, LDAP, SCIM, WebAuthn, TOTP, MFA, Face ID, Google Workspace, Azure AD



