Skip to main content

DoItLater

A simple python library to schedule work in the future with ability to loop infinitely. Does not depend on any 3rd party libraries.


Installation

The package can be simply installed using on of these methods:

  • pip: pip install doitlater
  • poetry: poetry add doitlater
  • poetry: poetry add git+https://github.com/evalkaz/doitlater.git

Usage

Simplest example:

from datetime import datetime, timedelta
from doitlater import Later

later = Later()

@later.on(datetime(2021, 1, 1))
def say_hello():
    print("Happy new years in 2021!")

if __name__ == "__main__":
    later.do()

To call the same function every 10 seconds with 30 seconds cold start:

@later.on(
    datetime.now() + timedelta(seconds=30),
    timedelta(seconds=10),
    loop=True
)
def repeatable_work():
    print("Hello every 10 seconds!")

The later.on() is stackable so this will work too (will be executed every 5 and every 7 days):

@later.on(datetime(2021, 1, 1), timedelta(days=5))
@later.on(datetime(2021, 1, 1), timedelta(weeks=1))
def say_hello():
    print("Happy new years in 2021!")

You can also pass a list of datetime or timedelta (or a mixed one) when to execute the function:

@later.on(datetime(2021, 1, 1), [
    datetime(2021, 2, 1),
    datetime(2021, 3, 1),
    timedelta(days=31)], loop=False)
def say_hello():
    print("Happy new years in 2021!")

If you want to stop executing the same function just return False:

@later.on(datetime(2021, 1, 1), timedelta(seconds=5), loop=True)
def only_one_hello():
    print("This will appear only once!")
    return False

If you have multiple functions and one of them throws an exception but you don't want to stop the work, pass ignore_errors=True to Later() object:

later = Later(ignore_errors=True)

By default, library will output logs on errors. To change logging, use dictConfig:

from datetime import datetime, timedelta
from doitlater import Later
from logging.config import dictConfig

dictConfig(
    {
        "version": 1,
        "formatters": {
            "default": {
                "format": "[%(asctime)s] %(levelname)s in %(module)s: %(message)s",
            }
        },
        "handlers": {
            "default": {"class": "logging.StreamHandler", "formatter": "default",}
        },
        "root": {"level": "INFO", "handlers": ["default"]},
    }
)

later = Later()

@later.on(datetime(2021, 1, 1))
def say_hello():
    print("Happy new years in 2021!")

if __name__ == "__main__":
    later.do()

API

Later(workers, ignore_errors) takes these parameters:

  • workers - number of threads to use, defaults to maximum number of threads supported by CPU.
  • ignore_errors - False will exit when one of the function throws an error, True - ignores exceptions and will resume the work.

later.on(exactly, repeat, loop) function takes these parameters:

  • exactly - on which time perform the first function call.
  • repeat - a single value or a list of datetime, timedelta or both on when to repeat the call. If None is passed the function will not be called again. Defaults to None.
  • loop - whether repeat calling times from repeat. Defaults to True.

later.do() does not take any parameters.

Metadata

Release files for doitlater 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for doitlater 0.1.2
File Size Uploaded
DoItLater-0.1.2.tar.gz 5.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for doitlater 0.1.2
File Interpreter ABI Platform
DoItLater-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 10.0 kB

Release files / DoItLater-0.1.2.tar.gz

Download URL DoItLater-0.1.2.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
92d4bb4c9c397d9baceeb441f676ca60bbf704a15f3130fa27d38d17ce5fec02
BLAKE2b-256 checksum
How to use checksums
0d825415e9adeee36ea3be33158c0004a2e67e26eedf78f3de9b5a24c41df802
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.0 CPython/3.6.9 Linux/4.4.0-148-generic

Release files / DoItLater-0.1.2-py3-none-any.whl

Download URL DoItLater-0.1.2-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4fbdf144a26164c3e3583e26916075acb46283a89382ba747c5b4844f7d522e1
BLAKE2b-256 checksum
How to use checksums
8ad43e89222c17369c188638dbf2b941d951dbafb9184995fcde7dc69ceb07cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.0 CPython/3.6.9 Linux/4.4.0-148-generic

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page