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.0.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: sched2-0.7.0.tar.gz
  • Upload date:
  • Size: 4.7 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.0.tar.gz
Algorithm Hash digest
SHA256 e19d8d82aa7cf79d57a5369979bd8747e475894f322b16677123e758d8b9ac3a
MD5 8a414e72323207c80b8aae3a7356d5df
BLAKE2b-256 a9303358760640f8808bc73e03c9357d517891384f7f6a018a12ae301e1e5f3f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sched2-0.7.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 83c63247ae6576ccc4db315bf999ab97232b124648313b2a70784702bfd70b51
MD5 3bf0dabafa78b77df73fd878228f5d5d
BLAKE2b-256 d88646a2433ef7bcb499f9eb253e44b996ce886e0e97eb523cefe48190e0fca2

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