✅ FastAPI Tutorial • How to use BACKGROUND TASKS

Subscribers:
1,420
Published on ● Video Link: https://www.youtube.com/watch?v=IGb3xvIwRmk



Category:
Tutorial
Duration: 6:39
2,631 views
57


Learn the best way on how to use FastAPI Background Tasks.

In this video I show you how you can use some simple background tasks in your first api application.

Firstly, FastAPI Background Tasks can defined as background tasks that can be run after returning a response.

The client doesn't really have to be wait for the operation to complete before receiving the response.

For example:
(i) Email notifications sent after performing an action.
(ii) Processing data etc.

First, import Background Tasks from FastAPI module and define a parameter in your path operation function with a type declaration of Background Tasks

We'll cover everything from setting up your environment to creating and scheduling backgroundtasks, and we'll use python windows notification module called winotify to schedule our windows notification, it will be shown after 5 seconds of hitting the endpoint.

Whether you're a python beginner or an experienced developer, this video will help you take your FastAPI skills to the next level. Join me and learn how to make your API more efficient and Scalable with FastAPI Background Tasks.

FastAPI Dependency Injection:
Using Background Tasks also works with the dependency injection system, you can declare a parameter of type Background Tasks at multiple levels: in a path operation function, in a dependency (dependable), in a sub-dependency, etc.

FastAPI knows what to do in each case and how to re-use the same object, so that all the background tasks are merged together and are run in the background afterwards.

Technical Details
The class Background Tasks comes directly from starlette.background.

It is imported/included directly into FastAPI so that you can import it from fastapi.
Avoid importing the alternative Background Tasks (without the s at the end) from starlette.background.

--timestamp--
00:00 Intro
00:13 Setting Python Environment
00:28 Initialize the App
01:21 Add Message Model
01:43 Add Notification Model
03:15 Import the Defined Methods
03:46 Create the Notification Task
04:22 Plugin Request Body
05:19 Rest Client to Test
06:16 Run the Background Tasks


For Source Code:
➡️ Github: https://github.com/amoprocedures/fastapi-background-tasks

If you intrested in more tech videos about computer programming and more about FastAPI:
🔗 https://www.youtube.com/playlist?list=PLp0LE6wXbOGYU1ZuwjxDI-Sa_DlI0sAPr

🔗 https://www.youtube.com/playlist?list=PLp0LE6wXbOGZVrYxXrmtfLT8nGHxhEOCH







Tags:
fastapi
api
fastapi background
fastapi background task
fastapi background tasks
fastapi tasks
background tasks
background shedule
fastapi background shedules
fastapi background shedule
fastapi tutorial
best fastapi api
fastapi for beginners
python fastapi
python tutorials
python sqlite
background schedule
fastapi tutorials for beginners
beginners tutorial
pytho for beginners
best python
python programming
fastapi server
best
fastapi tutorials