product:console
Introduction
product:console opens a Python shell inside your product’s application context, with the database and every model already imported. Use it to look at your data without writing a single import. It needs a selected product (SPLENT_APP) and a reachable database.
$ splent product:console
🐍 SPLENT console — my_first_app
app, db loaded.
Models: Note, User, UserProfile
Services: (none)
>>> User.query.count()
42
>>> Note.query.filter_by(user_id=1).all()
[<Note 1>, <Note 2>]
>>> db.session.execute(db.text("SELECT COUNT(*) FROM user")).scalar()
42
It uses IPython when it is installed, and the plain Python shell otherwise.
What is loaded
| Name | What it is |
|---|---|
app |
The Flask application, with its context pushed |
db |
The SQLAlchemy instance (splent_framework.db.db) |
| Model classes | Every db.Model subclass, such as User or Note |
| Services | Every service in app.extensions['splent_services'], by class name |
Where it runs
The console builds your product’s app, in development unless SPLENT_ENV says otherwise.
It runs in the product’s web container, <product>_web, when that container is up and either you work on another product than the selected one (SPLENT_APP=<name> splent product:console) or the features need a package the CLI’s image lacks. Otherwise it runs in the CLI’s container.
See also
db:consoleopens a MariaDB shell for raw SQL.product:shellopens a shell in the container.product:configshows the resolved configuration.