FlaskGroup Class — flask Architecture
Architecture documentation for the FlaskGroup class in cli.py from the flask codebase.
Entity Profile
Dependency Diagram
graph TD ee9fbc8f_42bd_3ef5_a80f_72abfe054c0b["FlaskGroup"] ea63e19e_2fd3_885d_2922_e4101fe8320a["AppGroup"] ee9fbc8f_42bd_3ef5_a80f_72abfe054c0b -->|extends| ea63e19e_2fd3_885d_2922_e4101fe8320a 9fb0ba66_32bf_1412_77b1_174dae79c4b2["ScriptInfo"] ee9fbc8f_42bd_3ef5_a80f_72abfe054c0b -->|extends| 9fb0ba66_32bf_1412_77b1_174dae79c4b2 a96499c3_f8a9_e782_f156_1c1ee4a86c69["cli.py"] ee9fbc8f_42bd_3ef5_a80f_72abfe054c0b -->|defined in| a96499c3_f8a9_e782_f156_1c1ee4a86c69 e9361747_7510_50a9_29c5_1934b7b46b16["__init__()"] ee9fbc8f_42bd_3ef5_a80f_72abfe054c0b -->|method| e9361747_7510_50a9_29c5_1934b7b46b16 67dea11c_5c94_6773_8a63_f280d0830338["_load_plugin_commands()"] ee9fbc8f_42bd_3ef5_a80f_72abfe054c0b -->|method| 67dea11c_5c94_6773_8a63_f280d0830338 596bd738_9f64_52c9_9cdc_d6c4ce8f6278["get_command()"] ee9fbc8f_42bd_3ef5_a80f_72abfe054c0b -->|method| 596bd738_9f64_52c9_9cdc_d6c4ce8f6278 d828f6fc_89be_5a05_5589_42611ae7786a["list_commands()"] ee9fbc8f_42bd_3ef5_a80f_72abfe054c0b -->|method| d828f6fc_89be_5a05_5589_42611ae7786a 57df2c73_65cb_ce7f_551b_d57f6d93eddf["make_context()"] ee9fbc8f_42bd_3ef5_a80f_72abfe054c0b -->|method| 57df2c73_65cb_ce7f_551b_d57f6d93eddf e15a2edb_266e_9bc5_e178_cc73b9ab503d["parse_args()"] ee9fbc8f_42bd_3ef5_a80f_72abfe054c0b -->|method| e15a2edb_266e_9bc5_e178_cc73b9ab503d
Relationship Graph
Source Code
src/flask/cli.py lines 531–688
class FlaskGroup(AppGroup):
"""Special subclass of the :class:`AppGroup` group that supports
loading more commands from the configured Flask app. Normally a
developer does not have to interface with this class but there are
some very advanced use cases for which it makes sense to create an
instance of this. see :ref:`custom-scripts`.
:param add_default_commands: if this is True then the default run and
shell commands will be added.
:param add_version_option: adds the ``--version`` option.
:param create_app: an optional callback that is passed the script info and
returns the loaded app.
:param load_dotenv: Load the nearest :file:`.env` and :file:`.flaskenv`
files to set environment variables. Will also change the working
directory to the directory containing the first file found.
:param set_debug_flag: Set the app's debug flag.
.. versionchanged:: 3.1
``-e path`` takes precedence over default ``.env`` and ``.flaskenv`` files.
.. versionchanged:: 2.2
Added the ``-A/--app``, ``--debug/--no-debug``, ``-e/--env-file`` options.
.. versionchanged:: 2.2
An app context is pushed when running ``app.cli`` commands, so
``@with_appcontext`` is no longer required for those commands.
.. versionchanged:: 1.0
If installed, python-dotenv will be used to load environment variables
from :file:`.env` and :file:`.flaskenv` files.
"""
def __init__(
self,
add_default_commands: bool = True,
create_app: t.Callable[..., Flask] | None = None,
add_version_option: bool = True,
load_dotenv: bool = True,
set_debug_flag: bool = True,
**extra: t.Any,
) -> None:
params: list[click.Parameter] = list(extra.pop("params", None) or ())
# Processing is done with option callbacks instead of a group
# callback. This allows users to make a custom group callback
# without losing the behavior. --env-file must come first so
# that it is eagerly evaluated before --app.
params.extend((_env_file_option, _app_option, _debug_option))
if add_version_option:
params.append(version_option)
if "context_settings" not in extra:
extra["context_settings"] = {}
extra["context_settings"].setdefault("auto_envvar_prefix", "FLASK")
super().__init__(params=params, **extra)
self.create_app = create_app
self.load_dotenv = load_dotenv
self.set_debug_flag = set_debug_flag
if add_default_commands:
self.add_command(run_command)
self.add_command(shell_command)
self.add_command(routes_command)
self._loaded_plugin_commands = False
def _load_plugin_commands(self) -> None:
if self._loaded_plugin_commands:
return
for ep in importlib.metadata.entry_points(group="flask.commands"):
self.add_command(ep.load(), ep.name)
self._loaded_plugin_commands = True
def get_command(self, ctx: click.Context, name: str) -> click.Command | None:
self._load_plugin_commands()
# Look up built-in and plugin commands, which should be
Domain
Defined In
Extends
Source
Frequently Asked Questions
What is the FlaskGroup class?
FlaskGroup is a class in the flask codebase, defined in src/flask/cli.py.
Where is FlaskGroup defined?
FlaskGroup is defined in src/flask/cli.py at line 531.
What does FlaskGroup extend?
FlaskGroup extends AppGroup, ScriptInfo.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free