cron-validator is a Python library providing tools for validating Unix cron expressions, matching specific datetimes against a cron pattern, and generating a sequence of datetimes that fulfill a given cron expression. It also includes a `CronScheduler` for simple task scheduling. Currently at version 1.0.8, the library receives regular, minor updates primarily for bug fixes and feature enhancements, such as extended cron rule support.
pip install cron-validatorVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to validate cron expressions, check if a specific datetime matches a cron expression, and generate future execution times within a given range.
Consult the library's GitHub README for specific syntax support. Test cron expressions thoroughly if migrating from other cron systems.
Integrate `CronScheduler.time_for_execution()` checks into an existing event loop or use a separate thread/process to prevent blocking your main application.
Upgrade to version 1.0.7 or later to use named values. For older versions, use numeric representations (e.g., `1-12` for months, `0-6` or `1-7` for days of week).
Upgrade to version 1.0.1 or later to ensure all generated execution datetimes are minute-aligned (seconds and microseconds set to 0). If using older versions, manually normalize the datetimes if minute-level precision is critical.
Install the library using pip: `pip install cron-validator`
Review the cron string for syntax errors, out-of-range values (e.g., day of month > 31, hour > 23), or incorrect number of fields. Use an online cron validator to help identify issues.
Always check if `CronValidator.parse()` returned a valid object (not `None`) before attempting to use its methods. For example: `cron_expression_obj = CronValidator.parse(cron_string); if cron_expression_obj: # proceed with using cron_expression_obj`
No dependency data recorded yet.