pycron


Namepycron JSON
Version 3.1.1 PyPI version JSON
download
home_pagehttps://github.com/kipe/pycron
SummarySimple cron-like parser, which determines if current datetime matches conditions.
upload_time2024-09-27 16:38:03
maintainerNone
docs_urlNone
authorKimmo Huoman
requires_python<3.13,>=3.9
licenseMIT
keywords cron parser
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            # pycron

![Test Status](https://github.com/kipe/pycron/actions/workflows/python-test.yml/badge.svg?branch=main)
[![Coverage Status](https://coveralls.io/repos/github/kipe/pycron/badge.svg?branch=main)](https://coveralls.io/github/kipe/pycron?branch=main)

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

## Installation

`pip install pycron`

## Usage

```python
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](https://en.wikipedia.org/wiki/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:

- [Arrow](http://arrow.readthedocs.io/en/latest/)
- [Delorean](http://delorean.readthedocs.io/en/latest/)
- [Pendulum](https://pendulum.eustace.io/)
- [udatetime](https://github.com/freach/udatetime)

#### 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 ;)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/kipe/pycron",
    "name": "pycron",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<3.13,>=3.9",
    "maintainer_email": null,
    "keywords": "cron, parser",
    "author": "Kimmo Huoman",
    "author_email": "kipenroskaposti+pycron@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/ee/a9/bd7c28cfdc45728b3e2d7203e236943eb645a210d21e4e9f534356237aa2/pycron-3.1.1.tar.gz",
    "platform": null,
    "description": "# pycron\n\n![Test Status](https://github.com/kipe/pycron/actions/workflows/python-test.yml/badge.svg?branch=main)\n[![Coverage Status](https://coveralls.io/repos/github/kipe/pycron/badge.svg?branch=main)](https://coveralls.io/github/kipe/pycron?branch=main)\n\nSimple cron-like parser for Python, which determines if current datetime matches conditions.\n\n## Installation\n\n`pip install pycron`\n\n## Usage\n\n```python\nimport pycron\npycron.is_now('*/5 * * * *')  # True every 5 minutes\npycron.is_now('0 * * * *')    # True every hour, on minute 0\n```\n\n## Help\n\nThe formats currently supported are\n\n- `*/5` (for \"every X\" function),\n- `4-10` (for time ranges),\n- `6,8,23` (for a list of values),\n- `*` (for wildcard),\n- and of course a single number.\n\nThe module includes `is_now(s, dt=None)`, where `s` is the cron-style string\nand `dt` is the datetime to use (defaults to current datetime, if not set).\nThe function returns `True`, if `dt` matches the format.\n\nIt also includes `has_been(s, since, dt=None)`, where `s` is the cron-style string,\n`since` is a datetime in the past and `dt` is the datetime to use (defaults to current datetime, if not set).\nThe function returns `True`, if `dt` would have matched the format at some point during the period.\nThis behaves much like like [anacron](https://en.wikipedia.org/wiki/Anacron) and is useful for applications which do not run continuously.\n\nAll functions are compatible with both timezone aware and naive datetimes.\n\nThere are couple of helpers available, mainly for use with Django.\nThey give out list of tuples, as required by Django field choices.\n\nThe available helpers are\n\n- `pycron.MINUTE_CHOICES`,\n- `pycron.HOUR_CHOICES`,\n- `pycron.DOM_CHOICES`, for day of month\n- `pycron.MONTH_CHOICES`, for month names\n- `pycron.DOW_CHOICES`, for day names\n\n## Support for alternative datetime -libraries\n\nCurrently supported \"alternative\" datetime libraries are:\n\n- [Arrow](http://arrow.readthedocs.io/en/latest/)\n- [Delorean](http://delorean.readthedocs.io/en/latest/)\n- [Pendulum](https://pendulum.eustace.io/)\n- [udatetime](https://github.com/freach/udatetime)\n\n#### Notes\n\nThis was done, as I personally needed something like this to implement proper timers for my Django-project and\nevery available library felt too complicated for my use-case. Also, this was a good coding exercise...\n\nAs the Django -helper choices are quite limited, I've expanded them in my own project by adding values like\n`('*/5', 'every 5 minutes')`, `('1-5', 'on weekdays')`, and `('0,6', 'on weekends')`.\nI 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 ;)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Simple cron-like parser, which determines if current datetime matches conditions.",
    "version": "3.1.1",
    "project_urls": {
        "Homepage": "https://github.com/kipe/pycron",
        "Repository": "https://github.com/kipe/pycron"
    },
    "split_keywords": [
        "cron",
        " parser"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "192cb038f9bcde67def9a51bdf4d64d399d6853addb6844991cec64b04e95c33",
                "md5": "0330ecdfbff13751d2551a8610588993",
                "sha256": "bf676a66b8dcf69edf1d3fd1d8f3f2b9468a2a007012c89a14e9d087d3f76198"
            },
            "downloads": -1,
            "filename": "pycron-3.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0330ecdfbff13751d2551a8610588993",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<3.13,>=3.9",
            "size": 4862,
            "upload_time": "2024-09-27T16:38:02",
            "upload_time_iso_8601": "2024-09-27T16:38:02.602717Z",
            "url": "https://files.pythonhosted.org/packages/19/2c/b038f9bcde67def9a51bdf4d64d399d6853addb6844991cec64b04e95c33/pycron-3.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "eea9bd7c28cfdc45728b3e2d7203e236943eb645a210d21e4e9f534356237aa2",
                "md5": "52459e269e071fa71e35cd99412bded0",
                "sha256": "6de8a555f721c74aa0bb681071a97da3d784ebf8ccea1d2bb9a3e66460b87da2"
            },
            "downloads": -1,
            "filename": "pycron-3.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "52459e269e071fa71e35cd99412bded0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<3.13,>=3.9",
            "size": 4374,
            "upload_time": "2024-09-27T16:38:03",
            "upload_time_iso_8601": "2024-09-27T16:38:03.911245Z",
            "url": "https://files.pythonhosted.org/packages/ee/a9/bd7c28cfdc45728b3e2d7203e236943eb645a210d21e4e9f534356237aa2/pycron-3.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-27 16:38:03",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "kipe",
    "github_project": "pycron",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "lcname": "pycron"
}
        
Elapsed time: 3.11600s