How to automatically run a Python script every day ?

There are a few good ways to automatically run a Python script every day depending on your system and setup.

Below are 3 main approaches, from simplest to most robust

Using cron (Linux / macOS)

This is the most reliable and common way.

Open your terminal and type:

1
crontab -e

Add a line like this (example: run every day at 6 AM):

1
0 6 * * * /usr/bin/python3 /path/to/your/script.py >> /path/to/log.txt 2>&1

Explanation:

  • 0 6 * * * → run at 6:00 AM daily
  • /usr/bin/python3 → full path to Python
  • /path/to/your/script.py → your script
  • >> /path/to/log.txt 2>&1 → saves logs

Save and close.

You can check scheduled jobs using:

1
crontab -l

‍Using Windows Task Scheduler (if on Windows)

  1. Open Task Scheduler.
  2. Choose Create Basic Task → Name it → Trigger = Daily.
  3. Action = “Start a program”.

Program/script:

1
python

Add argument:

1
C:\path\to\your\script.py

Start in:

1
C:\path\to\

Use Python itself (for a lightweight approach)

If you want to keep it all in Python (e.g., script runs on a server):

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
import time
import schedule
import subprocess

def job():
    subprocess.run(["python3", "/path/to/your/download_script.py"])

# Run every day at 06:00
schedule.every().day.at("06:00").do(job)

while True:
    schedule.run_pending()
    time.sleep(60)

Then run this “scheduler” script in the background (for example with nohup or screen):

1
nohup python3 scheduler.py &
  • If you just need it daily and reliably → use cron (best option).
  • If you need fine control or cross-platform automation → use a scheduler script or Airflow / Prefect later.

Real-World Example: Automatically Download Daily Data from a URL

This method can be used to automatically run a Python script each day — for instance, to download daily data from an online source.
For a detailed implementation, refer to the section Real-World Example: Automatically Download Daily Data from a URL.

References

Links Site
cron manual (Linux) Official Linux cron documentation (man7.org)
Task Scheduler (Windows) Official Microsoft documentation for Windows Task Scheduler
Schedule Python Library Official schedule library documentation (Read the Docs)
Python subprocess module Official Python documentation for running external commands
Python time module Official Python documentation for timing and sleeping functions