Schedule

1.2.2 · active · verified Thu Apr 09

Schedule is a lightweight, in-process job scheduler for Python that allows you to schedule tasks to run at specific intervals or times. It aims for a human-readable syntax and is designed for simplicity. The current version is 1.2.2, and it maintains a stable, low-cadence release cycle, indicating a mature and well-tested library.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to define simple functions as jobs and schedule them to run at set intervals. The `schedule.run_pending()` call within a `while` loop is crucial for the scheduler to check and execute due jobs. The `time.sleep(1)` prevents the loop from consuming too much CPU.

import schedule
import time

def greet_job(name):
    print(f"Hello, {name}!")

def farewell_job():
    print("Goodbye!")

# Schedule a job to run every 5 seconds, passing arguments
schedule.every(5).seconds.do(greet_job, 'Alice')

# Schedule a job to run once per minute
schedule.every().minute.do(farewell_job)

print("Scheduler started. Jobs will run in the console.")
print("Press Ctrl+C to stop.")

try:
    while True:
        schedule.run_pending() # Run all jobs that are due
        time.sleep(1) # Wait one second before checking again
except KeyboardInterrupt:
    print("Scheduler stopped.")

view raw JSON →