Skip to main content

lilota

lilota is a lightweight Python library for executing long-running tasks in the background without the overhead of full-fledged task queue systems. While those tools are powerful and valuable, lilota focuses on scenarios where a simpler approach is sufficient.

It is designed for simple, asynchronous task execution with minimal setup and overhead.

Features

  • Run long-running tasks
  • Simple API and minimal configuration and setup
  • Persistent task state stored in a database
  • No message broker required
  • Suitable for applications that use background jobs, i.e. web applications.

When to use lilota

Use lilota when your application needs to run tasks that take time, such as:

  • image or file processing
  • report generation
  • sending emails
  • heavy computations

Instead of blocking the request, lilota lets you start the task in the background.

Installation

pip install lilota

Quick example

This example demonstrates how to add two numbers using a function that runs in the background.

This could, of course, also be a function that generates a report or performs a heavy computation. For simplicity, we will just add two numbers.

First, we have to create a script that has an instance of a worker (LilotaWorker). This worker registers one or several task-functions that can be executed later by a scheduler.

myscript.py

from dataclasses import dataclass
from lilota.worker import LilotaWorker


@dataclass
class AddInput():
    a: int
    b: int


@dataclass
class AddOutput():
  sum: int


worker = LilotaWorker()


@worker.task
def add(input: AddInput) -> AddOutput:
  return AddOutput(input.a + input.b)


def main():
  worker.start()


if __name__ == "__main__":
  main()

Integration of lilota

The script created above is passed to a Lilota instance for execution.

Note: The script must start the worker by calling worker.start(). Each worker process runs the script as its entry point, and a script that ends without starting a worker is treated as a fatal error (see lilota.error).

That instance can start multiple processes, each of which executes the script once. By default, it starts one worker process. You can specify the number of workers for a Lilota instance with number_of_workers. A worker executes one task at a time, so this is the number of tasks that can be executed in parallel. See Number of workers for what a worker costs.

In this example, we use two model classes: one for input arguments and one for the output. These models should typically be defined in their own module and shared between Lilota and LilotaWorker.

from dataclasses import dataclass
from lilota.core import Lilota
from lilota.models import Task
import time


@dataclass
class AddInput():
    a: int
    b: int


@dataclass
class AddOutput():
  sum: int


lilota = Lilota(
  script_path="sample/myscript.py",
  number_of_workers=8
)


def main():
  # Start lilota
  lilota.start()

  # Schedule a task
  task_id = lilota.schedule("add", AddInput(a=2, b=3))

  # Wait one second because Lilota runs in the background and decides when to pick up a task.
  # This is normally not needed. We do it here because we want to wait until the task 
  # has been executed.
  time.sleep(1)

  # Retrieve task information from the database and print the result
  task: Task = lilota.get_task_by_id(task_id)
  print(f"We add the numbers 2 and 3: ")
  print(task.output)


if __name__ == "__main__":
  main()

Documentation

https://tobiasroessler.github.io/lilota/

Examples

Example URL
A simple "Hello World" example 1-hello-world
Add two numbers using an input and an output model 2-add-two-numbers
Add two numbers using a pydantic input and an output model 3-add-two-numbers-using-pydantic
Database access inside the task function 4-using-db-inside-task
Set the task progress manually in a task function 5-setting-task-progress-manually
Use a worker script that uses modules 6-script-with-modules
Use class methods to create a scheduler and workers 7-using-factory-methods

Metadata

Release files for lilota 1.3.0

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

Source distribution (sdist)

Source distribution for lilota 1.3.0
File Size Uploaded Provenance Actions
lilota-1.3.0.tar.gz 65.9 kB Without provenance Details for lilota-1.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for lilota 1.3.0
File Interpreter ABI Platform Actions
lilota-1.3.0-py3-none-any.whl Python 3 none any Details for lilota-1.3.0-py3-none-any.whl

Total release size: 109.4 kB

Release files / lilota-1.3.0.tar.gz

Download URL lilota-1.3.0.tar.gz
Size 65.9 kB
Tags Source
SHA-256 checksum
How to use checksums
9a8940e6f64b54928e232e78645c5788513d06fb7110f97aa453b79106ffa5af
BLAKE2b-256 checksum
How to use checksums
f1b169cba729bf8e8722767927581832fdd2bfef8a7a87d6b876c51fb7542269
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / lilota-1.3.0-py3-none-any.whl

Download URL lilota-1.3.0-py3-none-any.whl
Size 43.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
13aa1b07af58caf87617ca924cfd0b30854f3322ee0a289ff6a49480c4e75a4d
BLAKE2b-256 checksum
How to use checksums
15ad1f7850c76a994452b6842ec78252bf9ed9a23a5bab52ab0304912a7702b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for lilota 1.3.0

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.

Release history Release notifications | RSS feed

This release

1.3.0 This release

2 release files No provenance

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