High-performance persistent FIFO queues with LMDB backend supporting both single-queue and multi-queue broadcast patterns.
Project description
nque - Persistent FIFO Queue Implementation in Python
nque is a Python library that implements persistent FIFO queues backed by LMDB (Lightning
Memory-Mapped Database). Suitable for building data pipelines and handling data exchange between producer and consumer
processes. The queues operate in memory for performance while persisting data to disk for reliability. For detailed API
information and usage examples, please refer to the class and method docstrings.
Features
- Transaction-safe operations
- Two queue implementations:
- Basic FIFO queue (
FifoBasicQueueLmdb) for single queue scenarios - Multi-queue system (
FifoMultiQueueLmdb) supporting multiple named queues with broadcast capability
- Basic FIFO queue (
- Configurable queue size and item size limits
Requirements
- Python 3.10+
- LMDB
Installation
pip install nque
Usage Examples
Basic FIFO Queue
from nque import FifoBasicQueueLmdb
# Initialize queue with max 1000 items of max 20 KB each
queue = FifoBasicQueueLmdb(
db_path="queue",
items_count_max=1000,
item_bytes_max=20 * 1024
)
# Add items
queue.put([b"item1", b"item2"])
# Get items without removing (peek)
items = queue.get(2)
# Remove items after successful processing
queue.remove(2)
# Get and remove items atomically
items = queue.pop(2)
Multi-Queue System
from nque import FifoMultiQueueLmdb
# Create producer that broadcasts to all internal named queues
producer = FifoMultiQueueLmdb(
db_path="multiqueue",
queues=(b"queue1", b"queue2")
)
# Create consumer for specific internal queue
consumer = FifoMultiQueueLmdb(
db_path="multiqueue",
queues=(b"queue1", b"queue2"),
use=b"queue1"
)
# Broadcast to all queues atomically
producer.put([b"broadcast_message"])
# Consume from specific queue
items = consumer.pop(1)
Error Handling
The library provides three exception types:
QueueError: Base exception for general queue operationsArgumentError: Invalid argument errorsTryLater: Temporary condition preventing operation completion
Performance Considerations
- Queue max size is pre-defined using max items and item size
- Write operations (both producers and consumers) are serialized through LMDB's internal locking
API Reference
Common Queue Parameters
db_path: Path to the LMDB database storing the queue dataitems_count_max: Maximum number of items in the queue (default: 1000)item_bytes_max: Maximum size of each item in bytes (default: 20KB)
Multi-Queue Additional Parameters
queues: Names of internal queues producers broadcast touse: Name of queue to consume from (for consumers only)
Common Methods
put(items): Add items to the queueget(items_count): Retrieve items without removingremove(items_count): Remove items from the queuepop(items_count): Atomic get and remove operation
Best Practices and Error Prevention
- Use
get()to retrieve items first, then callremove()after successful processing - Use
pop()for atomic operations, particularly when concurrent consumers are needed - Implement retry logic for
TryLaterexceptions
Limitations
- Write operations (including from consumers) are serialized
- Get/remove operation pattern requires single consumer per queue
- Multi-queue supports maximum of 10 internal queues
- LMDB constraints apply to overall performance
Future Development
The nque library is designed with extensibility in mind. Future development areas may include:
- Support for monitoring and metrics capabilities
- Additional queue patterns and implementations
- Support for additional backend storage systems beyond LMDB
Suggestions and contributions are welcome.
Author
Artur Khakimau
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nque-1.0.1.tar.gz.
File metadata
- Download URL: nque-1.0.1.tar.gz
- Upload date:
- Size: 12.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d0f091ee1920452e3385d4d7746e4d8f919e2a54dbe35878fdc4100ae492713
|
|
| MD5 |
5bd9494c416c7dcf8ac3cde19ab2ab09
|
|
| BLAKE2b-256 |
09880d95ba78b2f97f224af96d602eaa7dd26eb07c7b6defa66ea047b3cf853b
|
File details
Details for the file nque-1.0.1-py3-none-any.whl.
File metadata
- Download URL: nque-1.0.1-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e4eed49622df65c7ead72bdb6b8709795a774e1dd9ec2b9e17d419ecf2b3bb5e
|
|
| MD5 |
8ceb666644b605cbaf7841bcb286172b
|
|
| BLAKE2b-256 |
6320a9e02614ae968d59409a9c7902947ceb38d40b15e4ac5d9a0f2021883f47
|