{"record":{"id":"9e86fab335ce978b","repo":"OpenBB-finance/OpenBB","slug":"error-the-app-file-app-path-does-not-contain-9e86fa","errorCode":null,"errorMessage":"Error: The app file '{app_path}' does not contain an '{name}' instance","messagePattern":"Error: The app file '(.+?)' does not contain an '(.+?)' instance","errorType":"exception","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"openbb_platform/extensions/platform_api/openbb_platform_api/utils/api.py","lineNumber":277,"sourceCode":"                raise FileNotFoundError(  # pylint: disable=raise-missing-from\n                    f\"Error: Neither module '{module_path}' could be imported nor file '{file_path}' exists\"\n                )\n\n            module = _load_module_from_file_path(file_path)\n\n    # Case 2: File path (e.g., \"main.py\" or \"my_app/main.py\")\n    else:\n        if not Path(app_path).is_absolute():\n            cwd = Path.cwd()\n            app_path = str(cwd.joinpath(app_path).resolve())\n\n        if not Path(app_path).exists():\n            raise FileNotFoundError(f\"Error: The app file '{app_path}' does not exist\")\n\n        module = _load_module_from_file_path(app_path)\n\n    if not hasattr(module, name):\n        raise AttributeError(\n            f\"Error: The app file '{app_path}' does not contain an '{name}' instance\"\n        )\n\n    app_or_factory = getattr(module, name)\n\n    # Here we use the same approach as uvicorn to handle factory functions.\n    # This prevents us from relying on explicit type annotations.\n    # See: https://github.com/encode/uvicorn/blob/master/uvicorn/config.py\n    try:\n        app = app_or_factory()\n        if not factory:\n            print(  # noqa: T201\n                \"\\n\\n[WARNING]   \"\n                \"App factory detected. Using it, but please consider setting the --factory flag explicitly.\\n\"\n            )\n    except TypeError:\n        if factory:\n            raise TypeError(  # pylint: disable=raise-missing-from","sourceCodeStart":259,"sourceCodeEnd":295,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/extensions/platform_api/openbb_platform_api/utils/api.py#L259-L295","documentation":"Raised after the app module was successfully imported/loaded but it has no attribute with the requested instance name (default 'app'). The loader then cannot retrieve the FastAPI application or factory from the module.","triggerScenarios":"Calling import_app('main.py', 'app') where main.py defines the variable under a different name (e.g. 'application', 'api', 'create_app') or only exposes it under __main__ guards.","commonSituations":"Uvicorn-style examples naming the app 'application'; the app assigned inside if __name__ == '__main__': so it does not exist at import time; typo in the --name parameter.","solutions":["Check the module's actual attribute name and pass it via the name parameter (or colon notation 'main:application').","Move the FastAPI(...) assignment to module top level, outside the __main__ guard.","Verify with: python -c \"import main; print(hasattr(main,'app'))\".","Fix typos in the --name argument."],"exampleFix":"# before\n# main.py\nif __name__ == \"__main__\":\n    app = FastAPI()\nimport_app('main.py', 'app')  # AttributeError\n\n# after\n# main.py\napp = FastAPI()\nif __name__ == \"__main__\":\n    ...\nimport_app('main.py', 'app')","handlingStrategy":"validation","validationCode":"import importlib\nmod = importlib.import_module(\"my_app.main\")\nassert hasattr(mod, app_name), f\"module defines: {[n for n in dir(mod) if not n.startswith('_')]}\"","typeGuard":"def module_exports(module, name: str) -> bool:\n    return hasattr(module, name)","tryCatchPattern":"try:\n    app = import_app(\"main.py\", \"app\")\nexcept AttributeError as e:\n    # discover likely names\n    import main\n    raise RuntimeError(f\"available names: {dir(main)}\") from e","preventionTips":["Name the FastAPI instance 'app' at module top level","Keep app assignment outside if __name__ == '__main__'","Use colon notation 'main:application' when the name differs"],"tags":["fastapi","startup","attribute-error"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}