GitHunt

fastqueue

Tests
PyPI versions
PyPI license
PyPI

Single-ended fast queues built in C tuned for Python.

Requirements

  • python 3.7+

Installation

To install fastqueue, using pip:

pip install fastqueue-lib

Quickstart

For general use cases fastqueue.Queue() objects are tuned to perform well.
The enqueue and dequeue methods perform well over a large sequence of arbitrary operations.
fastqueue.Queue() supports many standard sequence methods similar to lists.
fastqueue.Queue() minimizes memory usage but maintains the fast queue speeds.

>>> from fastqueue import Queue
>>> queue = Queue()
>>> queue.extend(['๐Ÿš’', '๐Ÿ›ด'])
>>> queue[0]
'๐Ÿš’'
>>> '๐Ÿ›ด' in queue
True
>>> queue.enqueue('๐Ÿš…')
>>> queue.enqueue('๐Ÿš—')
>>> queue[-1]
'๐Ÿš—'
>>> [queue.dequeue() for _ in range(len(queue)) ]
['๐Ÿš’', '๐Ÿ›ด', '๐Ÿš…', '๐Ÿš—']

For more specialized cases fastqueue.QueueC() objects are tuned to perform well.
The interface for fastqueue.QueueC() is identical to fastqueue.Queue().
The enqueue and dequeue methods perform similarly well over a large sequence of arbitrary operations.
fastqueue.QueueC() handles memory differently by doubling the capacity when full.
This increases the complexity but maintains fast amortized cost.
The benefit of this approach is even faster __getitem__ and __setitem__ speeds

>>> from fastqueue import QueueC

>>> queue_c = QueueC()
>>> queue_c.extend(['๐Ÿš’', '๐Ÿ›ด'])
>>> queue_c[0]
'๐Ÿš’'
>>> '๐Ÿ›ด' in queue_c
True
>>> queue_c.enqueue('๐Ÿš…')
>>> queue_c.enqueue('๐Ÿš—')
>>> queue_c[-1]
'๐Ÿš—'
>>> [queue_c.dequeue() for _ in range(len(queue_c)) ]
['๐Ÿš’', '๐Ÿ›ด', '๐Ÿš…', '๐Ÿš—']

Another alternative is fastqueue.LockQueue() which supports all queue operations.
fastqueue.LockQueue() is built as a thread-safe alternative to the other queue types.

Example Benchmarks

Queue operations

Ubuntu

Queue_times
Queue_types_linux

Windows

Queue_times
Queue_types

Iteration

Ubuntu

Iterable_Instantiation
Iterable_Iteration

Windows

Iterable_Instantiation
Iterable_Iteration

Languages

C59.9%Python30.7%C++8.7%Makefile0.7%

Contributors

MIT License
Created April 13, 2023
Updated March 2, 2025
MatthewAndreTaylor/fastqueue | GitHunt