| single |
# Cron Descriptor
[Python tests]
[Donate]
A Python library that converts cron expressions into human readable
strings. Ported to Python from
https://github.com/bradyholt/cron-expression-descriptor.
**Author**: Adam Schubert (https://www.salamek.cz)
**Original Author & Credit**: Brady Holt (http://www.geekytidbits.com)
**License**: [MIT]
## Features
* Supports all cron expression special characters including * / , - ? L W,
#
* Supports 5, 6 (w/ seconds or year), or 7 (w/ seconds and year) part cron
expressions
* Provides casing options (Sentence, Title, Lower, etc.)
* Localization with support for ~31 languages
* Supports Python 3.10 - 3.13
## Installation
Using PIP
```bash
pip install cron-descriptor
```
Babel is installed automatically. The selected `locale_code` controls
sentence
translations and weekday/month names without changing the process locale.
Missing message catalogs fall back to English. Custom catalogs with a
locale
identifier unknown to Babel retain their messages and use English calendar
names.
## Usage example
### Simple
```python
from cron_descriptor import get_description, ExpressionDescriptor
print(get_description("* 2 3 * *"))
#OR
print(str(ExpressionDescriptor("* 2 3 * *")))
```
### Advanced
```python
# Consult Options.py/CasingTypeEnum.py/DescriptionTypeEnum.py for more info
from cron_descriptor import Options, CasingTypeEnum, DescriptionTypeEnum,
ExpressionDescriptor
descriptor = ExpressionDescriptor(
expression = "*/10 * * * *",
casing_type = CasingTypeEnum.Sentence,
use_24hour_time_format = True
)
# GetDescription uses DescriptionTypeEnum.FULL by default:
print(descriptor.get_description())
print(f"{descriptor = }")
# Or passing Options class as second argument:
options = Options()
options.casing_type = CasingTypeEnum.Sentence
options.use_24hour_time_format = True
descriptor = ExpressionDescriptor("*/10 * * * *", options)
print(descriptor.get_description(DescriptionTypeEnum.FULL))
```
### Expressions with six fields
Set `six_field_expression_has_seconds` to select the format:
- `None` (default): Use the existing automatic format detection.
- `True`: Read the fields as seconds, minutes, hours, day of month, month,
and day of week.
- `False`: Read the fields as minutes, hours, day of month, month, day of
week, and year.
This option applies only to expressions with six fields.
```python
from cron_descriptor import ExpressionDescriptor, Options, get_description
options = Options(locale_code="en_US",
six_field_expression_has_seconds=False)
print(get_description("* * * * * *", options)) # Every minute
# Set the option with an ExpressionDescriptor keyword argument.
descriptor = ExpressionDescriptor(
"* * * * * *",
locale_code="en_US",
six_field_expression_has_seconds=False,
)
print(descriptor.get_description()) # Every minute
|