A simple in-process python scheduler library, designed to be integrated seamlessly with the `datetime` standard library.

Overview

scheduler

repository license pipeline status coverage report Documentation Status Code style: black


A simple in-process python scheduler library, designed to be integrated seamlessly with the datetime standard library. Due to the support of datetime objects, scheduler is able to work with time zones. This implementation enables the planning of Job s depending on time cycles, fixed times, weekdays, dates, weights, offsets and execution counts.


Features

  • Easy and user friendly in-process Job scheduling
    • Create recurring Jobs by given date, time, weekday, ...
    • Create recurring Jobs with a given timedelta
    • Oneshot Jobs
  • Job prioritization with linear weighting
  • datetime compatibility
  • Timezone compatibility
  • Lightweight
  • Limit and track the Job execution count
  • High test coverage
  • Online documentation

Installation

scheduler can be installed using pip with the following command:

pip install git+https://gitlab.com/DigonIO/scheduler.git

Alternatively clone the repository and install with:

git clone REPLACE_ME
cd scheduler
pip install .

Example: How to schedule Jobs

Some basics are presented here. For advanced scheduling examples please visit the online documentation. The following example shows how the Scheduler is instantiated and how cyclic Jobs are created:

import time
import datetime as dt
from scheduler import Scheduler, Weekday

def foo(msg = "bar"):
    print(msg)

sch = Scheduler()

sch.schedule(foo, dt.timedelta(minutes=10))  # every 10 minutes
sch.schedule(foo, dt.time(hour=16, minute=45))  # every day at 16:45
sch.schedule(foo, Weekday.MONDAY)  # every monday at 00:00

# every monday at 16:45
sch.schedule(
    foo,
    (Weekday.MONDAY, dt.time(hour=16, minute=45)),
)

# every friday at 00:00, every 10 minutes and every monday at 16:45
sch.schedule(
    foo,
    [
        Weekday.FRIDAY,
        dt.timedelta(minutes=10),
        (Weekday.MONDAY, dt.time(hour=16, minute=45)),
    ],
)

Besides cyclic Jobs, oneshot Jobs can also be easily created:

sch.once(foo, dt.datetime(year=2021, month=2, day=11))  # at given datetime
sch.once(foo, dt.timedelta(minutes=10))  # in 10 minutes

Pass parameters to the function handle foo:

sch.once(foo, dt.timedelta(seconds=10000), params={"msg": "fizz"})
sch.schedule(foo, dt.timedelta(minutes=1), params={"msg": "buzz"})

Create a loop in the host program to execute pending Jobs:

while True:
    sch.exec_jobs()
    time.sleep(1)

Build the documentation

The API documentation can either be viewed online or be generated using Sphinx with numpydoc formatting. To build, run:

sphinx-build -b html doc/ doc/_build/html

Testing

Testing is done using pytest. Using pytest-cov and coverage a report for the tests can be generated with:

pytest --cov=scheduler/ tests/
coverage html

To test the examples in the documentation run:

pytest --doctest-modules doc/examples.rst

TODO

  • Features
    • Support of monthly recurring Jobs (e.g. every second Monday in June and October)
    • Add __repr__ methods to Job and Scheduler
    • Execute all scheduled Jobs
    • Delete all scheduled Jobs
    • Optional Job flag: Discard missed executions befor the last pending execution
    • Execute a Job until a certain datetime stamp
    • Thread safety and background tasks
  • Documentation

License

This software is published under the GPLv3 license.

Owner
Developer Community, Development on GitLab
Better dates & times for Python

Arrow: Better dates & times for Python Arrow is a Python library that offers a sensible and human-friendly approach to creating, manipulating, formatt

Arrow 8.2k Jan 05, 2023
Cross Platform Application for Calculating Render Time

mdsanima-rt-go Cross Platform Application for Calculating Render Time. Testing This is a base application build on Windows Android and Linux. All buil

