How to automate scheduled running of a Python Notebook

Kundan Kumar
3 min readDec 6, 2020

--

Here is the process to automate or schedule running of Python script or a Jupyter notebook using Task Scheduler

Task scheduler is for windows only, for linux and Mac you can try https://snapcraft.io/mkcron and https://apple.stackexchange.com/questions/4714/os-x-is-there-a-built-in-scheduler-program.

This will work for both python script and a Jupyter notebook.

Step 1

In case of Jupyter notebook first convert it into a python script by going to file then download as python file.

Download a Jupyter notebook as a python file

Step 2

Now open Task scheduler and click on Task Scheduler Library.

  1. Then on the right menu click on create task.

2. Then give the task a name as description

It will look something like this
create task dialog box

Step 2

You will need to have certain locations before moving forward

  1. Location of installation of python interpreter : type where python in cmd to get the location
  2. Location of the python script
location of interpretor
location of the python script also note the name of the script

Step 3

Goto Action section of the task scheduler, here we will tell the task scheduler what to do, click on new

  1. Inside the Program/script box paste the location of python interpreter
  2. Inside Start in: add the location where the python file is
  3. And finally inside the Add Arguments box paste the name of the python file
  4. press ok
Creating Action for the scheduler

Step 4

Now go to the Triggers section and click new, we will set the schedule for which the program should run

  1. Select Weekly or daily or monthy depending on your requiments
  2. Select the time when the script should start
  3. optional set the expiration date

In my case I chose the script to run on every Monday, Tuesday, Wednesday and Friday at 8 hours, with no expiration date

creating trigger for the script

Finally

The new task will be created and status will tell if its ready or not, and the next run time will shown.

Scheduled Task created

To make your task a bit more better you can add a code to show notification at the end of execution.

task running along with notification

You can also add several print statements inside the python script file to see your progress when the script is executed.

--

--