Skip to main content

Calendar scheduler

Project description

Calendar Scheduler for Recurring Events

PyPI version

Features

  • Executes an action function on a schedule.
  • Thread-safe: events can be added and canceled from different threads.
  • Supports intervals from milliseconds to years.
  • Uses the standard sched scheduler.
  • Timezone support.
  • Syntax similar to datetime.
  • Events can be added at any time: before or after the scheduler starts, and from any thread.
  • No additional packages required.

Installation

Install via pip:

pip install calsched

Install via uv:

uv pip install calsched

Import

from calsched import CalendarScheduler

Creating the Scheduler

scheduler = CalendarScheduler()

Running the Scheduler

Start the scheduler using the run() method:

scheduler.run()

However, it will immediately exit if no events are scheduled. At least one event must be scheduled before starting.

Example that prints the current time every second:

import datetime
from calsched import CalendarScheduler

def print_time():
    print(datetime.datetime.now())

scheduler = CalendarScheduler()
scheduler.enter_every_second_event(action=print_time)
scheduler.run()

In this case, run() blocks the thread in which it is called.

The action function is executed in the same thread as the run() method.

To allow adding events after the scheduler has started, you can add a placeholder event before calling run() to keep the scheduler active:

scheduler = CalendarScheduler()
stub_event = scheduler.enter_hourly_event(action=lambda: None)
scheduler.run()

You can stop run() by canceling the placeholder event:

scheduler.cancel(stub_event)

Example of running in a separate thread:

import datetime
import threading
from time import sleep
from calsched import CalendarScheduler

def print_time():
    print(datetime.datetime.now())

scheduler = CalendarScheduler()
stub_event = scheduler.enter_hourly_event(action=lambda: None)
thread = threading.Thread(target=scheduler.run)
thread.start()
sleep(1.0)

event = scheduler.enter_every_second_event(action=print_time)
sleep(5.0)
scheduler.cancel(stub_event)
scheduler.cancel(event)
thread.join()

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

calsched-1.0.1.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

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

calsched-1.0.1-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file calsched-1.0.1.tar.gz.

File metadata

  • Download URL: calsched-1.0.1.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.12

File hashes

Hashes for calsched-1.0.1.tar.gz
Algorithm Hash digest
SHA256 9f738ecc1524a1334b77dfba30bce3ee150520cc07c09e2637472b276c136e4b
MD5 71326c31724d1108f74f01c3d350a4f5
BLAKE2b-256 532548a4c19fd03a0b217cbac790c07626329e6e05c954f91185d59de927066f

See more details on using hashes here.

File details

Details for the file calsched-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: calsched-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.12

File hashes

Hashes for calsched-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b13e71e1d59323ee7e4f7c1eb44d7156451e27252edf6f6a80aef7c9a88eafc5
MD5 c731223c7ffec26b1f9372762c5f8565
BLAKE2b-256 2f4680a29efe2380b80eac6562b37802cffe517bba4d47c720c3ec87bcf55d02

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