Skip to main content

A library for predefined and custom cron expressions

Project description

CronExpressions

A Python library that simplifies the creation and management of cron expressions. CronExpressions provides an intuitive, readable approach to writing cron syntax, making it easier to generate complex scheduling patterns without struggling with traditional cron expression notation.

Features

  • Simplified Cron Expression Writing: Easily create complex cron expressions using a fluent, chainable API.
  • Readable Syntax: Transform cryptic cron strings into clear, understandable code.
  • Flexible Expression Building: Construct cron expressions with an intuitive, step-by-step approach.

Installation

Install the package using pip:

pip install cronexpressions

Usage Guide

Predefined Constants

The library provides some predefined cron expression constants for quick reference:

from cronexpressions import CronExpression
print(CronExpression.EVERY_MINUTE)  # Outputs a standard cron expression for every minute
print(CronExpression.EVERY_HOUR)    # Outputs a standard cron expression for every hour
print(CronExpression.EVERY_DAY)     # Outputs a standard cron expression for daily execution

Building Cron Expressions

Use the CronBuilder class to construct cron expressions with ease:

Create Basic Expressions

from cronexpressions import CronBuilder
# Build a cron expression to run at 10:30:15 every day
cron = CronBuilder().set_second("15").set_minute("30").set_hour("10").build()
print(cron)  # Outputs a cron expression representing this specific time

Recurring Intervals

# Create an expression to run every 5 minutes
cron = CronBuilder().every('minute', 5).build()
print(cron)  # Outputs a cron expression for every 5 minutes

# Create an expression to run every 2 hours
cron = CronBuilder().every('hour', 2).build()
print(cron)  # Outputs a cron expression for every 2 hours

Range-based Expressions

# Create an expression for hours between 9 AM and 5 PM
cron = CronBuilder().set_range('hour', 9, 17).build()
print(cron)  # Outputs a cron expression covering this hour range

Specific Occurrences

# Create an expression for the first Monday of each month
cron = CronBuilder().set_specific('weekday', '1#1').build()
print(cron)  # Outputs a cron expression for this specific occurrence

Important Note

CronExpressions is a utility library for generating cron expressions. It does not handle job scheduling itself - it simply helps you create readable and maintainable cron syntax.

Use Cases

  • Generating cron expressions for scheduling libraries
  • Making cron syntax more readable and maintainable
  • Simplifying complex scheduling patterns
  • Providing a more intuitive interface for working with cron expressions

Inspiration

This library was inspired by two key motivations:

  1. The NestJS Schedule Module, which provides an elegant way to manage cron expressions in Node.js.

  2. The common struggles developers face when working with traditional, cryptic cron syntax. Developers often find themselves:

    • Spending excessive time deciphering complex cron expressions
    • Making errors due to the unintuitive nature of standard cron notation
    • Requiring constant reference to cron syntax guides
    • Struggling to quickly understand or modify existing cron schedules

CronExpressions aims to address these challenges by bringing a more intuitive, readable approach to cron expression generation in the Python ecosystem.

Contributions and feedback are welcome! 🚀

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

cronexpressions-0.1.1.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

cronexpressions-0.1.1-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file cronexpressions-0.1.1.tar.gz.

File metadata

  • Download URL: cronexpressions-0.1.1.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.7

File hashes

Hashes for cronexpressions-0.1.1.tar.gz
Algorithm Hash digest
SHA256 49f4ab7898696ba453ec7828d57dc7ea40971e5100b7bb266a873ada85df5221
MD5 f722b8dab1ccd5e1485b38d97741c684
BLAKE2b-256 131413c8a0b44e75fcab12d09d094363870d157301a283aba5d687ab41e2b302

See more details on using hashes here.

File details

Details for the file cronexpressions-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for cronexpressions-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e3bf299288df8bacb0cc4578ed236eb11bfa72214260959a0077fa378d88354a
MD5 faa508914b9f150febb5e5bd2ce36868
BLAKE2b-256 2471c2c20a44800e739c15ea59dd4bd0ed1b600b9713449098cb1081f447fce2

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