Cron Descriptor
A Python library that converts cron expressions into human readable strings. As of version 2.0.8, it supports Python 3.9 - 3.14 and offers localization for approximately 31 languages. The library is actively maintained with frequent releases.
Warnings
- breaking The parsing of cron expressions moved from `ExpressionDescriptor.get_description()` to the `ExpressionDescriptor` constructor in version 1.3. This means parsing exceptions are now thrown when creating an `ExpressionDescriptor` instance, not when calling `get_description()`. Update your exception handling logic accordingly.
- breaking The `throw_exception_on_parse_error` option was removed in version 1.3. The library now always throws an exception if a cron expression cannot be parsed, effectively behaving as if `throw_exception_on_parse_error=True`.
- breaking In version 2.0.3, the `Options` constructor parameters (`locale_code`, `use_24hour_time_format`) now explicitly override auto-detected system locale settings. If you previously relied on auto-detection and then set these in `Options` objects, their behavior might change to reflect the explicit settings.
- breaking Custom exceptions within the library were renamed from `*Exception` (e.g., `CronDescriptorException`) to `*Error` (e.g., `CronDescriptorError`) in version 2.0.3. Update `except` clauses to catch the new exception names.
- gotcha Using both Day of Month and Day of Week fields with explicit values (e.g., `1 1 1 1 1`) can be ambiguous in cron. While this library generally handles `?` to signify 'no specific value' for one of them, be aware that other cron parsers or environments might have different interpretations or stricter validation.
Install
-
pip install cron-descriptor
Imports
- get_description
from cron_descriptor import get_description
- ExpressionDescriptor
from cron_descriptor import ExpressionDescriptor
- Options
from cron_descriptor import Options
- CasingTypeEnum
from cron_descriptor import CasingTypeEnum
- DescriptionTypeEnum
from cron_descriptor import DescriptionTypeEnum
Quickstart
from cron_descriptor import get_description, ExpressionDescriptor, Options, CasingTypeEnum, DescriptionTypeEnum
# Simple usage
print(get_description("* 2 3 * *"))
# Using ExpressionDescriptor class
descriptor_instance = ExpressionDescriptor("* 2 3 * *")
print(str(descriptor_instance))
# Advanced usage with Options
options = Options()
options.casing_type = CasingTypeEnum.Sentence
options.use_24hour_time_format = True
options.locale_code = 'en' # Explicitly set locale for consistency
advanced_descriptor = ExpressionDescriptor("*/10 * * * *", options)
print(advanced_descriptor.get_description(DescriptionTypeEnum.FULL))