Search code examples
openapi-generatoruvicorn

How can I change the pythonpath on `uvicorn` execution?


I generated a FastAPI project and all imports are relative to the src folder:

├── src
│   └── openapi_server
│       ├── apis
│       ├── main.py
│       ├── models
│       ├── __pycache__
│       └── security_api.py

So, I have basically two options:

  1. Fix all relative imports
  2. Fix pythonpath

How can I change the pythonpath on uvicorn execution? I found https://github.com/encode/uvicorn/pull/619 which I thought was the solution, but

~/.../src$ uvicorn main:main --reload --app-dir openapi_server/

didn't do the trick.


Solution

  • It's done how it's regularly done in python. Therefore, you can simply use:

    ~/.../src$ uvicorn openapi_server.main:main --reload