Skip to main content

Simple queue built on top of SQLite

Project description


Queue implemented on top of SQLite


You can use this to implement a persistent queue. It also has extra timing metrics for the messages/tasks, and the api to set a message as done lets you specifiy the message_id to be set as done.

Since it's all based on SQLite / SQL, it is easily extendable.

Messages are always passed as strings, so you can use json data as messages. Messages are interpreted as tasks, so after you pop a message, you need to mark it as done when you finish processing it. When you run the .prune() method, it will remove all the finished tasks from the database.


pip install litequeue


from litequeue import LiteQueue

q = LiteQueue(":memory:")


# Message object used by LiteQueue
# Message(data='world', message_id=UUID('063e95f1-3d9f-7547-8000-c3eb531fff93'), status=<MessageStatus.READY: 0>, in_time=1676238611851409010, lock_time=None, done_time=None)

task = q.pop()

# Message(data='hello', message_id='063e95f1-3d9e-7bbc-8000-a6a18a5f65d1', status=1, in_time=1676238611851279408, lock_time=1676238623180543854, done_time=None)



# Message(
#     data='hello',
#     message_id='063e95f1-3d9e-7bbc-8000-a6a18a5f65d1',
#     status=2,                <---- status is now 2 (DONE)
#     in_time=1676238611851279408,
#     lock_time=1676238623180543854,
#     done_time=1676238641276753673
# )

Check out the docs page for more.

Differences with a normal Python queue.Queue

  • Persistence
  • Different API to set tasks as done (you tell it which message_id to set as done)
  • Timing metrics. As long as tasks are still in the queue or not pruned, you can see how long they have been there or how long they took to finish.
  • Easy to extend using SQL

Examples and bechmarks and bechmarks

You can have a look at the file. The tests are short and showcase different usage scenarios.

The benchmark.ipynb file contains some benchmarks comparing litequeue to the built-in Python queue.Queue.


Ricardo Ander-Egg Aguilar – @ricardoanderegg

Distributed under the MIT license. See LICENSE for more information.

Important changes

  • In version 0.6:
    • The database schema has changed and the column message is now data.
    • Time is still measured as an integer, but now it's using nanoseconds.
    • Messages are represented as a frozen dataclass, not as a dictionary.
    • Message IDs are uuidv7 strings.
  • In version 0.4 the database schema has changed and the column task_id is now message_id.


The only hard rules for the project are:

  • No extra dependencies allowed
  • No extra files, everything must be inside file.
  • Tests must be inside the file.

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

litequeue-0.7.tar.gz (8.5 kB view hashes)

Uploaded source

Built Distribution

litequeue-0.7-py3-none-any.whl (8.8 kB view hashes)

Uploaded py3

Supported by

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