tzcron is a Python library that provides a way to define schedules using cron/quartz expressions and attach them to specific timezones. It allows users to iterate over a schedule object to get future time occurrences, serving as a powerful cron parser without implementing scheduling capabilities itself. The current version is 1.0.0. The library appears to have a stable, though infrequent, release cadence, with the last update in 2016.
pip install tzcronVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create timezone-aware cron schedules using `tzcron`. It shows how to initialize a schedule with a cron expression and a `pytz` timezone, and then retrieve future occurrences by iterating or using `get_next_occurrence`.
Thoroughly test with your target Python environment and consider the implications of using an unmaintained library. Review dependencies like `pytz` for their maintenance status and alternatives like `zoneinfo`.
Always ensure `import pytz` is present and pass a valid `pytz.timezone` object to `tzcron.Schedule`. For example: `tzcron.Schedule('0 0 * * *', pytz.utc)`.When deploying actual cron jobs based on `tzcron`'s output, ensure the `crontab` entry specifies full paths to executables and scripts, sets necessary environment variables, and redirects output for debugging. For example, explicitly setting `PATH` within the `crontab` file.
Ensure `pytz` is installed (`pip install pytz`) and `import pytz` is present in your code before using `tzcron.Schedule`.
To get the next occurrence, use `next(schedule_object)` or `schedule_object.get_next_occurrence()`. If iterating, ensure you handle potential infinite sequences with a loop limit (e.g., `itertools.islice` or a `for i in range(n):`).
Use the `ambiguity_handler` parameter when creating the `Schedule` object, providing a callable that resolves the ambiguity. For example, `tzcron.Schedule(..., ambiguity_handler=tzcron.use_first_occurrence_of_ambiguous_time)` or `tzcron.Schedule(..., ambiguity_handler=tzcron.use_last_occurrence_of_ambiguous_time)`.
No resource links recorded.