{"id":906,"hash":"71c5230cbcba66b1163036de7ec57de9b8979996fc9fddcc851f600f012870b8","pattern":"FastAPI throws an error (Error loading ASGI app. Could not import module &quot;api&quot;)","full_message":"I tried to run FastAPI using uvicorn webserver but it throws an error.\n\nI run this command,\n\nuvicorn api:app --reload --host 0.0.0.0\n\nbut there is an error in the terminal.\n\nUvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)\nStarted reloader process [23445]\nError loading ASGI app. Could not import module \"api\".\nStopping reloader process [23445]","ecosystem":"pypi","package_name":"fastapi","package_version":null,"solution":"TL;DR\nAdd the directory name in front of your filename\n\nuvicorn src.main:app \n\nor cd into that directory\n\ncd src\nuvicorn main:app \n\nLong Answer\nIt happens because you are not in the same folder with your FastAPI app instance more specifically:\n\nLet's say i have an app-tree like this;\n\nmy_fastapi_app/\n├── app.yaml\n├── docker-compose.yml\n├── src\n│   └── main.py\n└── tests\n    ├── test_xx.py\n    └── test_yy.py\n\n$ pwd         # Present Working Directory\n/home/yagiz/Desktop/my_fastapi_app\n\nI'm not inside the same folder with my app instance, so if I try to run my app with uvicorn I'll get an error like yours\n\n$ uvicorn main:app --reload\nINFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)\nINFO:     Started reloader process [40645] using statreload\nERROR:    Error loading ASGI app. Could not import module \"main\".\n\nThe answer is so simple, add the folder name in front of your filename\n\nuvicorn src.main:app --reload\n\nor you can change your working directory\n\ncd src \n\nNow i'm inside of the folder with my app instance\n\nsrc\n└── main.py\n\nRun your uvicorn again\n\n$ uvicorn main:app --reload\nINFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)\nINFO:     Started reloader process [40726] using statreload\nINFO:     Started server process [40728]\nINFO:     Waiting for application startup.\nINFO:     Application startup complete.","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/60819376/fastapi-throws-an-error-error-loading-asgi-app-could-not-import-module-api","votes":189,"created_at":"2026-04-19T04:51:59.330860+00:00","updated_at":"2026-04-19T04:51:59.330860+00:00"}