Skip to main content

Collection of persistent (disk-based) and non-persistent (memory-based) queues

Project description

https://img.shields.io/pypi/v/queuelib.svg https://img.shields.io/pypi/pyversions/queuelib.svg https://github.com/scrapy/queuelib/actions/workflows/tests-ubuntu.yml/badge.svg Coverage report

Queuelib is a Python library that implements object collections which are stored in memory or persisted to disk, provide a simple API, and run fast.

Queuelib provides collections for queues (FIFO), stacks (LIFO), queues sorted by priority and queues that are emptied in a round-robin fashion.

Queuelib supports Python 3.10+ and has no dependencies.

Installation

You can install Queuelib either via the Python Package Index (PyPI) or from source.

To install using pip:

$ pip install queuelib

To install using easy_install:

$ easy_install queuelib

If you have downloaded a source tarball you can install it by running the following (as root):

# python setup.py install

FIFO/LIFO disk queues

Queuelib provides FIFO and LIFO queue implementations.

Here is an example usage of the FIFO queue:

>>> from queuelib import FifoDiskQueue
>>> q = FifoDiskQueue("queuefile")
>>> q.push(b'a')
>>> q.push(b'b')
>>> q.push(b'c')
>>> q.pop()
b'a'
>>> q.close()
>>> q = FifoDiskQueue("queuefile")
>>> q.pop()
b'b'
>>> q.pop()
b'c'
>>> q.pop()
>>>

The LIFO queue is identical (API-wise), but importing LifoDiskQueue instead.

PriorityQueue

A discrete-priority queue implemented by combining multiple FIFO/LIFO queues (one per priority).

First, select the type of queue to be used per priority (FIFO or LIFO):

>>> from queuelib import FifoDiskQueue
>>> qfactory = lambda priority: FifoDiskQueue('queue-dir-%s' % priority)

Then instantiate the Priority Queue with it:

>>> from queuelib import PriorityQueue
>>> pq = PriorityQueue(qfactory)

And use it:

>>> pq.push(b'a', 3)
>>> pq.push(b'b', 1)
>>> pq.push(b'c', 2)
>>> pq.push(b'd', 2)
>>> pq.pop()
b'b'
>>> pq.pop()
b'c'
>>> pq.pop()
b'd'
>>> pq.pop()
b'a'

RoundRobinQueue

Has nearly the same interface and implementation as a Priority Queue except that each element must be pushed with a (mandatory) key. Popping from the queue cycles through the keys “round robin”.

Instantiate the Round Robin Queue similarly to the Priority Queue:

>>> from queuelib import RoundRobinQueue
>>> rr = RoundRobinQueue(qfactory)

And use it:

>>> rr.push(b'a', '1')
>>> rr.push(b'b', '1')
>>> rr.push(b'c', '2')
>>> rr.push(b'd', '2')
>>> rr.pop()
b'a'
>>> rr.pop()
b'c'
>>> rr.pop()
b'b'
>>> rr.pop()
b'd'

Mailing list

Use the scrapy-users mailing list for questions about Queuelib.

Bug tracker

If you have any suggestions, bug reports or annoyances please report them to our issue tracker at: http://github.com/scrapy/queuelib/issues/

Contributing

Development of Queuelib happens at GitHub: http://github.com/scrapy/queuelib

You are highly encouraged to participate in the development. If you don’t like GitHub (for some reason) you’re welcome to send regular patches.

All changes require tests to be merged.

Tests

Tests are located in queuelib/tests directory. They can be run using nosetests with the following command:

nosetests

The output should be something like the following:

$ nosetests
.............................................................................
----------------------------------------------------------------------
Ran 77 tests in 0.145s

OK

License

This software is licensed under the BSD License. See the LICENSE file in the top distribution directory for the full license text.

Versioning

This software follows Semantic Versioning

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

queuelib-1.9.0.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

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

queuelib-1.9.0-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file queuelib-1.9.0.tar.gz.

File metadata

  • Download URL: queuelib-1.9.0.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for queuelib-1.9.0.tar.gz
Algorithm Hash digest
SHA256 b12fea79fd8c1dd23e212b1f3db58003b773949801d4f4e6f34d882467d4a192
MD5 bf79a57ad71acb6c107faa2115a43795
BLAKE2b-256 76f3d80ab8c7c91b8c42d9a2aa4dd97a8be1321e7b26000c2675b75e641d958c

See more details on using hashes here.

Provenance

The following attestation bundles were made for queuelib-1.9.0.tar.gz:

Publisher: publish.yml on scrapy/queuelib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file queuelib-1.9.0-py3-none-any.whl.

File metadata

  • Download URL: queuelib-1.9.0-py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for queuelib-1.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c5fd3bebf2c924446fa94fca6b72e81168f79cf4c2a9143b8b26f266a423fcf3
MD5 e0b40121bf2510442bc8ca8423b8a306
BLAKE2b-256 4a1c8df7b461497b42fcc1e7c44529201975ec77b0e1ebecd00df4b1f096c1d4

See more details on using hashes here.

Provenance

The following attestation bundles were made for queuelib-1.9.0-py3-none-any.whl:

Publisher: publish.yml on scrapy/queuelib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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