Skip to main content
https://img.shields.io/pypi/v/aiocron.svg https://img.shields.io/pypi/dm/aiocron.svg

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. Refer to it’s documentation to know more about crontab format.

Metadata

Release files for aiocron 2.1

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

Source distribution (sdist)

Source distribution for aiocron 2.1
File Size Uploaded
aiocron-2.1.tar.gz 21.1 kB Details

Built distribution (wheel)

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

Total release size: 26.7 kB

Release files / aiocron-2.1.tar.gz

Download URL aiocron-2.1.tar.gz
Size 21.1 kB
Tags Source
SHA-256 checksum
How to use checksums
1bb65a36aee137e8833592783956e0c7dc478bc3e9273fc2841d5d0c6045e4d2
BLAKE2b-256 checksum
How to use checksums
b0cc71fdc16da63deec40da37977541d81052227fc7cbbf2c13358f745f05d86
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.2

Release files / aiocron-2.1-py3-none-any.whl

Download URL aiocron-2.1-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b2612b67c552ebc4d24f524fe0316dec30b44f3c5a1d9a3697493d840aa7a5de
BLAKE2b-256 checksum
How to use checksums
f28290d3c43e137d06496e0305ce06596a0e36c7cd13c6de986378002c0fd749
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.2

Release history Release notifications | RSS feed

This release

2.1 This release

2 release files

2.0

2 release files

1.8

2 release files

1.7

2 release files

1.6

2 release files

1.5

1 release file

1.4

2 release files

1.3

2 release files

1.2

2 release files

1.1

2 release files

1.0

2 release files

0.7

2 release files

0.6

2 release files

0.5

2 release files

0.4

2 release files

0.3

1 release file

0.2

1 release file

0.1

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