crontab

1.0.5 · active · verified Sat Apr 11

The `crontab` library (from the `josiahcarlson/parse-crontab` project) is a Python package designed to parse crontab schedule entries and determine the next execution time. It calculates delays in seconds until a scheduled event. The current version is 1.0.5, with sporadic but active development and releases.

Warnings

Install

Imports

Quickstart

This example demonstrates how to parse a cron string and calculate its next execution time using the `CronTab` class. It uses `datetime` and `timedelta` to convert the returned delay in seconds into an absolute datetime object.

from crontab import CronTab
from datetime import datetime

# Define a crontab entry for 25 minutes past the hour, every hour
entry = CronTab('25 * * * *')

# Get the next scheduled execution time from now
now = datetime.now()
next_run_time = now + timedelta(seconds=entry.next(now))
print(f"Current time: {now}")
print(f"Next run for '25 * * * *' will be at: {next_run_time}")

# Example with a specific start time
some_past_time = datetime(2023, 1, 1, 10, 15, 0)
next_from_past = some_past_time + timedelta(seconds=entry.next(some_past_time))
print(f"Next run from {some_past_time} would be at: {next_from_past}")

view raw JSON →