Registry / aws / pyawscron

pyawscron

JSON →
library1.0.7pypypi✓ verified 24d ago

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.

pip install pyawscron
INSTALL
IMPORT
SIG · PYAWSCRON
P
pyawscron
awspythonv1.0.7
Install
1.7s avg
Import
21ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.7 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.022s · 18.7MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.7s · import 0.020s · 19MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

AWSCron
from pyawscron import AWSCron

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()
Debug
Known issues
gotchaAWS cron expressions differ significantly from standard Unix cron. Be aware of unique wildcards like '?', 'L', 'W', '#' and different field order/interpretation (e.g., year field is optional in AWS).
fix
Always consult AWS EventBridge/CloudWatch cron documentation. This library is designed specifically for AWS syntax.
affects: <1.0.0
gotchaYou cannot use the '*' wildcard in both the Day-of-month and Day-of-week fields simultaneously. If one is specified with '*', the other must use '?' (question mark).
fix
Ensure that if Day-of-month or Day-of-week has a specific value or '*', the other field uses '?' to indicate 'no specific value'.
affects: All
gotchaThe 'W' wildcard in the Day-of-month field specifies the weekday closest to the given day. For example, '3W' means the weekday closest to the 3rd of the month. Issue 56 (fixed in 1.0.6) addressed cases where 'W' interacted incorrectly with non-existent dates.
fix
Upgrade to 1.0.6 or newer for correct 'W' wildcard behavior. Understand its specific meaning beyond a simple 'weekday'.
affects: <1.0.6
gotchaThe `get_all_schedule_bw_dates` method returns a list of all matching datetimes within a range and has no built-in limit. For large or long date ranges, this can consume significant memory.
fix
For potentially numerous occurrences, prefer `get_next_n_schedule` for an iterative approach or process smaller date ranges.
affects: All
gotchaOlder versions of `pyawscron` (prior to 1.0.7) had stricter dependency constraints on `python-dateutil`, potentially causing conflicts when used in environments with newer `python-dateutil` versions.
fix
Upgrade to `pyawscron` version 1.0.7 or newer to benefit from relaxed `python-dateutil` dependency constraints.
affects: <1.0.7
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pyawscron'
The `pyawscron` library is not installed in your Python environment or the environment where your script is being run.
fix
You need to install the library using pip: `pip install pyawscron`
ValueError: Invalid AWS cron expression: <expression string> - Incorrect number of fields.
The provided cron expression string does not adhere to the expected AWS EventBridge cron format, specifically having an incorrect number of fields (AWS cron expressions typically have 6 or 7 fields).
fix
Ensure your AWS cron expression has the correct number of fields (e.g., 'minutes hours day-of-month month day-of-week year' or 'minutes hours day-of-month month day-of-week'). Refer to AWS documentation for the exact format, e.g., `cron(0 12 * * ? *)` for a 6-field expression.
ValueError: You cannot specify the Day-of-month and Day-of-week fields in the same cron expression. If you use a value in one, you must use '?' in the other.
AWS cron syntax has a specific rule that prevents you from using a specific value (or '*') in both the Day-of-month and Day-of-week fields simultaneously. One must be set to '?' if the other has a specific value or '*'.
fix
Modify your cron expression to use '?' in either the Day-of-month or Day-of-week field if the other field contains a specific value or '*'. For example, `cron(0 10 ? * MON *)` for every Monday at 10:00 UTC.
SyntaxError: invalid syntax
This generic Python error typically occurs when the cron expression string itself is malformed or contains characters that the `pyawscron` parser cannot interpret, or if there's a basic syntactical issue in how the `AWSCron` object is being instantiated.
fix
Carefully review your cron expression for typos, missing quotes, or incorrect characters. Also, check the Python code where `pyawscron.AWSCron()` is called to ensure correct Python syntax (e.g., proper parentheses, string formatting).
Upgrade
Version history
1.0.7latest on PyPI · released Aug 14, 2024
Audit
Dependencies
python-dateutilrequiredCore dependency for date and time calculations in cron parsing. Version 1.0.7 specifically improved compatibility with newer versions of this package.
Agent activity
15 hits · last 30 days
node
12
Resources
pyawscron — pip install pyawscron · libregistry