shell_command() — flask Function Reference
Architecture documentation for the shell_command() function in cli.py from the flask codebase.
Entity Profile
Dependency Diagram
graph TD d647a91f_21b8_ae35_eaba_e5cd7a4b6e5b["shell_command()"] a96499c3_f8a9_e782_f156_1c1ee4a86c69["cli.py"] d647a91f_21b8_ae35_eaba_e5cd7a4b6e5b -->|defined in| a96499c3_f8a9_e782_f156_1c1ee4a86c69 17ee5a72_b893_3ddb_5a29_fac91324b3ea["make_shell_context()"] d647a91f_21b8_ae35_eaba_e5cd7a4b6e5b -->|calls| 17ee5a72_b893_3ddb_5a29_fac91324b3ea style d647a91f_21b8_ae35_eaba_e5cd7a4b6e5b fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
src/flask/cli.py lines 1001–1045
def shell_command() -> None:
"""Run an interactive Python shell in the context of a given
Flask application. The application will populate the default
namespace of this shell according to its configuration.
This is useful for executing small snippets of management code
without having to manually configure the application.
"""
import code
banner = (
f"Python {sys.version} on {sys.platform}\n"
f"App: {current_app.import_name}\n"
f"Instance: {current_app.instance_path}"
)
ctx: dict[str, t.Any] = {}
# Support the regular Python interpreter startup script if someone
# is using it.
startup = os.environ.get("PYTHONSTARTUP")
if startup and os.path.isfile(startup):
with open(startup) as f:
eval(compile(f.read(), startup, "exec"), ctx)
ctx.update(current_app.make_shell_context())
# Site, customize, or startup script can set a hook to call when
# entering interactive mode. The default one sets up readline with
# tab and history completion.
interactive_hook = getattr(sys, "__interactivehook__", None)
if interactive_hook is not None:
try:
import readline
from rlcompleter import Completer
except ImportError:
pass
else:
# rlcompleter uses __main__.__dict__ by default, which is
# flask.__main__. Use the shell context instead.
readline.set_completer(Completer(ctx).complete)
interactive_hook()
code.interact(banner=banner, local=ctx)
Domain
Subdomains
Defined In
Calls
Source
Frequently Asked Questions
What does shell_command() do?
shell_command() is a function in the flask codebase, defined in src/flask/cli.py.
Where is shell_command() defined?
shell_command() is defined in src/flask/cli.py at line 1001.
What does shell_command() call?
shell_command() calls 1 function(s): make_shell_context.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free