Skip to main content

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

hron-0.4.1.tar.gz (17.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hron-0.4.1-py3-none-any.whl (20.7 kB view details)

Uploaded Python 3

File details

Details for the file hron-0.4.1.tar.gz.

File metadata

  • Download URL: hron-0.4.1.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.8

File hashes

Hashes for hron-0.4.1.tar.gz
Algorithm Hash digest
SHA256 8054774a27f405faa7eb975fc6ba39d62d85b2e4549f925149d4fa39a3a9899b
MD5 69efdf24ce5728e3288f2e447811cd01
BLAKE2b-256 ba7d47841409f1b4df3a69d5e9e7657a9fcabbac1b58aa2674305b3737932e7e

See more details on using hashes here.

File details

Details for the file hron-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: hron-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 20.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.8

File hashes

Hashes for hron-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1b0375daf6a488de920e0af7c40ad35092f6fbef31e9159172ac2bae91e53778
MD5 1b9d25b4ff2d4293ab49b25161cd12e8
BLAKE2b-256 f6d65a2240838eb9a99fe8052f620bbbf03eeb3f0341a5c9435f7bc78ede9473

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page