Flask shell with steroids
Project description
Flask Shell Turbo
A drop-in utility that supercharges the Flask interactive shell, inspired by Django's shell_plus (from django-extensions). It auto-discovers your SQLAlchemy models, injects common utilities, and gives you a productive REPL (Read-Eval-Print Loop) for debugging, data exploration, and quick fixes — no repetitive imports required.
Description
Working with flask shell out of the box means manually importing every model and helper you need each time you open a session. Flask Shell Turbo solves this by:
- Auto-discovering all SQLAlchemy models registered on
db.Model, so every model in your project is available in the shell immediately — no imports. - Injecting common utilities like
datetime,date,timedelta,timezone, and core SQLAlchemy query helpers (func,select,text,and_,or_,not_,desc,asc). - Using IPython automatically when available, with
%autoreloadenabled so code changes are picked up without restarting the shell. - Providing safe helpers —
commit()androllback()— that wrapdb.sessionoperations with clear success/error feedback. - Enhancing the standard
flask shelltoo, via ashell_context_processor, so you get the benefits even without the new command. - Adding a new CLI command,
flask shell-turbo, with flags for a plain Python fallback and SQL query logging.
Requirements
- Flask
- Flask-SQLAlchemy (or a project using the
db.Modeldeclarative pattern) - SQLAlchemy 1.4+ (a legacy fallback is included for older versions)
- IPython (optional, but recommended)
Installation
-
Install flask-shell-turbo
pip install flask-shell-turbo
Integration into a Flask Project
Call init_shell_turbo(app, db) right after your db is initialized — typically in your app factory, after db.init_app(app).
from flask import Flask
from your_project.extensions import db
from flask_shell_turbo import init_shell_turbo
def create_app():
app = Flask(__name__)
# ... your config ...
db.init_app(app)
# Register shell_turbo after db is initialized
init_shell_turbo(app, db)
return app
That's it — no further configuration is needed. Model discovery happens automatically each time the shell starts, so newly added models are picked up without any manual registration.
Usage
Launch the enhanced shell
FLASK_APP=app flask shell-turbo
This drops you into an IPython session (or the standard Python shell if IPython isn't installed) with everything pre-loaded:
Flask shell-turbo
Models: Account, Order, User
Extras : db, session, func, select, and_, or_, desc, asc, datetime, date, timedelta, text
Helpers: commit(), rollback()
──────────────────────────────
Work with your models directly — no imports
user = User.query.filter_by(username="ab").first()
user.name = "Alejandro"
commit()
If something goes wrong, commit() automatically rolls back and prints the error instead of leaving your session in a broken transaction state:
✘ rollback — (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint...
CLI flags
| Flag | Description |
|---|---|
--plain |
Forces the standard Python shell (code.interact) even if IPython is installed. |
--print-sql |
Enables SQL echo (db.engine.echo = True) so every generated query is printed to the console. |
Example:
flask shell-turbo --print-sql
Standard flask shell also benefits
Even without using shell-turbo, the regular command is enriched automatically:
flask shell
Because init_shell_turbo registers a shell_context_processor, all discovered models and utilities are available there too — shell-turbo simply adds the nicer IPython experience, autoreload, and the extra CLI flags on top.
Benefits
- Zero-import debugging — jump straight into querying and modifying data without hunting down import paths.
- Faster iteration —
%autoreloadpicks up code changes to your models and helpers without restarting the shell. - Safer transactions —
commit()/rollback()prevent half-finished transactions from silently blocking further queries. - Query visibility on demand —
--print-sqllets you inspect the exact SQL Flask-SQLAlchemy generates, useful for debugging N+1 queries or unexpected joins. - Works everywhere — enhances both the new
shell-turbocommand and the existingflask shell, so teammates who haven't adopted it yet still benefit. - No dependencies required — IPython is optional; the tool gracefully falls back to a standard shell with tab-completion via
readline/rlcompleter. - Version-safe model discovery — supports both the modern SQLAlchemy
registry.mappersAPI and the legacy_decl_class_registry, so it works across SQLAlchemy versions.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flask_shell_turbo-1.0.1.tar.gz.
File metadata
- Download URL: flask_shell_turbo-1.0.1.tar.gz
- Upload date:
- Size: 43.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7fad32d8118a3c92adaa200b3877ae47b8eeedebf7c50cde308d73cc0999b0bb
|
|
| MD5 |
f2b788d491bbc8c16ae39b6d8a3c6771
|
|
| BLAKE2b-256 |
795af6691a24eacdce38660fd0d079923e079dac8cbb6cb9cffe9ec1c8df0ce0
|
File details
Details for the file flask_shell_turbo-1.0.1-py3-none-any.whl.
File metadata
- Download URL: flask_shell_turbo-1.0.1-py3-none-any.whl
- Upload date:
- Size: 30.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc3b426036f7c0166b52de5e60c497b1e8bcb1d865a545e7727cf00c4cab765a
|
|
| MD5 |
677fc54baed7f89a6f1f8444ed8a80e1
|
|
| BLAKE2b-256 |
b919aa7068890153d703779d68eb978c03efa45a16913618b0c58dd56390411f
|