Skip to main content

prqrs

Python priority queue in Rust via pyo3

pdm-managed license

The prqrs package provides a simple interface to a priority queue implemented in Rust. This guide will show you how to create a priority queue, add items to it, and retrieve items based on their priority.

Installation

To build the Rust project from source run:

maturin develop --release

Alternatively using the PDM package manager, just run pdm install.

Usage

Creating a Priority Queue

To create a priority queue, import the PriorityQueue class from the prqrs package and instantiate it:

from prqrs import PriorityQueue

pq = PriorityQueue()

Creating Items

Items that can be added to the priority queue need a value and a priority. Import the Item class and create items:

from prqrs import Item

item1 = Item(value=5, priority=3)  # An item with value 5 and priority 3
item2 = Item(value=10, priority=1) # An item with value 10 and priority 1

Adding Items to the Queue

Add items to the queue using the push method:

pq.push(item1)
pq.push(item2)

Retrieving Items from the Queue

Retrieve items based on their priority using the pop method. This method returns the item with the highest priority (lowest numerical value of priority):

highest_priority_item = pq.pop()
if highest_priority_item is not None:
    print(f"Value: {highest_priority_item.value}, Priority: {highest_priority_item.priority}")

Checking if the Queue is Empty

To check whether the priority queue is empty, use the is_empty method:

if pq.is_empty():
    print("The priority queue is empty.")
else:
    print("The priority queue is not empty.")

Example

Here is a complete example that demonstrates creating a priority queue, adding items, and retrieving them:

from prqrs import PriorityQueue, Item

# Create a priority queue
pq = PriorityQueue()

# Add items
pq.push(Item(value=5, priority=3))
pq.push(Item(value=10, priority=1))
pq.push(Item(value=7, priority=2))

# Retrieve and print items
while not pq.is_empty():
    item = pq.pop()
    print(f"Value: {item.value}, Priority: {item.priority}")

This will output

Value: 5, Priority: 3
Value: 7, Priority: 2
Value: 10, Priority: 1

Benchmarking

Running pdm install (or maturin develop) to install the Rust wheel followed by python benchmark_1m.py:

1.1 GHz CPU: (0.18+0.51)s

Enqueue time for 1 million items: 0.1798386573791504 seconds
Dequeue time for 1 million items: 0.5103330612182617 seconds

3.7 GHz CPU: (0.08+0.19)s

Enqueue time for 1 million items: 0.08250904083251953 seconds
Dequeue time for 1 million items: 0.1858220100402832 seconds

Metadata

Release files for prqrs 0.1.0

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

Source distribution (sdist)

Source distribution for prqrs 0.1.0
File Size Uploaded
prqrs-0.1.0.tar.gz 9.2 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for prqrs 0.1.0
File
prqrs-0.1.0-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl PyPy 3.10 PyPy 3.10 7.3 Linux glibc 2.17+ x86-64 Details
prqrs-0.1.0-pp310-pypy310_pp73-manylinux_2_5_i686.manylinux1_i686.whl PyPy 3.10 PyPy 3.10 7.3 Linux glibc 2.5+ x86-32 Details
prqrs-0.1.0-cp311-none-win_arm64.whl CPython 3.11 none Windows ARM64 Details
prqrs-0.1.0-cp311-none-win_amd64.whl CPython 3.11 none Windows x86-64 Details
prqrs-0.1.0-cp311-none-win32.whl CPython 3.11 none Windows x86-32 Details
prqrs-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details
prqrs-0.1.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.whl CPython 3.11 CPython 3.11 Linux glibc 2.5+ x86-32 Details
prqrs-0.1.0-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details
prqrs-0.1.0-cp311-cp311-macosx_10_12_x86_64.whl CPython 3.11 CPython 3.11 macOS 10.12+ x86-64 Details
prqrs-0.1.0-cp310-none-win_arm64.whl CPython 3.10 none Windows ARM64 Details
prqrs-0.1.0-cp310-none-win_amd64.whl CPython 3.10 none Windows x86-64 Details
prqrs-0.1.0-cp310-none-win32.whl CPython 3.10 none Windows x86-32 Details
prqrs-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details
prqrs-0.1.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.whl CPython 3.10 CPython 3.10 Linux glibc 2.5+ x86-32 Details

