Python Backend

Analyses Configurations

Example analyses/index.yaml:

title: Databench - Packaged Analyses
description: Analyses that come packaged with Databench.
version: 0.0.1

analyses:
  - name: dummypi
    title: Dummy π
    description: Calculating π the simple way, but this is called dummypi to avoid conflict with simplepi in the databench_examples repo.
    watch:
      - dummypi/*.js
      - dummypi/*.html
  - name: scaffold
    title: Scaffold
    description: A short description of this analysis.
    watch:
      - scaffold/*.js
      - scaffold/*.html
  - name: dummypi_py
    kernel: py
    title: Dummy π with Python Language Kernel
    description: Calculating π the simple way, but this is called dummypi to avoid conflict with simplepi in the databench_examples repo. This is using a Python Language Kernel running in a separate process.
    watch:
      - dummypi_py/*.js
      - dummypi_py/*.html
      - dummypi_py/*.py
  - name: scaffold_py
    kernel: py
    title: Scaffold_Py
    description: A short description of this analysis.
    watch:
      - scaffold_py/*.js
      - scaffold_py/*.html
      - scaffold_py/*.py

Defaults at the global level for index.yaml:

title: Databench
description: null
description_html: null
author: null
version: null
build: null
watch: null

analyses:
  ...

Logging

Changed in version 0.7.

Use Python’s logging as usual. To log to logging and send a message to the frontend about the log message, use self.emit('log', ...). Similarly, if the frontend emits a log action, a backend logging message will also be emitted. Similarly to log, this also works for warn and error. Also see Logging in the JavaScript section.

Routes

Add a routes.py file to your analysis with extra Tornado request handlers and register them in a ROUTES variable. This is an example of a routes.py file:

from tornado.web import RequestHandler


class PostHandler(RequestHandler):
    def post(self):
        print(self.get_argument('data', 'No data received'))
        self.write('done')


class GetHandler(RequestHandler):
    def get(self):
        self.write('done')


ROUTES = [
    ('post', PostHandler, {}),
    ('get', GetHandler, {}),
]

Autoreload and Build

Autoreload watches all dependent Python files and rebuilds when any of them change. It can be deactivated with the command line option --no-watch. Autoreload uses tornado.autoreload in the backend.

To run a single build (e.g. before deploying a production setting for Databench), use the --build command line option.

SSL

Provide --ssl-certfile, --ssl-keyfile and --ssl-port.

Command Line and Request Arguments

Command line parameters are in self.cli_args and the arguments from the http request are in self.request_args.

Changed in version 0.7.