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
| Details | |
| Features |
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
Python
Cronspell is heavily inspired by Grafana's relative Date picker user interface. It shines when configuration is needed to reflect irregular date-distances such as in the example below.
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
Release history Release notifications | RSS feed
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 cronspell-0.3.0.tar.gz.
File metadata
- Download URL: cronspell-0.3.0.tar.gz
- Upload date:
- Size: 12.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
44b06a72235282477147d024eb983d9deb959f75aa6309791e1faf135c625da8
|
|
| MD5 |
ed76bbf1d4247190649fa9e9e74fc4bb
|
|
| BLAKE2b-256 |
999a1460485e28fa9c1f445098ceb6487ad0620b22ddbb938cbc497b51053d96
|
Provenance
The following attestation bundles were made for cronspell-0.3.0.tar.gz:
Publisher:
build.yml on iilei/cronspell
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cronspell-0.3.0.tar.gz -
Subject digest:
44b06a72235282477147d024eb983d9deb959f75aa6309791e1faf135c625da8 - Sigstore transparency entry: 157414156
- Sigstore integration time:
-
Permalink:
iilei/cronspell@919c9ce5ad7dc921ea7a2ea726e2ff11b44fcf0b -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/iilei
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@919c9ce5ad7dc921ea7a2ea726e2ff11b44fcf0b -
Trigger Event:
push
-
Statement type:
File details
Details for the file cronspell-0.3.0-py3-none-any.whl.
File metadata
- Download URL: cronspell-0.3.0-py3-none-any.whl
- Upload date:
- Size: 13.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d57f577d9a90d294d740685b0778a1dfd9cb0fd469ef14540043b7fb7c3ee0fe
|
|
| MD5 |
0498f0e3cccd79337bc9c1d17534104d
|
|
| BLAKE2b-256 |
256a76a9fa3e45d4358546b72a23c5dc26e4ab1fbed12c9a234e749597c01fac
|
Provenance
The following attestation bundles were made for cronspell-0.3.0-py3-none-any.whl:
Publisher:
build.yml on iilei/cronspell
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cronspell-0.3.0-py3-none-any.whl -
Subject digest:
d57f577d9a90d294d740685b0778a1dfd9cb0fd469ef14540043b7fb7c3ee0fe - Sigstore transparency entry: 157414157
- Sigstore integration time:
-
Permalink:
iilei/cronspell@919c9ce5ad7dc921ea7a2ea726e2ff11b44fcf0b -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/iilei
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@919c9ce5ad7dc921ea7a2ea726e2ff11b44fcf0b -
Trigger Event:
push
-
Statement type: