For production ready tool that is pure python, I would use airflow
. Airflow is pure Python pipelines orchestral tool that will allows building of pipelines/dags/jobs with beautiful UI
to see how the tasks are doing, plus aREST-APIs to interact with tasks from other tools.
For simple things, there multiple libraries: examples:
You could use schedule
. It’s available via python -m pip install --user schedule
import schedule
import time
def file_loader():
print("I'm loading files...")
schedule.every().day.at("12:00").do(file_loader)
schedule.every().day.at("0:00").do(file_loader)
while True:
schedule.run_pending()
time.sleep(1)
Anothe tool is apscheduler
also in PyPI pip install apscheduler
from pytz import utc
from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.jobstores.sqlalchemy import SQLAlchemyJobStore
from apscheduler.executors.pool import ProcessPoolExecutor
jobstores = {
'mongo': {'type': 'mongodb'},
'default': SQLAlchemyJobStore(url='sqlite:///jobs.sqlite')
}
executors = {
'default': {'type': 'threadpool', 'max_workers': 20},
'processpool': ProcessPoolExecutor(max_workers=5)
}
job_defaults = {
'coalesce': False,
'max_instances': 3
}
scheduler = BackgroundScheduler()
scheduler.add_job(file_loader, 'cron', hour=12, id='file_loader_id_12')
scheduler.add_job(file_loader, 'cron', hour=0, id='file_loader_id_24')
scheduler.configure(jobstores=jobstores, executors=executors, job_defaults=job_defaults, timezone=utc)
scheduler.start()