find_best_app() — flask Function Reference
Architecture documentation for the find_best_app() function in cli.py from the flask codebase.
Entity Profile
Dependency Diagram
graph TD 61227b34_c67c_0bff_1c83_c375e071843e["find_best_app()"] a96499c3_f8a9_e782_f156_1c1ee4a86c69["cli.py"] 61227b34_c67c_0bff_1c83_c375e071843e -->|defined in| a96499c3_f8a9_e782_f156_1c1ee4a86c69 95e11cb3_caab_ad8f_3f8c_c26632862fe3["locate_app()"] 95e11cb3_caab_ad8f_3f8c_c26632862fe3 -->|calls| 61227b34_c67c_0bff_1c83_c375e071843e c9d5aa34_1bf5_6777_6447_72b24ceb6b6b["_called_with_wrong_args()"] 61227b34_c67c_0bff_1c83_c375e071843e -->|calls| c9d5aa34_1bf5_6777_6447_72b24ceb6b6b style 61227b34_c67c_0bff_1c83_c375e071843e fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
src/flask/cli.py lines 41–91
def find_best_app(module: ModuleType) -> Flask:
"""Given a module instance this tries to find the best possible
application in the module or raises an exception.
"""
from . import Flask
# Search for the most common names first.
for attr_name in ("app", "application"):
app = getattr(module, attr_name, None)
if isinstance(app, Flask):
return app
# Otherwise find the only object that is a Flask instance.
matches = [v for v in module.__dict__.values() if isinstance(v, Flask)]
if len(matches) == 1:
return matches[0]
elif len(matches) > 1:
raise NoAppException(
"Detected multiple Flask applications in module"
f" '{module.__name__}'. Use '{module.__name__}:name'"
" to specify the correct one."
)
# Search for app factory functions.
for attr_name in ("create_app", "make_app"):
app_factory = getattr(module, attr_name, None)
if inspect.isfunction(app_factory):
try:
app = app_factory()
if isinstance(app, Flask):
return app
except TypeError as e:
if not _called_with_wrong_args(app_factory):
raise
raise NoAppException(
f"Detected factory '{attr_name}' in module '{module.__name__}',"
" but could not call it without arguments. Use"
f" '{module.__name__}:{attr_name}(args)'"
" to specify arguments."
) from e
raise NoAppException(
"Failed to find Flask application or factory in module"
f" '{module.__name__}'. Use '{module.__name__}:name'"
" to specify one."
)
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does find_best_app() do?
find_best_app() is a function in the flask codebase, defined in src/flask/cli.py.
Where is find_best_app() defined?
find_best_app() is defined in src/flask/cli.py at line 41.
What does find_best_app() call?
find_best_app() calls 1 function(s): _called_with_wrong_args.
What calls find_best_app()?
find_best_app() is called by 1 function(s): locate_app.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free