Tscheduler Tasks Scheduler (Tscheduler) is a Python library that lets you schedule your Python code to be executed later, either just once or periodically. You can add new jobs or remove old ones on the fly as you please.
Among other things, Tscheduler can be used as a cross-platform, application specific replacement to platform specific schedulers, such as the cron daemon or the Windows task scheduler. Please note, however, that Tscheduler is not a daemon or service itself, nor does it come with any command line tools. It is primarily meant to be run inside existing applications. That said, Tscheduler does provide some building blocks for you to build a scheduler service or to run a dedicated scheduler process.
Tscheduler has three built-in scheduling systems you can use:
Cron-style scheduling
Interval-based execution (runs jobs on even intervals)
Tscheduler also integrates with several common Python frameworks, like:
asyncio (PEP 3156)
gevent
Tornado
Twisted
Qt (using either PyQt , PySide6 , PySide2 or PySide)
There are third party solutions for integrating Tscheduler with other frameworks:
Django
Flask
Fastapi
How to use
First we install the package from pypi.org
pip install tscheduler
Second we call BackgroundScheduler from the package tscheduler
from tscheduler.tscheduler import BackgroundScheduler
Python Example 1:
from tscheduler.tscheduler import BackgroundScheduler
def hello():
print("hello")
scheduler = BackgroundScheduler()
scheduler.add_job(target=hello,trigger="interval",seconds=5) # line 1
scheduler.add_job(target=hello,seconds=5) # line 2 line 1 same result with line 2
scheduler.start()
This example shows the use of the interval
Python Example 2:
from tscheduler.tscheduler import BackgroundScheduler
def hello():
print("hello")
scheduler = BackgroundScheduler()
scheduler.add_job(target=hello,trigger="cron",hours=10,minutes=30,seconds=0) # line 1
scheduler.add_job(target=hello,trigger="cron",day_of_week="mon-tue-wed-thu-fri-sat-sun",hours=10,minutes=30,seconds=0) # line 2 line 1 same result with line 2
# day_of_week: With this property you can specify the days on which the job works.
scheduler.start()
This example shows the use of the cron
Python Example 3: this example using fastapi
from contextlib import asynccontextmanager
from time import sleep
from fastapi import FastAPI
from tscheduler.tscheduler import BackgroundScheduler
@asynccontextmanager
async def lifespan(_: FastAPI):
print("app started....")
sch.start()
yield
print("app stopped...")
sch.stop()
app = FastAPI(lifespan=lifespan)
sch = BackgroundScheduler()
def hello():
print("hello")
sch.add_job(target=hello, seconds=5)
Note: The function must not contain args But there is a solution for it. The function must be wrapped with a function not contain args Example:
from tscheduler.tscheduler import BackgroundScheduler
def hello(name):
print(f"hello {name}")
name="taibaoui mohamed"
def print_name():
hello(name)
scheduler = BackgroundScheduler()
scheduler.add_job(target=print_name,trigger="interval",seconds=5)
scheduler.start()
Metadata
Release files for tscheduler 0.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tscheduler-0.0.6.tar.gz | 4.4 kB | Without provenance | Details for tscheduler-0.0.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tscheduler-0.0.6-py3-none-any.whl | Python 3 | none | any | Details for tscheduler-0.0.6-py3-none-any.whl |
Total release size: 9.2 kB
Release files / tscheduler-0.0.6.tar.gz
| Download URL | tscheduler-0.0.6.tar.gz |
|---|---|
| Size | 4.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
de7b2b53e5118ca79cef43fd20f02c73e47e31bfa4a629f64c2c1f5a8bd63ff5
|
|
BLAKE2b-256 checksum How to use checksums |
5ae0eb2eafa8b6bcc5940f367ae46f6bbbe0ab519f06304a1c331d0ed56d1ead
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.1
|
Release files / tscheduler-0.0.6-py3-none-any.whl
| Download URL | tscheduler-0.0.6-py3-none-any.whl |
|---|---|
| Size | 4.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bfc65884211950bc7611dd404491c7144efcb71312e1269c9e4a62927e03f21d
|
|
BLAKE2b-256 checksum How to use checksums |
3b872f48addc7afb5e409f2032dfb6e6334119b311a84200dcb6c05ab741a826
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.1
|
Security for tscheduler 0.0.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.