Skip to main content

Event scheduler 2

Project description

The sched2 module extends the general purpose event scheduler sched from Python's standard library. sched2.scheduler is a subclass of sched.scheduler that adds new features such as the every and cron decorators. It's a practical tool for automating tasks that need to run repeatedly after certain time delays or at specific times.

Install

To install the sched2 module, you can use pip, the package installer for Python. Open a terminal and run the following command:

pip install sched2

Examples

The code below uses the every decorator to schedule checking the public IP address every two minutes.

from urllib.request import urlopen
from sched2 import scheduler

# Create a scheduler
sc = scheduler()


@sc.every(120)  # Run every two minutes
def print_ip_address():
    ip = urlopen("https://icanhazip.com/").read().decode("utf-8").strip()
    print(f"Public IP address: {ip}")

# Run the scheduler
sc.run()

The following code does something similar, but here we use the cron decorator to schedule an email report to be sent every weekday at 9:00.

from smtplib import SMTP_SSL
from sched2 import scheduler

# Create a scheduler
sc = scheduler()


@sc.cron("0 9 * * 1-5")  # Run every weekday at 9:00
def send_report():
    with SMTP_SSL("smtp.example.com") as smtp:
        smtp.login("me@example.com", "password")
        smtp.sendmail(
            "me@example.com",
            "team@example.com",
            "Subject: Daily Report\n\nThe numbers are up!",
        )


# Run the scheduler
sc.run()

Source Code and Issues

Help improve sched2 by reporting any issues or suggestions on the issue tracker at github.com/medecau/sched2/issues.

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

sched2-0.7.1.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

sched2-0.7.1-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file sched2-0.7.1.tar.gz.

File metadata

  • Download URL: sched2-0.7.1.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.12.1 Darwin/23.3.0

File hashes

Hashes for sched2-0.7.1.tar.gz
Algorithm Hash digest
SHA256 1d0c3b58a63cbf5da0d471705f20bfbfc72138300a59cc1947ba0596d74eebc1
MD5 86c8055f7ca0a6513d5465e95ff6f8b2
BLAKE2b-256 a2f6e90d24b3a00546fbc09b9afb181ffa345447ef0593aed1773657005d1823

See more details on using hashes here.

File details

Details for the file sched2-0.7.1-py3-none-any.whl.

File metadata

  • Download URL: sched2-0.7.1-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.12.1 Darwin/23.3.0

File hashes

Hashes for sched2-0.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6b81d11db48ce6add477819e14aaf0c33ad24e9dad03bfb8b67f4a2a425ebcfe
MD5 2b3f1260ea96fdfe05725eb67af83ded
BLAKE2b-256 46b251cf1f33a157fa629c3819372afef5f0b9b8c78f6392abc6cf2629528847

See more details on using hashes here.

Supported by

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