Flask-Shell-IPython

0.5.3 · active · verified Sat Apr 11

Flask-Shell-IPython (current version 0.5.3, released September 2024) is a Python package that seamlessly replaces the default `flask shell` command with an enhanced IPython shell. This integration provides developers with advanced interactive features such as syntax highlighting, tab-completion, command history, and IPython's "magic commands," significantly improving the Flask development and debugging experience. The project maintains an active development status with periodic updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a minimal Flask application that automatically uses the IPython shell when `flask shell` is executed. It also shows how to configure IPython settings and how to add custom objects (like `app` and `greeting`) to the shell's context using Flask's `shell_context_processor`.

from flask import Flask

app = Flask(__name__)

# Optional: Configure IPython settings via Flask app.config
app.config['IPYTHON_CONFIG'] = {
    'InteractiveShell': {
        'colors': 'Linux',
        'confirm_exit': False,
    },
}

@app.route('/')
def hello():
    return "Hello, World!"

# To make your app and any models/database objects available in the shell context,
# define a shell context processor.
@app.shell_context_processor
def make_shell_context():
    # In a real application, you would import your models and database instance here
    # e.g., from .models import User, Post
    # e.g., from .extensions import db
    return dict(app=app, greeting="Hello from shell context!")

# To run the IPython shell, save this file as app.py (or your preferred name)
# and execute in your terminal:
# FLASK_APP=app.py flask shell
# You should see the IPython prompt, and 'app' and 'greeting' will be available.

view raw JSON →