Skip to main content

SeqQueue

Python queue implementations for incrementally indexed, sequential data. SeqQueue makes sure any get() call returnes the next (index, item) pair from the queue.

Installation

pip3 install seqqueue

Install from source:

git clone https://github.com/highvight/seqqueue
cd seqqueue
pip3 install .

To run tests and benchmarks:

pip3 install .[testing]

Or just copy and paste and one of the classes to your project

Usage

from seqqueue import SeqQueue

q = SeqQueue(start_index=0)
q.put((1, "1"))
q.put((2, "2"))
q.put((0, "0"))
print(q.get())  # (0, "0")
print(q.get())  # (1, "1")
print(q.get())  # (2, "2")

Note that Empty and Full exceptions are raised with respect to the index

from seqqueue import SeqQueue

q = SeqQueue(start_index=0, maxsize=2)
q.put((1,"1"))
print(q.qsize())  # 1
q.get(block=False)  #  Raises Empty, index=0 not available
q.put((2,"2"), block=False)  #  Raises Full, index=2 > maxindex

For multiprocessing, use multiprocessing.Manager

import multiprocessing as mp

from seqqueue import SeqQueue

manager = mp.Manager()
q = manager.SeqQueue(start_index=0)

Benchmark

Make sure to install [testing] (see Usage). In the project root run:

pytest benchmark

This will run some benchmarks for concurrent put() and get() calls in comparison to PriorityQueue from the standard library. As you can see, depending on the number of threads and maxsize of the queue, keeping incremental index order comes at a cost. For instance, for a maxsize=8 and n_threads=[1,2,20], on my Laptop, SeqQeue is ~ 2x-3x slower:

put=1, get=1 put=2, get=2 put=20, get=20
PriorityQueue 31.8575 (1.0) 56.9946 (1.79) 76.1026 (2.39)
SeqQeue 59.4795 (1.87) 82.9272 (2.60) 197.6096 (6.20)

If you find faster implementations please open a MR!

In real-world applications the costs of queue management are often negligible. Adjust the benchmark scripts with your real data and thread target functions to find out :)

License

MIT

Release files for seqqueue 0.4

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

Source distribution (sdist)

Source distribution for seqqueue 0.4
File Size Uploaded
seqqueue-0.4.tar.gz 6.4 kB Details

Built distribution (wheel)

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

Total release size: 11.6 kB

Release files / seqqueue-0.4.tar.gz

Download URL seqqueue-0.4.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
7c2696388529224bfdc30a21548488fe41170ce1c763ac5a5413a286288e41f0
BLAKE2b-256 checksum
How to use checksums
a50a90811285a006bcb2dea454ac6f9e5a6ddc953c7e39ddb4b30a602fdb4377
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release files / seqqueue-0.4-py3-none-any.whl

Download URL seqqueue-0.4-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a9475910712c134e4aa8c4fde688713975166f56066cfaca32f3bcc75bb00cab
BLAKE2b-256 checksum
How to use checksums
f736d47e710285a49465162a482cda66fff709f810c16f06c7a092bdadf15e30
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release history Release notifications | RSS feed

This release

0.4 This release

2 release files

0.3

2 release files

0.2

1 release file

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