Skip to main content

Date-expression domain specific language parsing. A neat way to express things like "First Saturday of any year", or "3rd thursdays each month" and such

Project description

Cronspell Python Package / CLI Tool

Chronometry Spelled Out

Github Pages

Details Tests License - MIT
Features linting - Ruff types - mypy test - pytest Pre-Commit docs - mkdocs

Date-expression domain specific language (DSL) parsing. A neat way to express things like "First Saturday of any year", or "3rd thursdays each month" and such.

DSL Example

To get the last saturday of last month:

"now /m -1d /sat"

The same, more verbose:

"now /month -1day /sat"

Test for Upcoming Occurrences

Find upcoming dates beginning of every 3rd calendar week using the upcoming module and its moments generator.


from collections.abc import Generator

import time_machine

from cronspell.upcoming import moments as upcoming


cw3: Generator = upcoming("@cw 3")

# given the current Calendar week is in 2024-W51 ... 2025-W02
assert next(cw3).strftime("%G-W%V") == "2025-W03"
assert next(cw3).strftime("%G-W%V") == "2025-W06"
assert next(cw3).strftime("%G-W%V") == "2025-W09"

Installation

Python module

If you need just the python function to parse cronspell expressions:

pip install cronspell
from cronspell import parse

date_of_interest = parse("now /m -1d /sat")

Command Line Interface

If you like to use it in your command line:

pip install 'cronspell[cli]'
cronspell parse "now /m -1d /sat"

Features

Cronspell is heavily inspired by Grafana's relative Date picker user interface. It was designed for the cases when configuration is needed to reflect irregular date-distances.

Use it within your Python project or via command line interface.

Python

cronspell lets you express relative dates such as "last saturday of last month" and converts it to a date object for use in your python project.

from cronspell import parse

# Cronspell's purpose is mostly to parse configuration files written in yaml
# and therein express relative date times in a human friendly manner.

# here is but a simple demo:
last_saturday = parse("now/sat")
...

Cli

The same interface, exposed to the command line. Formatted via isodate by default -- which is open for configuration using the --format option.

This is how you get the last saturday of the current month, for example:

cronspell parse "now /month + 34 days /m -1d /sat"

Pre-Commit Hook: Validation

Cronspell comes with a pre-commit hook that validates configured date-expressions based on yamlpath.

Check out the documentation for detailed instructions.

Credits

  • Domain-Specific-Language Parser: TextX
  • This package was created with The Hatchlor project template.

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

cronspell-0.3.1.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

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

cronspell-0.3.1-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file cronspell-0.3.1.tar.gz.

File metadata

  • Download URL: cronspell-0.3.1.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for cronspell-0.3.1.tar.gz
Algorithm Hash digest
SHA256 6584f6dedfe9ca51763641dba4db64a6022f2c91aa68715fe3ba33c17c801b06
MD5 51b3cb00b168f33ccf353fe2789112a8
BLAKE2b-256 ef5f21b0fcd97265f3eda6a909371d32d2051fce552068a5e17812e28af94370

See more details on using hashes here.

Provenance

The following attestation bundles were made for cronspell-0.3.1.tar.gz:

Publisher: build.yml on iilei/cronspell

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cronspell-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: cronspell-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 14.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for cronspell-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f360720d0e5797c78530991eeab82260d42426fdb0337a871e9bf38fd104644e
MD5 4f20b2131e5245d04debcd6bec02bee6
BLAKE2b-256 aee680ee40e65e73e6ab7782ee9e3282e8b03260c1163b167263e4545d8a7664

See more details on using hashes here.

Provenance

The following attestation bundles were made for cronspell-0.3.1-py3-none-any.whl:

Publisher: build.yml on iilei/cronspell

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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