Simple, lightweight task scheduler for Python with async support
Project description
FastScheduler
Simple, lightweight task scheduler for Python with async support.
Features
- Simple decorator-based API
- Async/await support
- Persistent state (survives restarts)
- FastAPI integration with web dashboard
- Automatic retries on failure
- Quiet mode for minimal logging
Installation
pip install fastscheduler
Quick Start
from fastscheduler import FastScheduler
# Create scheduler
scheduler = FastScheduler(quiet=True)
# Schedule tasks
@scheduler.every(10).seconds
def task():
print("Task executed")
@scheduler.daily.at("14:30")
async def daily_task():
print("Daily task at 2:30 PM")
# Start scheduler
scheduler.start()
Examples
Basic Usage
import time
from fastscheduler import FastScheduler
scheduler = FastScheduler(quiet=True)
@scheduler.every(5).seconds
def quick_task():
print(f"[{time.strftime('%H:%M:%S')}] Task running")
scheduler.start()
# Keep program running
try:
while True:
time.sleep(60)
scheduler.print_status() # Simple status output
except KeyboardInterrupt:
scheduler.stop()
FastAPI Integration
from fastapi import FastAPI
from fastscheduler import FastScheduler
from fastscheduler.fastapi_integration import create_scheduler_routes
app = FastAPI()
scheduler = FastScheduler(quiet=True)
# Add web dashboard at /scheduler
app.include_router(create_scheduler_routes(scheduler))
@scheduler.every(30).seconds
def background_task():
print("Background work")
scheduler.start()
Scheduling Options
Interval-based
@scheduler.every(10).seconds
@scheduler.every(5).minutes
@scheduler.every(2).hours
@scheduler.every(1).days
Time-based
@scheduler.daily.at("09:00") # Daily at 9 AM
@scheduler.hourly.at(":30") # Every hour at :30
@scheduler.weekly.monday.at("10:00") # Every Monday at 10 AM
One-time
@scheduler.once(60) # Run once after 60 seconds
@scheduler.at("2024-12-25 00:00:00") # Run at specific datetime
Configuration
# Create scheduler with options
scheduler = FastScheduler(
state_file="scheduler.json", # Persistence file
quiet=True, # Minimal logging
auto_start=False # Don't auto-start
)
# Configure individual jobs
@scheduler.every(10).seconds.retries(5) # Retry up to 5 times
@scheduler.every(1).hours.no_catch_up() # Don't run missed jobs
Web Dashboard
The FastAPI integration includes a simple dark-mode dashboard:
- View all scheduled jobs
- Monitor execution history
- Check scheduler statistics
- Auto-refreshes every 10 seconds
Access at: http://localhost:8000/scheduler/
API
Core Methods
scheduler.start()- Start the schedulerscheduler.stop()- Stop gracefullyscheduler.print_status()- Print simple statusscheduler.get_jobs()- Get all scheduled jobsscheduler.get_statistics()- Get runtime statistics
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
fastscheduler-0.1.0.tar.gz
(45.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastscheduler-0.1.0.tar.gz.
File metadata
- Download URL: fastscheduler-0.1.0.tar.gz
- Upload date:
- Size: 45.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bebcf0a3b5c53e006a19e85f09428906a2014126634a90cd4f29a9c6158ad3d4
|
|
| MD5 |
bdca7ee044157a9aedd1d091a2bf6e6f
|
|
| BLAKE2b-256 |
0487961bb1b8db2d2f822e71ac99e4d2494981dda60b8383198061d9b5933eae
|
File details
Details for the file fastscheduler-0.1.0-py3-none-any.whl.
File metadata
- Download URL: fastscheduler-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c658bee1de5e7e9232d6f6b567705a043bc6075f17d37ce81c33e690a81513c5
|
|
| MD5 |
60cda7b168017b87cfaf2c0ad6bed033
|
|
| BLAKE2b-256 |
baccb3807ee31df3cd390da776ccdec4361b644619fe836a25219a5100f59b03
|