In this tutorial, you will learn how to schedule Python scripts through Windows Scheduler.
Sometimes, you need to call an API after a specific interval of time. For example, if you want to
execute a Python script every hour in a Windows machine, then you need to use Windows Scheduler.
Steps: Here are steps to schedule a Python script using Windows Scheduler.
- First, you need to prepare a Python script that you need to execute.
In our example, I’ll use the script to display the label ‘Hello World!.’
- Once you’re done writing the script, save it as a Python file (which should have the .py file type):
- After that, you need to create a batch file to run the Python script. That contains
"Python exe path stored in system \python.exe" "Python script path stored \script name.py"
In my case- Path of Python exe is:
“C:\Users\ComputerName\AppData\Local\Programs\Python\Python37-32\python.exe” - Path of Python script is, (see step-2):
“C:\Users\ComputerName\Desktop\Hello_World.py”
- Path of Python exe is:
- Save this file with a .bat extension. Like FileName.bat
- Additionally, You need to add a pause command at the end of the bat file. It will keep the command line open until the key action will be performed by the user.
- Schedule Python Script using Windows Scheduler
For this step, I’m using Windows 10 to execute the Python Script via the Windows Task Scheduler. Open Control Panel after that click on Administrative Tools:
Then click on Task Scheduler to create basic tasks
Then click on
Type a name for your task (you can type any description), and then press Next.
I have named the task as Run Hello World
Next, I chose to start the task ‘Daily’ since we wish to run the Python script daily at 6 am:
After that Fill in the Start Date and Time.
The action will then recur every day at 6 am, starting from 2021-04-12.
Select, Start a program, and then press Next:
After that, add the path of your batch file
Then click next and press the Finish Button
From now, the Python script will run every day at 06:00 AM.
Note: You can edit the scheduler according to your need at any time.
The English language is the most widely used language as a medium of communication around the world. Having a certification for the English language can be an advantage. StudySection provides an English Certification Exam that tests English language proficiency in English grammar, reading, and writing.