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

Uploaded Source

Built Distribution

sched2-0.8.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sched2-0.8.0.tar.gz
  • Upload date:
  • Size: 5.2 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.8.0.tar.gz
Algorithm Hash digest
SHA256 3267fc88ed3d91cf89ba0b143a293bbd9717c1397e0042b7d6602c524712d9a9
MD5 0809747f2e437ca49047592ea3218817
BLAKE2b-256 b092108ae3bb45f187928258d315e9729cf89c30d5c31527151715e22299dfeb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sched2-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 5.6 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.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ac1bc5b957f6bfb1b611315934373fcb30457723a6536d52915abbd1c9a5838b
MD5 43652c06ac178e6efe4253d22b8e158e
BLAKE2b-256 8d73cc8f5193c627333406690e1fb29469d82e365f3710923399754112ec84a9

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