Skip to content

User Guide

This user guide shows you how to use FastAPI-APScheduler4 with most of its features.

Multiple Files

If you are building an application with multiple files, you can use the Scheduler class to manage the scheduled tasks.

app/schedulers/hello.py
from fastapi_apscheduler4 import Scheduler

scheduler = Scheduler()


@scheduler.interval(seconds=5)
def hello() -> None:
    print("Hello, world!")

Just need to import the Scheduler and include it in the SchedulerApp.

app/main.py
from fastapi import FastAPI
from fastapi_apscheduler4 import SchedulerApp

from .schedulers import hello

scheduler_app = SchedulerApp()
scheduler_app.include(hello.scheduler)

app = FastAPI(lifespan=scheduler_app.lifespan)