Skip to main content

Build Status pypi  GitHub license 

cronpi

A small tool for deploying crontab jobs into a unix-like system, eg. Linux/Mac from python.

cronpi makes jobs more human readable and works on both 2.X and 3.X version.

Installation

pip install cronpi

Usage

cronpi has following functions

SN Name Description
1. run_by_date job that runs just by setting date in format YYYY-MM-DD HH:mm
2. run_every_day job that runs every day at given time HH:mm
3. run_every_week job that runs every week at the given time of given weekdays
4. run_every_month job that runs every month at the given time of given days of a month
5. run_every_year job that runs at the given time of given days of given months
6. run_custom command will be exactly similar to single line which we write during "crontab -e"

Each functions take two parameters

<command to execute>, <isOverwrite=bool>?
parameter type description
command string This command will be executed as scheduled
isOverwrite bool It is optional and default value is false, which means cronpi will always insert new job

cronpi will always install a new cron job if only command is passed as parameter or isOverwrite is set to False. If command passed as first parameter already exists in cronjon and "isOverwrite=True" is passed as second parameter ,then it will update the time of running the job instead of adding new job.

cronpi.XXXX("/some/command", isOverwrite=True)

Time used as parameter can contain or may not contain AM|PM prefix. For eg, following two parameters represent same time.

5:30pm = 17:30

Use Case 1 - Run By Date

  1. Run a job at 20th october 2020 at 5:30PM
import cronpi
cronpi.run_by_date("/some/command").on("2020-10-20 5:30pm")

※ This command will run every year after if the command is not deleted from crontab manually.

Use Case 2 - Run every day

  1. Run a job daily at 5:30PM
import cronpi
cronpi.run_every_day("/some/command").on("5:30pm")

Use Case 3 - Run every week

  1. Run a job at every sunday at 5:30PM
import cronpi
cronpi.run_every_week("/some/command").on("sunday", time="17:30")
  1. Run a job at every saturday and sunday at 5:30PM
import cronpi
cronpi.run_every_week("/some/command").on(["sat", "sun"], time="5:30PM")

Use Case 4 - Run every month

  1. Run a job at every 10th of a month at 5:30PM
import cronpi
cronpi.run_every_month("/some/command").on(10, time="17:30")
  1. Run a job at every 10th and 20th of a month at 5:30PM
import cronpi
cronpi.run_every_month("/some/command").on([10,20], time="17:30")

Use Case 5 - Run every year

  1. Run a job at every 10th january at 5:30am
import cronpi
cronpi.run_every_year("/some/command").on("january", day=10, time="5:30am")
  1. Run a job at every 10th of january, april and october at 5:30AM
import cronpi
cronpi.run_every_year("/some/command").on(["jan", "oct"], day=10, time="5:30")

Use Case 6 - run like crontab

Add a job to crontab by passing the command that we input to "crontab -e" command.

  1. Run a job that runs at every minute
import cronpi
cronpi.run_custom("* * * * * /some/command")
# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12)
# │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday;
# │ │ │ │ │                                   7 is also Sunday on some systems)
# │ │ │ │ │
# │ │ │ │ │
# * * * * * command to execut

Helper Function - Get list of current jobs

cronpi has a helper function named "get_job_list" which will retrive the the job items in list.

import cronpi
cronpi.get_job_list()

Release information

Nov 12th, 2019 (ver@2.0.0)

  • restructured the library format so that it is more human readable.
    cronpi.run_every_month("/some/command")
        .on([10,20], time="1:30AM")

Nov 7th, 2019 (ver@1.0.0)

  • released first version

Metadata

Release files for cronpi 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cronpi 2.0.1
File Size Uploaded
cronpi-2.0.1.tar.gz 8.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cronpi 2.0.1
File Interpreter ABI Platform
cronpi-2.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 18.5 kB

Release files / cronpi-2.0.1.tar.gz

Download URL cronpi-2.0.1.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f01553594e3bdf3f2f2750d84a4a7ef9e6d801e861abeb2e5857d69aed67f6b0
BLAKE2b-256 checksum
How to use checksums
e47231171460dbf78323582f7ad4e1c8f2e426c69bb1e7306d80d04b462bac9c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.6.9

Release files / cronpi-2.0.1-py3-none-any.whl

Download URL cronpi-2.0.1-py3-none-any.whl
Size 10.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ca766233216e00937cd1a6d5cc18cb5c3cea80c80024f71bcbc1b02f57259b68
BLAKE2b-256 checksum
How to use checksums
9a2df52de2a6f6f9f675aa01e8be66c925c855deaf57d955fd23de1e60556251
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.6.9

Release history Release notifications | RSS feed

This release

2.0.1 This release

2 release files

2.0.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page