Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

async_task_scheduler-0.1.0.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

async_task_scheduler-0.1.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file async_task_scheduler-0.1.0.tar.gz.

File metadata

File hashes

Hashes for async_task_scheduler-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9c22c643ddc229c67e7545392dbb35d2dcd5f646b6a99bdffdbb24d697e51f29
MD5 06cb140aca6a377f192ba875835e19aa
BLAKE2b-256 45f5e676914d28db2c728998e3089582165cbfe2ef0e222867663b1f5413f493

See more details on using hashes here.

File details

Details for the file async_task_scheduler-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for async_task_scheduler-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d0b85cfd28e960e01209cb842f7f7208eb0446368a3dfc7e52fda606cfad4f0a
MD5 acda6e3cb096f42a651eef68f8d047a1
BLAKE2b-256 4928526f4ff10675806bdf7c3cecdd06aef0151df771a6ffeb1a1431ef6d8ff5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page