There are very few utility programs as useful as cron in all computer systems based on Unix. It's designed is to schedule commands to run at a specific time. This type of scheduled command or task is called a "cron job".
cron is used to run scheduled backups, monitor disk space, clean old logs files and residue periodically, perform system maintenance tasks, and a lot more. Developers can easily send commands directly to
cron to create and manage cron jobs, as it's included in most Linux distro.
This article lists the best 5 mature and actively maintained Python package that can be used to work with cron jobs from inside your Python application.
cronutils is a Python package designed to simplify the configuration and dispatching of tasks via cron, as well as to give nicely formatted error reports by mail.
If what you want to do is simply creating and managing cron jobs, cronutils is the perfect choice. Some of its features are email error reporting (with the help of cronic), automatic process killing if a task takes longer than expected to run, error aggregation, Sentry and Django integration.
In order to use cronutils, Ubuntu/Debian users can install the dependencies using the following command.
sudo apt-get install sendmail mailutils moreutils
pip install cronutils
Project Repository and Documentation : https://github.com/zagaran/cronutils
Python-Crontab is a Python package that allows for reading and writing crontab configuration, i.e. cron jobs, programmatically using a direct API.
The package supports both Python 3 (3.5 to 3.7) and Python 2.7. Windows has limited support for only non-system crontabs. SystemV based platform is also supported, inclusing SunOS, AIX and HP.
Below is a simple example on how we would use Python-Crontab in a program.
from crontab import CronTab cron = CronTab(user='root') job = cron.new(command='echo hello_world') job.minute.every(1) cron.write()
pip install python-crontab
Project Repository and Documentation : https://gitlab.com/doctormo/python-crontab
django-cron is a Python package developed by Tivix that lets you run Django/Python code periodically, providing basic plumbing to track and execute tasks.
The 2 most common ways to tackle the above problem is to either writing custom Python scripts or a management command per cron (leads to too many management commands!). Along with that some mechanism to track success, failure etc. is also usually necesary. django-cron app solves both issues to a reasonable extent.
pip install django-cron
Project Repository and Documentation : https://github.com/tivix/django-cron
aiocron - Crontabs for asyncio
There are two ways you can use aiocron programmatically, the first way is a decorator to run function at time,
@aiocron.crontab('*/30 * * * *') async def attime(): print('run')
and the second way to use it is through
await crontab('0 * * * *').next()
pip install aiocron
Project Repository and Documentation : https://github.com/gawel/aiocron
nb_cron is a small Jupyter extension that allows you to managing cron jobs from within Jupyter. The extension adds a tab named Cron to the Jupyter file browsers. In that tab, you can view the list of the current cron jobs, edit or delete them or add a new one.
In order to install nb_cron, you have to install the actual package using
pip first, then add it to Jupyter using
pip install nb_cron jupyter nbextension install nb_cron --py --sys-prefix --symlink jupyter nbextension enable nb_cron --py --sys-prefix jupyter serverextension enable nb_cron --py --sys-prefix
Project Repository and Documentation : https://github.com/alexanghh/nb_cron