aiocron


Nameaiocron JSON
Version 2.0 PyPI version JSON
download
home_pageNone
SummaryCrontabs for asyncio
upload_time2025-02-13 23:24:18
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseMIT License Copyright (c) 2016 Gael Pasgrimaud Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords crontab cron asyncio
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            ================================================
aiocron - Crontabs for asyncio
================================================


.. image:: https://img.shields.io/pypi/v/aiocron.svg
  :target: https://pypi.python.org/pypi/aiocron
.. image:: https://img.shields.io/pypi/dm/aiocron.svg
  :target: https://pypi.python.org/pypi/aiocron

Usage
=====

``aiocron`` provide a decorator to run function at time::

    >>> import aiocron
    >>> import asyncio
    >>>
    >>> @aiocron.crontab('*/30 * * * *')
    ... async def attime():
    ...     print('run')
    ...
    >>> asyncio.get_event_loop().run_forever()

You can also use it as an object::

    >>> @aiocron.crontab('1 9 * * 1-5', start=False)
    ... async def attime():
    ...     print('run')
    ...
    >>> attime.start()
    >>> asyncio.get_event_loop().run_forever()

Your function still be available at ``attime.func``

You can also await a crontab. In this case, your coroutine can accept
arguments::

    >>> @aiocron.crontab('0 9,10 * * * mon,fri', start=False)
    ... async def attime(i):
    ...     print('run %i' % i)
    ...
    >>> async def once():
    ...     try:
    ...         res = await attime.next(1)
    ...     except Exception as e:
    ...         print('It failed (%r)' % e)
    ...     else:
    ...         print(res)
    ...
    >>> asyncio.get_event_loop().run_forever()

Finally you can use it as a sleep coroutine. The following will wait until
next hour::

    >>> await crontab('0 * * * *').next()

If you don't like the decorator magic you can set the function by yourself::

    >>> cron = crontab('0 * * * *', func=yourcoroutine, start=False)

Notice that unlike standard unix crontab you can specify seconds at the 6th
position.

``aiocron`` use `croniter <https://pypi.python.org/pypi/croniter>`_. Refer to
it's documentation to know more about crontab format.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "aiocron",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "crontab, cron, asyncio",
    "author": null,
    "author_email": "Gael Pasgrimaud <gael@gawel.org>",
    "download_url": "https://files.pythonhosted.org/packages/1b/5e/d2bef7a2ce4ca7056966ce6f90c5065fe2d671297ac91b9b0f5bc9155aff/aiocron-2.0.tar.gz",
    "platform": null,
    "description": "================================================\naiocron - Crontabs for asyncio\n================================================\n\n\n.. image:: https://img.shields.io/pypi/v/aiocron.svg\n  :target: https://pypi.python.org/pypi/aiocron\n.. image:: https://img.shields.io/pypi/dm/aiocron.svg\n  :target: https://pypi.python.org/pypi/aiocron\n\nUsage\n=====\n\n``aiocron`` provide a decorator to run function at time::\n\n    >>> import aiocron\n    >>> import asyncio\n    >>>\n    >>> @aiocron.crontab('*/30 * * * *')\n    ... async def attime():\n    ...     print('run')\n    ...\n    >>> asyncio.get_event_loop().run_forever()\n\nYou can also use it as an object::\n\n    >>> @aiocron.crontab('1 9 * * 1-5', start=False)\n    ... async def attime():\n    ...     print('run')\n    ...\n    >>> attime.start()\n    >>> asyncio.get_event_loop().run_forever()\n\nYour function still be available at ``attime.func``\n\nYou can also await a crontab. In this case, your coroutine can accept\narguments::\n\n    >>> @aiocron.crontab('0 9,10 * * * mon,fri', start=False)\n    ... async def attime(i):\n    ...     print('run %i' % i)\n    ...\n    >>> async def once():\n    ...     try:\n    ...         res = await attime.next(1)\n    ...     except Exception as e:\n    ...         print('It failed (%r)' % e)\n    ...     else:\n    ...         print(res)\n    ...\n    >>> asyncio.get_event_loop().run_forever()\n\nFinally you can use it as a sleep coroutine. The following will wait until\nnext hour::\n\n    >>> await crontab('0 * * * *').next()\n\nIf you don't like the decorator magic you can set the function by yourself::\n\n    >>> cron = crontab('0 * * * *', func=yourcoroutine, start=False)\n\nNotice that unlike standard unix crontab you can specify seconds at the 6th\nposition.\n\n``aiocron`` use `croniter <https://pypi.python.org/pypi/croniter>`_. Refer to\nit's documentation to know more about crontab format.\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2016 Gael Pasgrimaud  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Crontabs for asyncio",
    "version": "2.0",
    "project_urls": {
        "Homepage": "https://github.com/gawel/aiocron/"
    },
    "split_keywords": [
        "crontab",
        " cron",
        " asyncio"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "dd0cdc1fe9564b579a80e49e1439695821ff59e8c1a24641138c6dccd79052c4",
                "md5": "a83515fde6b8cddfa35ed1c346a49068",
                "sha256": "72d2730e111e47001f493c5a6d451e4e7e2bb56ed8316a9200990634f23cbf62"
            },
            "downloads": -1,
            "filename": "aiocron-2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a83515fde6b8cddfa35ed1c346a49068",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 5559,
            "upload_time": "2025-02-13T23:24:16",
            "upload_time_iso_8601": "2025-02-13T23:24:16.587973Z",
            "url": "https://files.pythonhosted.org/packages/dd/0c/dc1fe9564b579a80e49e1439695821ff59e8c1a24641138c6dccd79052c4/aiocron-2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1b5ed2bef7a2ce4ca7056966ce6f90c5065fe2d671297ac91b9b0f5bc9155aff",
                "md5": "630d6cfcda4bdf4951e2b11bd9f0f99c",
                "sha256": "4277416797ea0797244c2e5252d227d466c0718e2b275654dadc7b6857992f13"
            },
            "downloads": -1,
            "filename": "aiocron-2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "630d6cfcda4bdf4951e2b11bd9f0f99c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 21379,
            "upload_time": "2025-02-13T23:24:18",
            "upload_time_iso_8601": "2025-02-13T23:24:18.509127Z",
            "url": "https://files.pythonhosted.org/packages/1b/5e/d2bef7a2ce4ca7056966ce6f90c5065fe2d671297ac91b9b0f5bc9155aff/aiocron-2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-13 23:24:18",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "gawel",
    "github_project": "aiocron",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "lcname": "aiocron"
}
        
Elapsed time: 0.52570s