crontools is a library that allows you to parse crontab expression and iterate over scheduled fire times.
Features:
crontab expression parser
optional seconds field support
optional year field support
crontab fire time sequential iteration support
Installation
You can install crontools with pip:
$ pip install crontools
Quickstart
Get next cron fire time:
>>> import datetime as dt
>>> import crontools as ct
>>>
>>> tz = dt.timezone.utc
>>> now = dt.datetime.fromisoformat('2020-02-29 23:59:59.999+00:00')
>>> ct = ct.Crontab.parse(
... '* * * * * * *',
... seconds_ext=True,
... years_ext=True,
... tz=tz,
... )
>>>
>>> print(f"Next fire time: {ct.next_fire_time(now=now)}")
Next fire time: 2020-03-01 00:00:00+00:00
Iteration over cron fire times starting from now:
>>> import crontools as ct
>>>
>>> tz = dt.timezone.utc
>>> now = dt.datetime.fromisoformat('2021-02-01 00:00:00+00:00')
>>> ct = ct.Crontab.parse(
... '30 30 12-16/2 1,2 JAN SAT,SUN *',
... seconds_ext=True,
... years_ext=True,
... tz=tz,
... )
>>>
>>> cron_iter = ct.iter(start_from=now)
>>> for n, fire_datetime in zip(range(1, 31), cron_iter):
... print("{n:2}: {dt}".format(n=n, dt=fire_datetime))
...
...
1: 2022-01-01 12:30:30+00:00
2: 2022-01-01 14:30:30+00:00
3: 2022-01-01 16:30:30+00:00
4: 2022-01-02 12:30:30+00:00
5: 2022-01-02 14:30:30+00:00
6: 2022-01-02 16:30:30+00:00
7: 2022-01-08 12:30:30+00:00
8: 2022-01-08 14:30:30+00:00
9: 2022-01-08 16:30:30+00:00
10: 2022-01-09 12:30:30+00:00
11: 2022-01-09 14:30:30+00:00
12: 2022-01-09 16:30:30+00:00
13: 2022-01-15 12:30:30+00:00
14: 2022-01-15 14:30:30+00:00
15: 2022-01-15 16:30:30+00:00
16: 2022-01-16 12:30:30+00:00
17: 2022-01-16 14:30:30+00:00
18: 2022-01-16 16:30:30+00:00
19: 2022-01-22 12:30:30+00:00
20: 2022-01-22 14:30:30+00:00
21: 2022-01-22 16:30:30+00:00
22: 2022-01-23 12:30:30+00:00
23: 2022-01-23 14:30:30+00:00
24: 2022-01-23 16:30:30+00:00
25: 2023-01-01 12:30:30+00:00
26: 2023-01-01 14:30:30+00:00
27: 2023-01-01 16:30:30+00:00
28: 2023-01-02 12:30:30+00:00
29: 2023-01-02 14:30:30+00:00
30: 2023-01-02 16:30:30+00:00
Metadata
Release files for crontools 0.1.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| crontools-0.1.6.tar.gz | 8.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| crontools-0.1.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.4 kB
Release files / crontools-0.1.6.tar.gz
| Download URL | crontools-0.1.6.tar.gz |
|---|---|
| Size | 8.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
41446c73d06b21e373663dc229f36139c587bc57179889da37c2844a9c881662
|
|
BLAKE2b-256 checksum How to use checksums |
d78277c9d5145fd789c63b4779f29c92bd22060a2b7a8476415819b13120f3e3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.3.2 CPython/3.11.2 Linux/5.15.0-1033-azure
|
Release files / crontools-0.1.6-py3-none-any.whl
| Download URL | crontools-0.1.6-py3-none-any.whl |
|---|---|
| Size | 7.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6fbe2e2822722fb7986022790ba413d6dafaa880f75840147c27b26912868784
|
|
BLAKE2b-256 checksum How to use checksums |
45544b44f1c4fb21d681bedff91a429f4205bda64abba06f97b1f591c083c814
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.3.2 CPython/3.11.2 Linux/5.15.0-1033-azure
|