{"id":4384,"library":"pycron","title":"pycron: Cron-like Parser","description":"pycron is a simple Python library for parsing cron-like expressions and determining if a given datetime matches the specified conditions. It supports standard cron formats, day names, and step values. The current version is 3.2.0, and the library is actively maintained with several releases per year.","status":"active","version":"3.2.0","language":"en","source_language":"en","source_url":"https://github.com/kipe/pycron","tags":["cron","scheduler","datetime","parser","time"],"install":[{"cmd":"pip install pycron","lang":"bash","label":"Install pycron"}],"dependencies":[],"imports":[{"symbol":"is_now","correct":"from pycron import is_now"},{"note":"Used for 'anacron' style checks to see if conditions have been met since a past datetime.","symbol":"has_been","correct":"from pycron import has_been"}],"quickstart":{"code":"import datetime\nfrom pycron import is_now, has_been\n\n# Check if current time (or a specific datetime) matches a cron string\n# This example checks if it's currently every minute\nmatches_every_minute = is_now('* * * * *')\nprint(f\"Matches every minute (current time): {matches_every_minute}\")\n\n# Check for a specific time, e.g., 9:30 AM every weekday\nspecific_dt = datetime.datetime(2023, 10, 26, 9, 30, 0) # Thursday\nmatches_specific_time = is_now('30 9 * * 1-5', specific_dt)\nprint(f\"Matches 9:30 AM on a weekday (2023-10-26 09:30): {matches_specific_time}\")\n\n# Using has_been (anacron style)\n# Check if '0 0 * * *' (midnight) has occurred since an hour ago\nnow = datetime.datetime.now()\none_hour_ago = now - datetime.timedelta(hours=1)\nmidnight_occurred = has_been('0 0 * * *', one_hour_ago, now)\nprint(f\"Midnight occurred between {one_hour_ago.strftime('%H:%M')} and {now.strftime('%H:%M')}: {midnight_occurred}\")","lang":"python","description":"Demonstrates how to use `is_now` to check if a cron expression matches a given datetime (or the current time), and `has_been` for checking if a condition was met within a time range."},"warnings":[{"fix":"Upgrade Python to a supported version (>=3.9, <4.0) or pin `pycron` to an older version like `pycron<3.0.0`.","message":"Version 3.0.0 dropped support for Python 2.7 and Python 3.4. Users on these older Python versions must remain on `pycron < 3.0.0`.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Thoroughly test existing cron expressions when upgrading to `pycron >= 3.1.0` to ensure continued expected behavior, especially for expressions involving specific days of the month or week combinations.","message":"Version 3.1.0 included updates to the DOM (Day of Month) and DOW (Day of Week) parsing logic. While intended for correctness, this might subtly change the interpretation of certain complex or edge-case cron expressions, potentially leading to different match outcomes.","severity":"breaking","affected_versions":">=3.1.0"},{"fix":"Ensure that the datetime objects passed to `is_now` or `has_been` are consistently timezone-aware (preferably UTC) or consistently naive, matching the intended timezone context of your cron expressions.","message":"pycron supports both timezone-aware and naive datetime objects. However, mixing them or not consistently handling timezones can lead to unexpected matches, particularly when cron expressions refer to specific times (e.g., '0 0 * * *' for midnight). The library itself does not perform timezone conversions.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Verify your Python environment meets the `>=3.9, <4.0` requirement before installing `pycron`.","message":"pycron 3.x strictly requires Python versions >=3.9 and <4.0. Attempting to install or run on Python 3.8 or older, or Python 4.0 and newer (when released) without explicit support, will result in installation failures or runtime errors.","severity":"gotcha","affected_versions":">=3.0.0"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}