/diskq

DiskQ is a Python package that provides persistent queues using disk storage.

Primary LanguagePythonApache License 2.0Apache-2.0

DiskQ

codecov PyPI PyPI - Python Version Downloads GitHub top language GitHub stars https://blog.csdn.net/flower_drop autofix enabled

DiskQ is a Python library for persistent queue management. It allows you to store queue data on disk, making it easier to manage your data and prevent data loss in the event of system crashes or power outages.

Installation

You can install DiskQ using pip:

pip install diskq

Usage

PersistentQueue

The PersistentQueue class is used to create a persistent queue. Here's an example:

from diskq import PersistentQueue

# create a new persistent queue
queue = PersistentQueue('my_queue.pkl')

# add items to the queue
queue.put('item1')
queue.put('item2')
queue.put('item3')

# get items from the queue
item1 = queue.get()
item2 = queue.get()
item3 = queue.get()

PersistentPriorityQueue

The PersistentPriorityQueue class is used to create a persistent priority queue. Here's an example:

from diskq import PersistentPriorityQueue

# create a new persistent priority queue
queue = PersistentPriorityQueue('my_priority_queue.pkl')

# add items to the queue with priorities
queue.put((1, 'item1'))
queue.put((2, 'item2'))
queue.put((3, 'item3'))

# get items from the queue in order of priority
item1 = queue.get()
item2 = queue.get()
item3 = queue.get()

PersistentLifoQueue

The PersistentLifoQueue class is used to create a persistent last-in, first-out (LIFO) queue. Here's an example:

from diskq import PersistentLifoQueue

# create a new persistent LIFO queue
queue = PersistentLifoQueue('my_lifo_queue.pkl')

# add items to the queue
queue.put('item1')
queue.put('item2')
queue.put('item3')

# get items from the queue in reverse order
item3 = queue.get()
item2 = queue.get()
item1 = queue.get()

License

This project is licensed under the MIT License. See the LICENSE file for details.