Skip to main content

Command Palette

Search for a command to run...

Scheduling Python Scripts

with the Windows Task Scheduler

Published
1 min read
Scheduling Python Scripts
M

I am a developer with 36+ years of rigorous business operations experience. I don't just write Python; I build tools that save businesses 20+ hours a week. Specialising in custom dashboards (Streamlit), high-performance APIs (FastAPI), and automated data gathering (Scraping).

Scheduling Python scripts with Windows Task Scheduler allows you to automate tasks and execute scripts at specific times or intervals. This can be useful for tasks like data processing, backups, or sending email notifications.

Creating a Batch File

  1. Create a batch file (.bat) using a text editor.

  2. For virtualized environments, activate the virtual environment, run the script, and deactivate the virtual environment.

call C:\path_of_your_project\.venv\Scripts\activate.bat
C:\path_of_your_project\.venv\Scripts\python.exe C:\path_of_your_project\main.py
call deactivate
  1. For non-virtualized environments, specify the Python executable path and script path.
C:\Users\emeer\AppData\Local\Programs\Python\Python312\python.exe
C:\path_of_your_project\main.py

Scheduling the Batch File

  1. Open the Task Scheduler.

  2. Create a new basic task.

  3. Provide a name and description for the task.

  4. In the "Triggers" tab, choose when to run the task (e.g., daily, weekly, or at startup).

  5. In the "Actions" tab, select "Start a program" and browse to the batch file created earlier.

  6. In the "Conditions" tab, set any conditions for running the task (e.g., network connection or idle status).

  7. Review the task settings and click "Finish" to save the scheduled task.

Now, the Python script will run automatically according to the specified schedule.