OpenBB-finance/OpenBB · error · AttributeError
Error: The app file '{app_path}' does not contain an '{name}
Error message
Error: The app file '{app_path}' does not contain an '{name}' instance What it means
AttributeError raised after the app module was successfully imported/loaded, but it has no attribute with the requested name (default 'app', or the part after ':' in 'module:attr' notation, or the --name value). The importer then cannot retrieve the FastAPI instance to serve.
Source
Thrown at openbb_platform/extensions/mcp_server/openbb_mcp_server/utils/app_import.py:74
raise FileNotFoundError( # pylint: disable=raise-missing-from
f"Error: Neither module '{module_path}' could be imported nor file '{file_path}' exists"
)
module = _load_module_from_file_path(file_path)
# Case 2: File path (e.g., "main.py" or "my_app/main.py")
else:
if not Path(app_path).is_absolute():
cwd = Path.cwd()
app_path = str(cwd.joinpath(app_path).resolve())
if not Path(app_path).exists():
raise FileNotFoundError(f"Error: The app file '{app_path}' does not exist")
module = _load_module_from_file_path(app_path)
if not hasattr(module, name):
raise AttributeError(
f"Error: The app file '{app_path}' does not contain an '{name}' instance"
)
app_or_factory = getattr(module, name)
# Here we use the same approach as uvicorn to handle factory functions.
# This prevents us from relying on explicit type annotations.
# See: https://github.com/encode/uvicorn/blob/master/uvicorn/config.py
try:
app = app_or_factory()
if not factory:
print( # noqa: T201
"\n\n[WARNING] "
"App factory detected. Using it, but please consider setting the --factory flag explicitly.\n"
)
except TypeError:
if factory:
raise TypeError( # pylint: disable=raise-missing-fromView on GitHub (pinned to 3e071fcc2c)
Solutions
- Match the name: use colon notation --app main.py:application or pass --name application
- Or add 'app = application' (an alias) in the module so the default name works
- For factories, export the factory function by its exact name and add --factory
Example fix
# before # main.py: application = FastAPI() openbb-mcp --app ./main.py # looks for 'app' # after openbb-mcp --app ./main.py:application
Defensive patterns
Strategy: validation
Validate before calling
import runpy # or import the module explicitly
mod = importlib.import_module(module_name) if module_importable else runpy.run_path(file_path)
if not hasattr(mod, attr_name):
available = [n for n in dir(mod) if isinstance(getattr(mod, n), FastAPI)]
raise ValueError(f"no '{attr_name}' attr; FastAPI instances found: {available}") Type guard
def module_exposes_app(module, name: str) -> bool:
return hasattr(module, name) Try / catch
try:
app = import_app("./main.py", "app")
except AttributeError as e:
if "does not contain" in str(e):
import runpy
mod = runpy.run_path("./main.py")
candidates = [n for n, v in mod.items() if isinstance(v, FastAPI)]
app = import_app(f"./main.py:{candidates[0]}", candidates[0])
else:
raise Prevention
- Standardize on the variable name 'app' across your services
- Use colon notation main.py:application to state the name explicitly in the command
- Lint for 'app = FastAPI(' in the entry module during CI
When it happens
Trigger: --app main.py where main.py creates the app under a different variable (e.g. 'application' or 'api'); --app my_app.main:create_app without that function existing; --name app when the file names it 'fastapi_app'. The check is a plain hasattr on the loaded module.
Common situations: Following a tutorial whose variable name differs from your project's, refactoring that renames the app variable, using a factory function name that was misspelled, assuming 'app' is exported by a package's __init__ when it is defined in a submodule.
Related errors
- Failed to load the file specs for '{file_path}'
- Error: Neither module '{module_path}' could be imported nor
- Error: The app file '{app_path}' does not exist
- Error: The {name} instance in '{app_path}' appears not to be
- Error: The {name} instance in '{app_path}' is not an instanc
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/78d8b09616622b15.
Report an issue: GitHub.