Total release size: 5.2 MB

Release files / prqrs-0.1.0.tar.gz

Download URL prqrs-0.1.0.tar.gz
Size 9.2 kB
Tags Source
SHA-256 checksum
How to use checksums
a29fa25bac7fe0d38dcbafbbda0013bdb33951eb215010890aefdfb7e4c0e7cd
BLAKE2b-256 checksum
How to use checksums
e19aeb5d2990179d2b4c41497b1bb5ece54985004f5b4ecd9a3b0fe52d456ecf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.4.0

Release files / prqrs-0.1.0-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL prqrs-0.1.0-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 655.8 kB
Tags Linux glibc 2.17+ x86-64 PyPy 3.10 PyPy 3.10 7.3
SHA-256 checksum
How to use checksums
fef87fe58ce1d1c82f9dbf9305733782470523025e3b1e870cbc292aea609c37
BLAKE2b-256 checksum
How to use checksums
a18d71feba24360bd2310602fb6b866850cf78c209d409dca96f4954e4620ae6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.4.0

Release files / prqrs-0.1.0-pp310-pypy310_pp73-manylinux_2_5_i686.manylinux1_i686.whl

Download URL prqrs-0.1.0-pp310-pypy310_pp73-manylinux_2_5_i686.manylinux1_i686.whl
Size 663.4 kB
Tags Linux glibc 2.5+ x86-32 PyPy 3.10 PyPy 3.10 7.3
SHA-256 checksum
How to use checksums
04fbc02e82a886e1509b6a6ebf2fa96c75a3e072bacd9f8104f919fac02b6745
BLAKE2b-256 checksum
How to use checksums
adf2d31d3a1b1b31ed4caeb654d91ea960ec04cd25940dbf15be041b8e4fdf09
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.4.0

Release files / prqrs-0.1.0-cp311-none-win_arm64.whl

Download URL prqrs-0.1.0-cp311-none-win_arm64.whl
Size 123.3 kB
Tags CPython 3.11 Windows ARM64
SHA-256 checksum
How to use checksums
a91cc111ee36236ce0a28afd64cce0c30e2f7fa67b9d8529de34c8ba0a382c55
BLAKE2b-256 checksum
How to use checksums
a216974eb38897613715de0f9ae769e22c6479ee7cf805bb6f7324999b1a33f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.4.0

Release files / prqrs-0.1.0-cp311-none-win_amd64.whl

Download URL prqrs-0.1.0-cp311-none-win_amd64.whl
Size 129.1 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
c5645f7a73fa241d64499a9853bea6b6021ae4520b74ea58d203eb65e3185973
BLAKE2b-256 checksum
How to use checksums
6f083240f37fb6344ce5daf2c6d959803df681b5d2e0a13e97de037ffd31b346
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.4.0

Release files / prqrs-0.1.0-cp311-none-win32.whl

Download URL prqrs-0.1.0-cp311-none-win32.whl
Size 123.6 kB
Tags CPython 3.11 Windows x86-32
SHA-256 checksum
How to use checksums
75265aedf395a9f596e0a213db4d2505bcfb47dbeefb909be2ad1bff7e44caf8
BLAKE2b-256 checksum
How to use checksums
19a9d7ff007553401ba993b34e273753b376fc4af2f5ebcbd5b911d340a31389
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.4.0

Release files / prqrs-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL prqrs-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 655.8 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
cc19bba654305b66547f338d136fd4b17283ed178de60321f2a14a69881c39f6
BLAKE2b-256 checksum
How to use checksums
ac945044ba46fd24fa71584e9f1da7ac46845a4cc79c08972cbe0900cd85e005
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.4.0

