Skip to content

An improved shell command for the Flask CLI

License

Notifications You must be signed in to change notification settings

sbusch/flask-konch

 
 

Repository files navigation

Flask-Konch

Latest version Travis-CI

Flask-Konch

An improved shell command for Flask

Flask-Konch adds an improved shell command, flask konch, to the Flask CLI.

Benefits of flask konch over flask shell

  • Uses IPython, BPython, or ptpython if available, and falls back to built-in interpreter
  • Automatically imports top-level Flask functions and classes by default
  • Define additional variables to include in the shell context
  • Configurable banner and prompt

Flask-Konch uses konch, a shell configuration utility, under the hood.

Get it now

pip install flask-konch

Usage

To run the shell:

export FLASK_APP=path/to/app.py
flask konch

To add additional variables to the shell context:

app = Flask(__name__)
app.config.update({
   'KONCH_CONTEXT': {
      'db': database,
      'User': User,
   }
})

Configuration options

  • KONCH_FLASK_IMPORTS: Whether to automatically import top-level Flask functions and classes. Defaults to True.
  • KONCH_FLASK_SHELL_CONTEXT: Whether to automatically import Flask shell context, as registered by shell_context_processor(f). Defaults to True.
  • KONCH_CONTEXT: Dictionary of additional variables to include in the shell context.
  • KONCH_SHELL: May be 'ipy', 'bpy', 'ptpy', 'ptipy', 'py', or 'auto' (default).
  • KONCH_BANNER: Custom banner.
  • KONCH_PROMPT: Custom input prompt.
  • KONCH_OUTPUT: Custom output prompt.
  • KONCH_CONTEXT_FORMAT: Format to display shell context. May be 'full', 'short', or a function that receives the context dictionary as input and returns a string.
  • KONCH_IPY_AUTORELOAD: Whether to load and enable the IPython autoreload extension (must be using ipython shell).
  • KONCH_IPY_EXTENSIONS: List of IPython extension names to load (must be using ipython shell).
  • KONCH_PTPY_VI_MODE: Enable vi mode (must be using ptpython shell).

Contributing

Linting via invoke and flake8:

invoke lint

Testing via invoke and pytest:

# Run test suite once
invoke test

# Run only tests which failed at last run
invoke test --last-failing

# Run test suite on each file change
invoke test --watch

This requires that the Python dependencies from dev-requirements.txt are installed, possibly into an own environment (virtualenv).

The test command also includes linting.

Full example:

# prepare Python environment
python3 -m venv ./venv
. ./venv/bin/activate
pip install -U -r dev-requirements.txt
pip install -U .

# single unit test
invoke test

# continuous unit tests while watching for file changes
pip install pytest-xdist
invoke test --watch

# leave Python environment
# note: does not remove ./venv folder
deactivate

To run tests on all supported Python versions, run

tox

tox installs Python dependencies into separate environments. On Fedora, tox can be installed globally via dnf install tox, which also installs all supported Python versions.

Project Links

License

MIT licensed. See the bundled LICENSE file for more details.

About

An improved shell command for the Flask CLI

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%