A Python utility for AWS cron expressions. Validate and parse AWS EventBridge cron expressions seamlessly.
Project description
AWS Croniter
AWS Croniter is a Python package for parsing, validating, and calculating occurrences of AWS EventBridge cron expressions. AWS cron expressions are a powerful way to schedule events, but they differ from standard Unix cron syntax. This library makes it easy to work with AWS-specific cron schedules programmatically.
Features
- Validate AWS cron expressions against AWS EventBridge syntax.
- Parse and interpret cron rules with detailed validation error messages.
- Compute:
- Next and previous occurrence times for a given schedule.
- All occurrences of a schedule between two given dates.
- Handle special AWS cron syntax (e.g.,
?,L,W,#) and aliases for months (JAN,FEB, ...) and days of the week (SUN,MON, ...).
Installation
Install the package via pip:
pip install aws-croniter
Usage
Here is a basic example of how to use AWS Croniter:
from aws_croniter import AwsCroniter
# Example AWS cron expression
cron_expression = "0 12 15 * ? 2023"
aws_cron = AwsCroniter(cron_expression)
Getting the Next Occurrence
from aws_croniter import AwsCroniter
from datetime import datetime, timezone
# Example AWS cron expression
cron_expression = "0 12 15 * ? 2023"
aws_cron = AwsCroniter(cron_expression)
# Start from a given datetime
start_date = datetime(2023, 12, 14, tzinfo=timezone.utc)
next_occurrence = aws_cron.get_next(start_date)
print(next_occurrence)
## Results in: [datetime.datetime(2023, 12, 15, 12, 0, tzinfo=datetime.timezone.utc)]
Getting the Previous Occurrence
from aws_croniter import AwsCroniter
from datetime import datetime, timezone
# Example AWS cron expression
cron_expression = "0 12 15 * ? 2023"
aws_cron = AwsCroniter(cron_expression)
# Start from a given datetime
start_date = datetime(2023, 12, 14, tzinfo=timezone.utc)
prev_occurrence = aws_cron.get_prev(start_date)
print(prev_occurrence)
## Results in: [datetime.datetime(2023, 11, 15, 12, 0, tzinfo=datetime.timezone.utc)]
Getting All Occurrences Between Two Dates
from aws_croniter import AwsCroniter
from datetime import datetime, timezone
# Example AWS cron expression
cron_expression = "0 12 15 * ? 2023"
aws_cron = AwsCroniter(cron_expression)
from_date = datetime(2023, 11, 14, tzinfo=timezone.utc)
to_date = datetime(2023, 12, 31, tzinfo=timezone.utc)
all_occurrences = aws_cron.get_all_schedule_bw_dates(from_date, to_date)
print(all_occurrences)
## Results in: [datetime.datetime(2023, 11, 15, 12, 0, tzinfo=datetime.timezone.utc), datetime.datetime(2023, 12, 15, 12, 0, tzinfo=datetime.timezone.utc)]
Handling Validation Errors
If an invalid AWS cron expression is provided, AwsCroniter raises specific exceptions indicating the type of error:
from aws_croniter import AwsCroniter
from aws_croniter.exceptions import AwsCroniterExpressionError
try:
invalid_cron = "0 18 ? * MON-FRI" # Missing required fields
AwsCroniter(invalid_cron)
except AwsCroniterExpressionError as e:
print(f"Invalid cron expression: {e}")
## Results in: Invalid cron expression: Incorrect number of values in '0 18 ? * MON-FRI'. 6 required, 5 provided.
Contributing
Contributions are welcome! Please read the contributing guidelines first.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Contact
For any questions or suggestions, please open an issue or contact the maintainer at email@example.com.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aws_croniter-0.2.0.tar.gz.
File metadata
- Download URL: aws_croniter-0.2.0.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e48c8a2eac48ff93e7aa90e2c8a08730d8716fe0f8185a61b73e8105ad579910
|
|
| MD5 |
d79f03421d36d65f5750dcb0a139ca17
|
|
| BLAKE2b-256 |
887ab36acda15cafba405e61cc57261df99d41a616120625c7ff54e2348235a5
|
Provenance
The following attestation bundles were made for aws_croniter-0.2.0.tar.gz:
Publisher:
release.yml on siddarth-patil/aws-croniter
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aws_croniter-0.2.0.tar.gz -
Subject digest:
e48c8a2eac48ff93e7aa90e2c8a08730d8716fe0f8185a61b73e8105ad579910 - Sigstore transparency entry: 158355279
- Sigstore integration time:
-
Permalink:
siddarth-patil/aws-croniter@4a1b5c548ff87f26e91635623bddadbf3a642621 -
Branch / Tag:
refs/tags/0.2.0 - Owner: https://github.com/siddarth-patil
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4a1b5c548ff87f26e91635623bddadbf3a642621 -
Trigger Event:
push
-
Statement type:
File details
Details for the file aws_croniter-0.2.0-py3-none-any.whl.
File metadata
- Download URL: aws_croniter-0.2.0-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a99b4f3bcf7589ae63785290a37154ad3e7176ef44cee01cca12522b233b96a2
|
|
| MD5 |
663f480caf934c883a0cb09df46b015b
|
|
| BLAKE2b-256 |
0162c245488013a37cd03f16a0078a6e27bf5864d5d5f02f856a3446bee9de5f
|
Provenance
The following attestation bundles were made for aws_croniter-0.2.0-py3-none-any.whl:
Publisher:
release.yml on siddarth-patil/aws-croniter
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aws_croniter-0.2.0-py3-none-any.whl -
Subject digest:
a99b4f3bcf7589ae63785290a37154ad3e7176ef44cee01cca12522b233b96a2 - Sigstore transparency entry: 158355282
- Sigstore integration time:
-
Permalink:
siddarth-patil/aws-croniter@4a1b5c548ff87f26e91635623bddadbf3a642621 -
Branch / Tag:
refs/tags/0.2.0 - Owner: https://github.com/siddarth-patil
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4a1b5c548ff87f26e91635623bddadbf3a642621 -
Trigger Event:
push
-
Statement type: