AWS Cron Parser

1.0.7 · active · verified Mon Apr 13

pyawscron is a Python library that parses and interprets AWS EventBridge (formerly CloudWatch Events) cron expressions. It supports all AWS-specific cron syntax, including special wildcards like 'L', 'W', and '#', and can calculate next, previous, or all occurrences within a date range. The current version is 1.0.7, with releases addressing compatibility and parsing nuances.

Warnings

Install

Imports

Quickstart

Initializes an AWSCron object with an AWS-specific cron expression and demonstrates how to retrieve the next `n` schedule occurrences. It highlights the use of `datetime` objects with timezone information.

import datetime
from pyawscron import AWSCron

def main():
    # An AWS cron expression: at 05:00 AM (UTC) on the 4th of every month.
    # '?' in day-of-week indicates "no specific day of the week" to avoid conflict
    aws_cron = AWSCron("0 5 4 * ? *")

    # Get the next 5 schedule occurrences from a specific start time
    start_dt = datetime.datetime.utcnow().replace(second=0, microsecond=0, tzinfo=datetime.timezone.utc)
    print(f"Next 5 occurrences from {start_dt.isoformat()}:")
    for dt in aws_cron.get_next_n_schedule(start_dt, 5):
        print(dt)

if __name__ == "__main__":
    main()

view raw JSON →