Implement Background Tasks in FastAPI
Learn how to run background tasks and send an immediate response to the client using FastAPI.
What are background tasks?
Often when you get a request from a client, you do not want your API to process that data completely, else you will have to send a confirmation as soon as you receive a request and process that data or operation in the background. In other words, these are useful for operations that need to happen after a request, but the client doesn’t need to wait for the operation to get completed before receiving the response. For example:
-
Email notifications sent after performing some action: Connecting to an email server and then sending an email could be a slow (several seconds) process. We can return ...