croniter

Parses cron schedule strings and iterates the matching datetime values, with DST, second/year fields, and last-weekday support.

Library
PyPI
v6.2.4
562 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
73 /100 Good
Development Activity 76
Maintenance 56
Community 76
Maturity 56
Momentum 28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
75 /100 Good
Architecture 78
Code Quality 88
Innovation 80
Learning Curve 55

croniter takes a standard (or extended) cron expression and a starting datetime, then walks forward or backward to the exact moments the schedule fires. It’s the parsing and iteration engine underneath most Python scheduling code: task queues computing the next run for a periodic job, cron-expression validators in web UIs, and dashboards that need to show “next 5 runs” for a saved schedule.

Beyond the standard five-field Unix syntax, it supports optional seconds and year fields, last-day-of-month (l), nearest-weekday (W), Nth-weekday-of-month (#), hash-based expressions for spreading load across a fleet (H / @hourly-style), configurable AND/OR semantics between day-of-month and day-of-week, and DST-aware iteration when given timezone-aware datetimes.

What You Get

  • A croniter class that wraps a cron expression and a start time, exposing get_next() / get_prev() to step through matching datetimes or Unix timestamps
  • croniter.is_valid() and croniter.expand() classmethods for validating and introspecting a cron string before scheduling it, including opt-in strict=True cross-field validation (rejects impossible dates like Feb 31)
  • Extended syntax beyond POSIX cron: optional seconds and year fields, l (last day of month), W/nW (nearest weekday), # (Nth weekday of month), and hash-based expressions (H, @hourly with a hash_id) for staggering many jobs’ fire times
  • day_or and implement_cron_bug flags to control whether day-of-month and day-of-week combine with OR (POSIX default) or AND (fcron-style), including reproducing a known vixie-cron quirk for compatibility
  • Full timezone/DST awareness via zoneinfo, pytz, or dateutil.tz when a timezone-aware start_time is supplied
  • croniter_range() helper and the iterator protocol (all_next()/all_prev()) for pulling a bounded or unbounded sequence of fire times directly in a for loop

Common Use Cases

  • Computing a job’s next scheduled run inside a task queue or scheduler (Celery beat, Airflow, custom cron-like schedulers) without shelling out to system cron
  • Validating user-submitted cron expressions in a web form or admin UI before saving a scheduled job
  • Generating a preview list of upcoming run times (“next 5 executions”) for a saved schedule shown in a dashboard
  • Staggering many periodic jobs across a time window using hash-based (H) expressions so they don’t all fire at the same instant
  • Backfilling or auditing historical run times for a cron-scheduled job by iterating backward with get_prev()

Under The Hood

Architecture croniter centers on a single croniter class (src/croniter/croniter.py, ~1,600 lines) that does two things: expand a cron expression string into per-field integer sets (_expand, feeding expanded, nth_weekday_of_month, and nearest_weekday state), then walk forward or backward from a timestamp field-by-field (proc_year/proc_month/proc_day_of_month/proc_day_of_week/proc_hour/proc_minute/proc_second closures inside _calc_next) until every field matches. A separate HashExpander class isolates the hash-based (H, @hourly) expansion logic from the core matching loop, keeping that fairly niche feature from complicating the primary code path. get_next/get_prev are thin wrappers over a shared _get_next, and all_next/all_prev turn that into a generator for the iterator protocol. The design is intentionally a single cohesive module rather than a layered system — appropriate for a focused parsing/iteration library where the field-matching state machine is the entire product.

Tech Stack Pure Python (3.9+) with exactly one runtime dependency, python-dateutil, used for relativedelta (DST-safe date arithmetic) and tzutc/datetime_exists (DST-transition detection). No C extensions. Packaged with hatchling and uv-managed dependency groups (dev, lint, mypy, format, tox, release); tox.ini wires pytest+coverage for tests, ruff for lint and formatting, and mypy for type-checking into a single tox -e lint,mypy,fmt gate.

Code Quality 161 test functions spread across purpose-specific files (test_croniter.py, test_croniter_range.py, test_croniter_dst_repetition.py, test_croniter_hash.py, test_croniter_random.py, plus a test_croniter_speed.py performance check), run via pytest with branch coverage. A dedicated custom exception hierarchy (CroniterError, CroniterBadCronError, CroniterBadDateError, CroniterBadTypeRangeError, CroniterNotAlphaError, CroniterUnsupportedSyntaxError) replaces generic ValueErrors with specific, catchable failure modes. CI (cicd.yml) runs the lint/mypy/format gate plus the full test suite across Python 3.9 through 3.13, and a separate zizmor.yml workflow scans the GitHub Actions workflows themselves for supply-chain issues — a level of CI hygiene beyond most libraries this size.

API Design The public surface is deliberately small: construct a croniter(expr, start_time), then call get_next()/get_prev() repeatedly, or use it directly as an iterator. Sensible defaults (POSIX OR semantics, ret_type=float) mean the common case needs no keyword arguments, while power users get explicit opt-in flags (day_or, hash_id, implement_cron_bug, expand_from_start_time, second_at_beginning) for the less common behaviors. The README documents every extended feature with runnable, copy-pasteable examples rather than prose-only explanation, which keeps the learning curve low despite the fairly deep feature set (leap years, DST, hash expressions, AND/OR day semantics) hiding underneath.

Used by 15 apps in this directory

TypeScript
56%
Other

agenta

AI Development · Developer Tools · Devops

4,788

The open-source LLMOps platform unifying prompt engineering, evaluation, and observability for teams building reliable LLM applications.

View details
91
Repo Health
77
Technical
67
Dependency
Built with
TypeScript 56%
Python 39%
Updated 1 weeks ago
Python
100%
Apache 2.0

Agno

AI Development · Automation · Devops

42,358

Build, run, and manage agent platforms with a full production stack — SDK, runtime, and control plane included.

View details
93
Repo Health
87
Technical
66
Dependency
Built with
Python 100%
Updated 1 weeks ago
Python
89%
Apache 2.0

Apache Airflow

Data Engineering

46,995

Define, schedule, and monitor complex data workflows as Python code — with a powerful UI, 80+ provider integrations, and battle-tested scalability across thousands of production deployments.

View details
96
Repo Health
89
Technical
64
Dependency
Built with
Python 89%
Updated 1 weeks ago
Python
68%
MIT

ArchiveBox

Bookmarks Archiving

28,636

Self-hosted web archiving that saves HTML, PDFs, screenshots, media, and code in open formats you own forever

View details
88
Repo Health
84
Technical
69
Dependency
Built with
Python 68%
HTML 25%
Updated 1 weeks ago
Python
66%
Other

AutoGPT

AI Assistants · Automation · Productivity

187,596

Build, deploy, and run autonomous AI agents that automate complex multi-step workflows using a visual block-based graph editor.

View details
93
Repo Health
78
Technical
66
Dependency
Built with
Python 66%
TypeScript 33%
Updated 1 weeks ago
Go
84%
AGPL 3.0

Beta9

AI Development · Automation · Data Engineering

1,794

Run AI workloads at scale with a Pythonic serverless runtime that handles GPU inference, background jobs, and sandboxes with zero infrastructure overhead.

View details
85
Repo Health
78
Technical
66
Dependency
Built with
Go 84%
Python 15%
Updated 1 weeks ago
Python
90%
MIT

Cronboard

Developer Tools · Devops

1,456

A keyboard-driven terminal dashboard for managing cron jobs on local machines and remote servers via SSH.

View details
79
Repo Health
74
Technical
75
Dependency
Built with
Python 90%
Updated 2 weeks ago
TypeScript
50%
Other

Dify

AI Development · Design Tools · Developer Tools

157,364

Visual LLM workflow platform with RAG pipelines, agent capabilities, and model management for building production AI applications.

View details
92
Repo Health
85
Technical
66
Dependency
Built with
TypeScript 50%
Python 47%
Updated 1 weeks ago
Python
65%
MIT

Flowfile

Data Engineering

363

Visual ETL that compiles to Polars — build pipelines on a canvas, export as standalone Python, and run anywhere without platform lock-in.

View details
83
Repo Health
81
Technical
66
Dependency
Built with
Python 65%
Vue 17%
TypeScript 17%
Updated 1 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers