Skip to content

Using the schedule Library for Python

Why schedule

It’s simple for:

  • β€œrun every hour”
  • β€œrun at 09:00 daily”

Example

schedule_example.py
import schedule
import time
 
 
def job():
    print("running")
 
 
schedule.every(10).seconds.do(job)
 
while True:
    schedule.run_pending()
    time.sleep(1)
schedule_example.py
import schedule
import time
 
 
def job():
    print("running")
 
 
schedule.every(10).seconds.do(job)
 
while True:
    schedule.run_pending()
    time.sleep(1)

Notes

  • this keeps a process running
  • for server deployment, cron/systemd is usually better

πŸ§ͺ Try It Yourself

Exercise 1 – List Files with os.listdir

Exercise 2 – Join Paths with os.path.join

Exercise 3 – Write and Read a File

If this helped you, consider buying me a coffee β˜•

Buy me a coffee

Was this page helpful?

Let us know how we did