Release files / prqrs-0.1.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.whl

Download URL prqrs-0.1.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.whl
Size 663.5 kB
Tags CPython 3.11 Linux glibc 2.5+ x86-32
SHA-256 checksum
How to use checksums
5a098ac9219653429116bcd7ccc392434c96c8bdf64729c5526f0503b7bb1013
BLAKE2b-256 checksum
How to use checksums
740a7de07456524add5a9f768c6111cb702ce189e03a17539d11fb6171f33449
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.4.0

Release files / prqrs-0.1.0-cp311-cp311-macosx_11_0_arm64.whl

Download URL prqrs-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
Size 243.0 kB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
b8e6a846eafda0b251ec55d91d8a586dc734f4991e415b24dd7a493b03a6525e
BLAKE2b-256 checksum
How to use checksums
fad19cbf8631d0421022929c44e629345eeec0214a93379f188231b38115328c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.4.0

Release files / prqrs-0.1.0-cp311-cp311-macosx_10_12_x86_64.whl

Download URL prqrs-0.1.0-cp311-cp311-macosx_10_12_x86_64.whl
Size 248.4 kB
Tags CPython 3.11 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
825e614d156c5c0b7835ea34eed2c598d07df300a2dc3e69bc678cf69df2e9d7
BLAKE2b-256 checksum
How to use checksums
a110328f37f3faa3a514e888bb62796745062186e7a99a711fceaeb060e89519
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.4.0

Release files / prqrs-0.1.0-cp310-none-win_arm64.whl

Download URL prqrs-0.1.0-cp310-none-win_arm64.whl
Size 123.3 kB
Tags CPython 3.10 Windows ARM64
SHA-256 checksum
How to use checksums
ab8799bf958f32c6f638d7fee4efb3cf184db4c354f5f452c8d96aa2fa055ecf
BLAKE2b-256 checksum
How to use checksums
003e4238ff7694c57bf866f98b1b428586d7408d57544cd4d53b57b8c6c0a5da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.4.0

Release files / prqrs-0.1.0-cp310-none-win_amd64.whl

Download URL prqrs-0.1.0-cp310-none-win_amd64.whl
Size 129.1 kB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
cc0c7990188dc30a4b19661a6f487771f7cfda060160d2a41e216556a91d0ed2
BLAKE2b-256 checksum
How to use checksums
14cb000db48a2a9a59ca0307190ffd42b235315425f5cf9776911b86dcee63ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.4.0

Release files / prqrs-0.1.0-cp310-none-win32.whl

Download URL prqrs-0.1.0-cp310-none-win32.whl
Size 123.6 kB
Tags CPython 3.10 Windows x86-32
SHA-256 checksum
How to use checksums
b3d765314843d6615ed67b4a25a792eeffca45c4d430ecce2ec2956ac3507fd6
BLAKE2b-256 checksum
How to use checksums
e7ba45deac5f0cbc661d24421af13fe691abf32102b98efa748eb9fcaac15c8b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.4.0

Release files / prqrs-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL prqrs-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 655.8 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
fb78ee9e1aae12b06f30fc8850138a45692c068c8cfaa6474091999d026211c9
BLAKE2b-256 checksum
How to use checksums
f5262894f2d52b5202802856a360e6d579b483ac3bf36b0ab21ef4ee32bd2ae0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.4.0

Release files / prqrs-0.1.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.whl

Download URL prqrs-0.1.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.whl
Size 663.5 kB
Tags CPython 3.10 Linux glibc 2.5+ x86-32
SHA-256 checksum
How to use checksums
31178b6f25326da2f1bdd83d8db1f23020cb9e618206264ed4415643cb61e30f
BLAKE2b-256 checksum
How to use checksums
b9609876c1511e0887f925753381a45ca7cb0ab447235dead691451b40835e9e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.4.0

Release history Release notifications | RSS feed

This release

0.1.0 This release

15 release files

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