uvicorn

FastAPI python: How to run a thread in the background?

FastAPI python: How to run a thread in the background? Question: I’m making a server in python using FastAPI, and I want a function that is not related to my API, to run in background every 5 minutes (like checking stuff from an API and printing stuff depending on the response) I’ve tried to make …

Total answers: 2

Way to pass arguments to FastAPI app via command line

Way to pass arguments to FastAPI app via command line Question: I’m using python 3.8.0 for my FastAPI app. It uses the .env file located on the root of a project directory. I am using the dotenv package, and the location of the .env file is hardcoded within the app. Here is my unit file …

Total answers: 1

Error loading ASGI app. Could not import module "src.main"

Error loading ASGI app. Could not import module "src.main" Question: I saw the solution is changing main -> src.main so I tried that, but the same problem is occuring even if I use cd src to move to src and run uvicorn main:app –reload, errors continue. What do I need? I am using a virtual …

Total answers: 3

How to return a list of PIL image files from fastapi response?

How to return a list of PIL image files from fastapi response? Question: I have created an rest-api using fastapi, which takes a document (pdf) as input and return a jpeg image of it, I am using a library called docx2pdf for conversion. from docx2pdf import convert_to from fastapi import FastAPI, File, UploadFile app = …

Total answers: 1

reload flag with uvicorn: can we exclude certain code?

reload flag with uvicorn: can we exclude certain code? Question: Is it somehow possible to exclude certain part of the code when reloading the scrip with –reload flag? uvicorn main:app –reload Use case: I have a model which takes a lot of time loading so I was wondering if there is a way to ignore …

Total answers: 4

FastAPI and Pydantic RecursionError Causing Exception in ASGI application

FastAPI and Pydantic RecursionError Causing Exception in ASGI application Question: Description I’ve seen similar issues about self-referencing Pydantic models causing RecursionError: maximum recursion depth exceeded in comparison but as far as I can tell there are no self-referencing models included in the code. I’m just just using Pydantic’s BaseModel class. The code runs successfully until …

Total answers: 3

is there a difference between running fastapi from uvicorn command in dockerfile and from pythonfile?

is there a difference between running fastapi from uvicorn command in dockerfile and from pythonfile? Question: I am running a fast api and when i was developing i had the following piece of code in my app.py file code in app.py: import uvicorn if __name__=="__main__": uvicorn.run("app.app:app",host=’0.0.0.0′, port=4557, reload=True, debug=True, workers=3) so i was about to …

Total answers: 2

How to do multiprocessing in FastAPI

How to do multiprocessing in FastAPI Question: While serving a FastAPI request, I have a CPU-bound task to do on every element of a list. I’d like to do this processing on multiple CPU cores. What’s the proper way to do this within FastAPI? Can I use the standard multiprocessing module? All the tutorials/questions I …

Total answers: 1