Skip to main content

A lightweight solution for long-running tasks

Project description

lilota

lilota is a lightweight Python library for executing long-running tasks in the background without the complexity of full task queue systems like Celery or RabbitMQ.

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

Features

  • Run long-running tasks in separate processes
  • Simple API and minimal configuration
  • Persistent task state stored in a database
  • No message broker required
  • Suitable for web applications and background jobs

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 and immediately return a response to the user.

Installation

pip install lilota

Quick example

Define input and output models

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

@dataclass
class AddInput:
  a: int
  b: int

@dataclass
class AddOutput:
  sum: int

Create a lilota instance

lilota = Lilota(
  name="My Server",
  db_url="postgresql+psycopg://postgres:postgres@localhost:5432/lilota_sample"
)

Register a background task

@lilota.register("add", input_model=AddInput, output_model=AddOutput)
def add(data: AddInput) -> AddOutput:
  return AddOutput(sum=data.a + data.b)

Start lilota

lilota.start()

Schedule a task

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

Task persistence

schedule will directly execute our function in a separate process. Information about the executed task are stored inside the database in the task table:

Columns Notes
id Primary key
name Task name
pid Process ID
status pending, running, completed, failed, cancelled
progress_percentage Progress (0-100)
start_date_time Start timestamp
end_date_time End timestamp
input Serialized input data
output Serialized output data
exception Exception details if the task fails

Shutdown

lilota.stop()

lilota will wait for running tasks to finish before exiting.

Full example

The full example can be found here: https://github.com/tobiasroessler/lilota-sample/blob/main/src/2-add-two-numbers.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lilota-0.2.1.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lilota-0.2.1-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file lilota-0.2.1.tar.gz.

File metadata

  • Download URL: lilota-0.2.1.tar.gz
  • Upload date:
  • Size: 17.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for lilota-0.2.1.tar.gz
Algorithm Hash digest
SHA256 9ffb06440673a7dc72f0607e2bc626c644b9a5675ae39abf1ab8e8c3959215f4
MD5 3ec43840a0c39a07725d45ccfe31d87e
BLAKE2b-256 40de43c601410b76e09e2d1db4564c26a14703d8df2d436e1237c4ef0e22afe2

See more details on using hashes here.

File details

Details for the file lilota-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: lilota-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for lilota-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b934c2a6441212505c64af88cef1ae3660ed588c05b3bf5c9eb736b8665f9b34
MD5 077c65b5435a5f8e81e7804b91c239a5
BLAKE2b-256 27545c1988c9b670b934f93f81734480c6fe3728ea8fc997e7bd4a4fb4d7073c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page