Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

pycron

Test Status

Simple cron-like parser for Python, which determines if current datetime matches conditions.

Installation

pip install pycron

Usage

import pycron
pycron.is_now('*/5 * * * *')  # True every 5 minutes
pycron.is_now('0 * * * *')    # True every hour, on minute 0

Help

The formats currently supported are

  • */5 (for "every X" function),
  • 4-10 (for time ranges),
  • 6,8,23 (for a list of values),
  • * (for wildcard),
  • and of course a single number.

The module includes is_now(s, dt=None), where s is the cron-style string and dt is the datetime to use (defaults to current datetime, if not set). The function returns True, if dt matches the format.

It also includes has_been(s, since, dt=None), where s is the cron-style string, since is a datetime in the past and dt is the datetime to use (defaults to current datetime, if not set). The function returns True, if dt would have matched the format at some point during the period. This behaves much like like anacron and is useful for applications which do not run continuously.

All functions are compatible with both timezone aware and naive datetimes.

There are couple of helpers available, mainly for use with Django. They give out list of tuples, as required by Django field choices.

The available helpers are

  • pycron.MINUTE_CHOICES,
  • pycron.HOUR_CHOICES,
  • pycron.DOM_CHOICES, for day of month
  • pycron.MONTH_CHOICES, for month names
  • pycron.DOW_CHOICES, for day names

Support for alternative datetime -libraries

Currently supported "alternative" datetime libraries are:

Notes

This was done, as I personally needed something like this to implement proper timers for my Django-project and every available library felt too complicated for my use-case. Also, this was a good coding exercise...

As the Django -helper choices are quite limited, I've expanded them in my own project by adding values like ('*/5', 'every 5 minutes'), ('1-5', 'on weekdays'), and ('0,6', 'on weekends'). I haven't included them in the code, as every use-case is different, this was just to give an idea on how to use this ;)

Release files for pycron 3.3.0a1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pycron 3.3.0a1
File Size Uploaded
pycron-3.3.0a1.tar.gz 71.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pycron 3.3.0a1
File Interpreter ABI Platform
pycron-3.3.0a1-py3-none-any.whl Python 3 none any Details

Total release size: 76.2 kB

Release files / pycron-3.3.0a1.tar.gz

Download URL pycron-3.3.0a1.tar.gz
Size 71.1 kB
Tags Source
SHA-256 checksum
How to use checksums
720523d7fdc66f30497818adb5f2b6898aff2e4154e4ab30c618e2df9d3ec140
BLAKE2b-256 checksum
How to use checksums
62dbfcc4ecaad758b5f204db19aa7fb9aefe22d3a1cda1f3aac168e431249f8c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.15 {"installer":{"name":"uv","version":"0.12.15","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}

Release files / pycron-3.3.0a1-py3-none-any.whl

Download URL pycron-3.3.0a1-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e919d2829937f7fde0d53f654e0646bbe206d670b6f7dadf7e142cab045db2a0
BLAKE2b-256 checksum
How to use checksums
221e812e22e2e9fb56da1f83036b1ebfffc7e0da755e4f957263e9069c1e1c13
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.15 {"installer":{"name":"uv","version":"0.12.15","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}

Release history Release notifications | RSS feed

3.3.0

2 release files

This release

3.3.0a1 This release

2 release files

3.2.0

2 release files

3.1.2

2 release files

3.1.1

2 release files

3.1.0

2 release files

3.0.0

1 release file

1.0.0

1 release file

0.80.0

1 release file

0.40

1 release file

0.32

1 release file

0.31

1 release file

0.3

1 release file

0.2

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page