A simple in-process python scheduler library with asyncio, threading and timezone support.
Project description
A simple in-process python scheduler library with asyncio, threading and timezone support. Schedule tasks by their time cycles, fixed times, weekdays, dates, weights, offsets and execution counts and automate Jobs.
If you find the scheduler library beneficial, please consider supporting the project by starring it on GitHub.
Features
- Easy and user friendly in-process Job scheduling (Quick Start)
- Asyncio scheduler (Example)
- Threading scheduler (Example)
- Timezone compatibility (Example)
- Passing of parameters (Example)
- Job prioritization
- Job tagging (Example)
- Job batching (Example)
- Job metadata (Example)
- Lightweight
- High test coverage
- Online documentation
Installation
pip
scheduler
can be installed directly from the PyPI repositories with:
pip install scheduler
Alternatively install scheduler
from the git
repository with:
git clone https://gitlab.com/DigonIO/scheduler.git
cd scheduler
pip install .
Arch Linux
The PKGBUILD
file can be utilized from the
Arch Build System.
Download the PKGBUILD
file and from within the containing folder run
makepkg -i
Example: How to schedule Jobs
The following example shows how the Scheduler
is instantiated and how basic Job
s are created.
For advanced scheduling examples please visit the online
documentation.
import datetime as dt
from scheduler import Scheduler
from scheduler.trigger import Monday, Tuesday
def foo():
print("foo")
schedule = Scheduler()
schedule.cyclic(dt.timedelta(minutes=10), foo)
schedule.minutely(dt.time(second=15), foo)
schedule.hourly(dt.time(minute=30, second=15), foo)
schedule.daily(dt.time(hour=16, minute=30), foo)
schedule.weekly(Monday(), foo)
schedule.weekly(Monday(dt.time(hour=16, minute=30)), foo)
schedule.once(dt.timedelta(minutes=10), foo)
schedule.once(Tuesday(), foo)
schedule.once(dt.datetime(year=2022, month=2, day=15, minute=45), foo)
A human readable overview of the scheduled jobs can be created with a simple print
statement:
print(schedule)
max_exec=inf, tzinfo=None, priority_function=linear_priority_function, #jobs=9
type function / alias due at due in attempts weight
-------- ---------------- ------------------- --------- ------------- ------
MINUTELY foo() 2021-05-26 03:55:15 0:00:14 0/inf 1
CYCLIC foo() 2021-05-26 04:05:00 0:09:59 0/inf 1
ONCE foo() 2021-05-26 04:05:00 0:09:59 0/1 1
HOURLY foo() 2021-05-26 04:30:15 0:35:14 0/inf 1
DAILY foo() 2021-05-26 16:30:00 12:34:59 0/inf 1
WEEKLY foo() 2021-05-31 00:00:00 4 days 0/inf 1
WEEKLY foo() 2021-05-31 16:30:00 5 days 0/inf 1
ONCE foo() 2021-06-01 00:00:00 5 days 0/1 1
ONCE foo() 2022-02-15 00:45:00 264 days 0/1 1
Executing pending Job
s periodically can be achieved with a simple loop:
import time
while True:
schedule.exec_jobs()
time.sleep(1)
Documentation
View the API documentation online.
Sponsor
We specialize in consulting, data engineering, and data science to fine-tune AI services for seamless integration into your projects.
License
This free and open source software (FOSS) is published under the LGPLv3 license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for scheduler-0.8.7-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0917fe659a4e62f3d306af7c36f77c5161ef73a7a645bf231db6bd19722b9a3e |
|
MD5 | 953a146c9cfca9f039d1d8618d49d555 |
|
BLAKE2b-256 | 698b1be07b3915a79e1032958c5c89fa9296d9e8e09ba2b9bc40f86262d9ff00 |