
Research
/Security News
Critical Vulnerability in NestJS Devtools: Localhost RCE via Sandbox Escape
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Cron scheduling extension for FastAPI with decorators, async support, Hooks, CLI, and SQLite job tracking.
Effortlessly schedule and manage your background tasks.
Built with the tools and technologies:
Welcome to the official guide for using fastapi_crons
, a high-performance, developer-friendly cron scheduling extension for FastAPI. This library enables you to define, monitor, and control scheduled background jobs using simple decorators and provides CLI tools, web-based monitoring, and SQLite-based job tracking.
from fastapi import FastAPI, Crons
/crons
)pip install fastapi-crons
from fastapi import FastAPI
from fastapi_crons import Crons, get_cron_router
app = FastAPI()
crons = Crons(app)
app.include_router(get_cron_router())
@app.get("/")
def root():
return {"message": "Hello from FastAPI"}
@crons.cron("*/5 * * * *", name="print_hello")
def print_hello():
print("Hello! I run every 5 minutes.")
@crons.cron("0 0 * * *", name="daily_task", tags=["rewards"])
async def run_daily_task():
# Distribute daily rewards or any async task
await some_async_function()
┌───────────── minute (0 - 59)
│ ┌───────────── hour (0 - 23)
│ │ ┌───────────── day of the month (1 - 31)
│ │ │ ┌───────────── month (1 - 12)
│ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday)
│ │ │ │ │
* * * * *
* * * * *
: Every minute*/15 * * * *
: Every 15 minutes0 * * * *
: Every hour0 0 * * *
: Every day at midnight0 0 * * 0
: Every Sunday at midnightOnce included, visit:
GET /crons
You'll get a full list of jobs with:
name
expr
(cron expression)tags
last_run
(from SQLite)next_run
We use SQLite (via aiosqlite
) to keep a persistent record of when each job last ran. This allows observability and resilience during restarts.
CREATE TABLE IF NOT EXISTS job_state (
name TEXT PRIMARY KEY,
last_run TEXT
);
By default, job state is stored in a SQLite database named cron_state.db
in the current directory. You can customize the database path:
from fastapi_cron import Crons, SQLiteStateBackend
# Custom database path
state_backend = SQLiteStateBackend(db_path="/path/to/my_crons.db")
crons = Crons(state_backend=state_backend)
The scheduler supports both async and sync job functions Jobs can be:
async def
→ run in asyncio loopdef
→ run safely in background thread using await asyncio.to_thread(...)
# List all registered jobs
fastapi_cron list
# Manually run a specific job
fastapi_cron run_job < job_name >
You can add tags to jobs for better organization:
@cron_job("*/5 * * * *", tags=["maintenance", "cleanup"])
async def cleanup_job():
# This job has tags for categorization
pass
FastAPI App
│
├── Crons()
│ ├── Registers decorated jobs
│ ├── Starts background scheduler (async)
│
├── SQLite Backend
│ ├── Tracks last run for each job
│
├── /crons endpoint
│ ├── Shows current job status (with timestamps)
│
└── CLI Tool
├── List jobs / Run manually
We welcome PRs and suggestions! If you'd like this added to FastAPI officially, fork the repo, polish it, and submit to FastAPI with a clear integration proposal.
Made with ❤️ by Mehar Umar.
Designed to give developers freedom, flexibility, and control when building production-grade FastAPI apps.
FAQs
Cron scheduling extension for FastAPI with decorators, async support, Hooks, CLI, and SQLite job tracking.
We found that fastapi-crons demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.