Flask-Runner: Command Line Options for Flask

I just published a little extension for Flask that exposes some of the options that can be given when calling app.run().

Here is the minimal Flask application from the documentation, modified to use this extension:

from flask import Flask, request, render_template
from flask.ext.runner import Runner
app = Flask(__name__)
runner = Runner(app)

@app.route('/')
def hello_world():
    return 'Hello World!'

if __name__ == '__main__':
    runner.run()

You can see the extension in action by invoking the application with --help:

$ python hello.py --help
usage: hello.py [-h] [--host HOST] [--port PORT] [--debug] [--noeval]
                [--reload] [--extra FILE]

optional arguments:
  -h, --help    show this help message and exit
  --host HOST   hostname or IP address to listen on (default is "127.0.0.1")
  --port PORT   port of the web server (default is 5000)
  --debug       enable the debugger
  --noeval      disable the exception evaluation feature in the debugger
  --reload      reload the Python process when any modules are changed
  --extra FILE  additional file for the reloader to watch for changes

To install this extension you can use pip:

$ pip install flask-runner

The source code is available on my github.

I hope you find it useful!

UPDATE: just added --profile and --lint to enable the Werkzeug profiler and lint middlewares!

UPDATE #2: just released version 2.0, which is a rewrite as an extension to Flask-Script. The simple interface described in this article remains available, but a more powerful interface that allows custom commands is also available. See the github page for details.

Miguel

1 comment

  • #1 Samuel Bucquet said :

    It's a great addition. Would it be possible to use plac for this, as I use it a lot ? https://pypi.python.org/pypi/plac

Leave a Comment

Note: all comments are screened before they are published. Thank you for your patience!