Human-readable cron — a scheduling expression language that is a superset of cron
Project description
hron
Human-readable cron — scheduling expressions that are a superset of what cron can express.
from hron import Schedule
schedule = Schedule.parse("every weekday at 9:00 in America/New_York")
Install
pip install hron
Usage
from datetime import datetime
from zoneinfo import ZoneInfo
from hron import Schedule
# Parse an expression
schedule = Schedule.parse("every weekday at 9:00 except dec 25, jan 1 in America/New_York")
# Get next occurrence
now = datetime.now(ZoneInfo("America/New_York"))
next_time = schedule.next_from(now)
print(next_time)
# Get next 5 occurrences
upcoming = schedule.next_n_from(now, 5)
for dt in upcoming:
print(dt)
# Check if a datetime matches
schedule.matches(datetime(2026, 2, 9, 9, 0, tzinfo=ZoneInfo("America/New_York"))) # True
# Convert to/from cron
simple = Schedule.parse("every day at 9:00")
print(simple.to_cron()) # "0 9 * * *"
from_cron = Schedule.from_cron("*/30 * * * *")
print(from_cron) # "every 30 min from 00:00 to 23:59"
# Validate without exceptions
Schedule.validate("every day at 9:00") # True
Schedule.validate("invalid") # False
Expression Syntax
See the full expression reference.
API
Schedule.parse(input: str) -> Schedule
Parse an hron expression string.
Schedule.from_cron(cron_expr: str) -> Schedule
Convert a 5-field cron expression to a Schedule.
Schedule.validate(input: str) -> bool
Check if an input string is a valid hron expression.
schedule.next_from(now: datetime) -> datetime | None
Compute the next occurrence after now.
schedule.next_n_from(now: datetime, n: int) -> list[datetime]
Compute the next n occurrences after now.
schedule.matches(dt: datetime) -> bool
Check if a datetime matches this schedule.
schedule.to_cron() -> str
Convert to a 5-field cron expression. Raises HronError if the schedule can't be expressed as cron.
str(schedule) -> str
Render as the canonical string form (roundtrip-safe).
schedule.timezone -> str | None
The timezone, if specified.
schedule.expression -> ScheduleExpr
The underlying schedule expression AST.
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hron-0.5.0.tar.gz.
File metadata
- Download URL: hron-0.5.0.tar.gz
- Upload date:
- Size: 16.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c818134047a8b603b70541a3ab88dbbccf1de12b83736f0e729393ff1615d7ff
|
|
| MD5 |
c506fdd497d4eea400ef36195105fb75
|
|
| BLAKE2b-256 |
358ba1e0a33e04871e5485dea7c3ef9e3a34459085c9249694694fec104ed7f4
|
File details
Details for the file hron-0.5.0-py3-none-any.whl.
File metadata
- Download URL: hron-0.5.0-py3-none-any.whl
- Upload date:
- Size: 20.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e799b9790fdea0f581a0f75099efd6ca48b5a9eb408b1cde439732776bdef59d
|
|
| MD5 |
4dffeac8ad897adcc9633852c00dbcd9
|
|
| BLAKE2b-256 |
adb17a8a3ee21aae2494f6b368a38185484473e563f309cc89b514707dc59f7a
|