async_task_scheduler
is a Python module that allows you to schedule asynchronous tasks using various scheduling strategies such as cron-like schedules, one-time execution, and more.
To install the module, simply install it using pip
:
pip install async_task_scheduler
First, create an instance of the Scheduler
class:
from async_task_scheduler import Scheduler
scheduler = Scheduler()
You can add tasks to the scheduler using various decorators:
Runs the task every minute.
@scheduler.always
async def every_minute():
print("This will be called every minute")
Runs the task based on a cron-like schedule.
@scheduler.cron("*/2 * * * 5")
async def custom_cron_schedule():
print("This will be called every two minutes on Fridays")
Runs the task at the start of every hour.
@scheduler.hourly
async def every_hour():
print("This will be called every hour")
Runs the task at the start of every day.
@scheduler.daily
async def every_day():
print("This will be called every day")
Runs the task at the start of every week.
@scheduler.weekly
async def every_week():
print("This will be called every week")
Runs the task at the start of every month.
@scheduler.monthly
async def every_month():
print("This will be called every month")
Runs the task once when the scheduler starts.
@scheduler.at_start
async def start_task():
print("This will be called once when the scheduler starts")
Runs the task at a specific datetime.
@scheduler.at(datetime(2025, 3, 10, 18, 29))
async def future_task():
print("This will be called at 6:29 PM on March 10, 2025")
To run the scheduler, await the run
method or call it using asyncio.run
:
await scheduler.run()
or
import asyncio
asyncio.run(scheduler.run())
The scheduler will run indefinitely until the program is stopped.
See the end of the source file for a complete example.
This project is licensed under the MIT License.