{"id":2904,"library":"cron-converter","title":"Cron-converter","description":"Cron-converter is a Python library that provides a cron string parser and scheduler. It allows parsing cron expressions from strings or lists and iterating over datetime objects in a cron-like format. It is a transposition of the JavaScript cron-converter library and is currently at version 1.3.1, actively maintained with regular releases.","status":"active","version":"1.3.1","language":"en","source_language":"en","source_url":"https://github.com/Sonic0/cron-converter","tags":["cron","scheduler","parser","datetime","utility"],"install":[{"cmd":"pip install cron-converter","lang":"bash","label":"Install stable release"}],"dependencies":[{"reason":"Used for timezone-aware datetime operations within the scheduler.","package":"python-dateutil"}],"imports":[{"symbol":"Cron","correct":"from cron_converter import Cron"}],"quickstart":{"code":"from cron_converter import Cron\nfrom datetime import datetime\nfrom itertools import islice\nimport dateutil.tz # Dependency for timezone-aware operations\n\n# Example 1: Basic cron parsing and iteration (UTC)\ncron_expression_str = '*/10 9-17 * * MON-FRI'\ncron_instance = Cron(cron_expression_str)\n\nprint(f\"Cron expression: {cron_instance.to_string()}\")\nprint(f\"Cron list representation: {cron_instance.to_list()}\")\n\n# Get a schedule iterator, starting from a specific datetime\nstart_time = datetime(2026, 4, 14, 8, 0, 0, tzinfo=dateutil.tz.UTC)\n# The schedule iterator is infinite, use islice or explicit breaks\nschedule = cron_instance.schedule(start_time)\n\nprint(f\"Next 5 scheduled times after {start_time}:\")\nfor i, next_run in enumerate(islice(schedule, 5)):\n    print(f\"  {i+1}: {next_run}\")\n\n# Example 2: With constructor options (outputting names)\ncron_with_names = Cron('*/5 9-17 * 1-3 MON-FRI', {\n    'output_weekday_names': True,\n    'output_month_names': True\n})\nprint(f\"Cron with names: {cron_with_names.to_string()}\")","lang":"python","description":"This quickstart demonstrates how to initialize a `Cron` object with a cron string, retrieve its string and list representations, and iterate over upcoming scheduled times using the `schedule` method. It also shows how to use constructor options for named output and highlights the importance of using `itertools.islice` or similar mechanisms when iterating over the (infinite) schedule."},"warnings":[{"fix":"Wrap the `schedule()` call with `itertools.islice(cron_instance.schedule(start_date), num_iterations)` or add manual break logic within your loop.","message":"The `schedule()` method returns an infinite iterator. To avoid unbounded loops, always use limiting mechanisms like `itertools.islice()` or implement explicit break conditions.","severity":"gotcha","affected_versions":"1.3.0 and later (since Seeker object implements Iterator protocol)"},{"fix":"When calling `cron_instance.schedule()`, pass a `datetime` object with `tzinfo` set, e.g., `datetime.now(pytz.timezone('America/New_York'))` or `datetime.now(dateutil.tz.gettz('Asia/Tokyo'))` if using `python-dateutil`.","message":"For correct handling of Daylight Saving Time (DST) and timezone conversions, initialize your `Cron` instance's `schedule` method with a timezone-aware `datetime` object or specify a `timezone_str`. By default, `schedule` starts with a UTC datetime.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Update imports and refactor code to use `cron-converter`'s `Cron` class and `schedule()` method. Refer to `cron-converter` documentation for specific API changes.","message":"`cron-converter` has been recommended as a replacement for the `croniter` library, which is set to be decommissioned. Users migrating from `croniter` should be aware of API differences.","severity":"deprecated","affected_versions":"Users of `croniter`"},{"fix":"Pass a dictionary of options to the `Cron` constructor: `cron_instance = Cron('...', {'output_weekday_names': True})`.","message":"Constructor options like `output_weekday_names`, `output_month_names`, and `output_hashes` are available to modify the output format of the cron string. These are `false` by default.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}