Scheduling Python Scripts: Complete Guide

Learn how to run Python scripts automatically on a schedule using cron, Task Scheduler, and the schedule library.

Using the Schedule Library

import schedule import time def job(): print("Running task...") # Schedule task schedule.every().day.at("10:00").do(job) schedule.every().hour.do(job) schedule.every(5).minutes.do(job) while True: schedule.run_pending() time.sleep(1)

Windows Task Scheduler

Use Task Scheduler to run scripts on Windows:

  1. Open Task Scheduler
  2. Create Basic Task
  3. Set trigger (daily, weekly, etc.)
  4. Action: Start a program
  5. Program: python.exe
  6. Arguments: your_script.py

Linux Cron Jobs

# Edit crontab crontab -e # Run daily at 2am 0 2 * * * /usr/bin/python3 /path/to/script.py # Run every hour 0 * * * * /usr/bin/python3 /path/to/script.py

Mac Launchd

Create a .plist file in ~/Library/LaunchAgents/ to schedule scripts on macOS.

← Back to Blog