MDSANIMA DEV 2 Mar 29, 2022
The Terasic DECA board as a mandelbrot acceleerator

deca-mandelbrot The Terasic DECA board as a mandelbrot accelerator. This is a hobby project to explore parallel computation/pipelining on a FPGA. curr

Hans Baier 11 Aug 29, 2022
ISO 8601 date/time parser

ISO 8601 date/time parser This module implements ISO 8601 date, time and duration parsing. The implementation follows ISO8601:2004 standard, and imple

118 Dec 20, 2022
Make Python datetime formatting human readable

Make Python datetime formatting human readable

James Timmins 0 Oct 03, 2021
A simple digital clock made with the help of python

Digital-Clock ⏰ Description 📚 ✔️ A simple digital clock made with the help of python. The code is easy to understand and implement. With this reposit

Mohit 0 Dec 10, 2021
🏹 Better dates & times for Python

Arrow: Better dates & times for Python Arrow is a Python library that offers a sensible and human-friendly approach to creating, manipulating, formatt

Arrow 8.2k Jan 09, 2023
Datetimes for Humans™

Maya: Datetimes for Humans™ Datetimes are very frustrating to work with in Python, especially when dealing with different locales on different systems

Timo Furrer 3.4k Dec 28, 2022
🕟 Date and time processing language

Date Time Expression dte is a WIP date-time processing language with focus on broad interpretation. If you don't think it's intuitive, it's most likel

Marcelo 303 Dec 19, 2022
pytz Python historical timezone library and database

pytz Brings the IANA tz database into Python. This library allows accurate and cross platform timezone calculations. pytz contains generated code, and

Stub 236 Jan 03, 2023
A datetime parser in Python by Ari24-cb24 and NekoFantic

datetimeparser A datetime parser in Python by Ari24-cb24 and NekoFantic V 1.0 Erinnerung für den Parser Auf falsche Eingaben überprüfen Liste an Event

AriDevelopment 13 Dec 30, 2022
darts is a Python library for easy manipulation and forecasting of time series.

A python library for easy manipulation and forecasting of time series.

Unit8 5.2k Jan 01, 2023
Croniter provides iteration for the datetime object with a cron like format

Introduction Contents Introduction Travis badge Usage About DST About second repeats Testing if a date matches a crontab Gaps between date matches Ite

kiorky 152 Dec 30, 2022
Generate and work with holidays in Python

python-holidays A fast, efficient Python library for generating country, province and state specific sets of holidays on the fly. It aims to make dete

Maurizio Montel 881 Dec 29, 2022
Useful extensions to the standard Python datetime features

dateutil - powerful extensions to datetime The dateutil module provides powerful extensions to the standard datetime module, available in Python. Inst

2k Dec 29, 2022
python parser for human readable dates

Python parser for human readable dates Key Features • How To Use • Installation • Common use cases • You may also like... • License Key Features Suppo

Scrapinghub 2.2k Jan 08, 2023
A Python 3 library for parsing human-written times and dates

Chronyk A small Python 3 library containing some handy tools for handling time, especially when it comes to interfacing with those pesky humans. Featu

Felix Wiegand 339 Dec 19, 2022
A Python library for dealing with dates

moment A Python library for dealing with dates/times. Inspired by Moment.js and Kenneth Reitz's Requests library. Ideas were also taken from the Times

Zach Williams 709 Dec 09, 2022
TimeTagger is a web-based time-tracking solution that can be run locally or on a server

TimeTagger is a web-based time-tracking solution that can be run locally or on a server. In the latter case, you'll want to add authentication, and also be aware of the license restrictions.

Almar Klein 626 Jan 06, 2023
⌚️Internet Time reference and (eventually) converter site, for planning things with your internet friends who aren't (yet) obsessed with Internet Time 😉

Internet-Ti.me Internet Time reference and (eventually) converter site, for planning things with your internet friends who aren't (yet) obsessed with

Jessica Stokes 17 Nov 02, 2022