An async task scheduler framework
Project description
async-task-scheduler
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.
Installation
To install the module, simply install it using pip:
pip install async-task-scheduler
Usage
Creating a Scheduler
First, create an instance of the Scheduler class:
from async_task_scheduler import Scheduler
scheduler = Scheduler()
Adding Tasks
You can add tasks to the scheduler using various decorators:
Always
Runs the task every minute.
@scheduler.always
async def print_time_every_minute():
print("Cron time:", datetime.now().strftime("%M %H %d %m %w"))
Cron
Runs the task based on a cron-like schedule.
@scheduler.cron("*/2 * * * *")
async def two_minutes():
print("Every 2 minutes")
Hourly
Runs the task at the start of every hour.
@scheduler.hourly
async def hourly_task():
print("It is now", datetime.now().strftime("%H:%M"))
Daily
Runs the task at the start of every day.
@scheduler.daily
async def daily_task():
print("Good morning!")
Weekly
Runs the task at the start of every week.
@scheduler.weekly
async def weekly_task():
print("This is a weekly task!")
Monthly
Runs the task at the start of every month.
@scheduler.monthly
async def monthly_task():
print("Welcome to", datetime.now().strftime("%B"))
At Start
Runs the task once when the scheduler starts.
@scheduler.at_start
async def long_task():
print("Long task starting")
await asyncio.sleep(5)
print("Long task done")
At Specific Time
Runs the task at a specific datetime.
@scheduler.at(datetime(2025, 3, 10, 18, 29))
async def future_task():
print("This is a task for a specific time.")
Running the Scheduler
To run the scheduler, await the run method or call it using asyncio.run:
await scheduler.run()
or
asyncio.run(scheduler.run())
The scheduler will run indefinitely until the program is stopped.
Example
See the end of the source file for a complete example.
License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file async_task_scheduler-0.1.0.tar.gz.
File metadata
- Download URL: async_task_scheduler-0.1.0.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c22c643ddc229c67e7545392dbb35d2dcd5f646b6a99bdffdbb24d697e51f29
|
|
| MD5 |
06cb140aca6a377f192ba875835e19aa
|
|
| BLAKE2b-256 |
45f5e676914d28db2c728998e3089582165cbfe2ef0e222867663b1f5413f493
|
File details
Details for the file async_task_scheduler-0.1.0-py3-none-any.whl.
File metadata
- Download URL: async_task_scheduler-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d0b85cfd28e960e01209cb842f7f7208eb0446368a3dfc7e52fda606cfad4f0a
|
|
| MD5 |
acda6e3cb096f42a651eef68f8d047a1
|
|
| BLAKE2b-256 |
4928526f4ff10675806bdf7c3cecdd06aef0151df771a6ffeb1a1431ef6d8ff5
|