A fast implementation of an Israeli Queue
Project description
Israeli Queue
A fast Python (Cython) implementation of an Israeli Queue.
Table of Contents
- Overview
- What is an Israeli Queue?
- Installation
- Classes
- Documentation
- Complexity
- Synchronous Example
- Asynchronous Example
- License
Overview
This project implements a queue system where each item is associated with a "group." The queue processes items in groups, ensuring that items belonging to the same group are dequeued together. This implementation provides both a synchronous version (IsraeliQueue
) and an asynchronous version (AsyncIsraeliQueue
) using asyncio
.
What is an Israeli Queue?
An Israeli Queue is a type of a priority queue where tasks are grouped together in the same priority. Adding new tasks to the queue will cause them to skip the line and group together. The tasks will then be taken out in-order, group by group.
Why is this useful?
IsraeliQueues enjoy many benefits from processing grouped tasks in batches. For example, imagine a bot or an API that requires logging in to a remote repository in order to bring files:
def login(repo_name: str):
return Session("repo_name") # Expensive operation
def download_file(session: Session, filename: str):
return Session.download(filename)
def logout(session: Session):
session.logout
Now, we have a thread or an asyncio task that adds files to download to the queue:
from israeliqueue import IsraeliQueue
queue = IsraeliQueue()
queue.put("cpython", "build.bat")
queue.put("black", "pyproject.toml")
queue.put("black", "bar") # Same repo as the second item
queue.put("cpython", "index.html") # Same repository as the first item
An ordinary queue will cause our bot to login and logout four times, processing each item individually. The IsraeliQueue groups the repositories together, saving setup costs and allowing to download them all in the same request:
while True:
group, items = queue.get_group()
session = login(group)
for item in items:
download_file(session, item)
logout(session)
If the downloading process accepts multiple files at once, it's even more efficient:
session.download_files(*items)
Other uses may include batching together AWS queries, batching numpy calculations, and plenty more!
Installation
To install the package, simply pip install cisraeliqueue
.
You can use the classes in your project as follows:
from israeliqueue import IsraeliQueue, AsyncIsraeliQueue
Classes
IsraeliQueue
This is the synchronous implementation of the Israeli Queue. It provides group-based task processing and supports both blocking and non-blocking queue operations. The class is thread-safe and can be used in multithreaded environments.
AsyncIsraeliQueue
This is the asynchronous version of the Israeli Queue, built using Python's asyncio
framework. It provides non-blocking, asynchronous methods for queue operations and is suitable for applications requiring high concurrency and asynchronous task management.
Documentation
Full documentation exists on our RTD page.
Complexity
- put / put_nowait: O(1) - Insertion at the end of the queue.
- get / get_nowait: O(1) - Dequeueing from the front of the queue.
- get_group / get_group_nowait: O(group) - Dequeueing all items from the same group.
- task_done: O(1) - Simple bookkeeping to track completed tasks.
- join: O(1) - Blocks until all tasks are done
Synchronous Example
from israeliqueue import IsraeliQueue
# Initialize the queue
queue = IsraeliQueue(maxsize=10)
# Add items to the queue
queue.put('group1', 'task1')
queue.put('group1', 'task2')
queue.put('group2', 'task3')
# Get items from the queue
group, task = queue.get()
print(f"Processing {task} from {group}")
# Get all items from the same group
group, tasks = queue.get_group()
print(f"Processing all tasks from {group}: {tasks}")
# Mark the task as done
queue.task_done()
# Wait for all tasks to complete
queue.join()
Asynchronous Example
import asyncio
from israeliqueue import AsyncIsraeliQueue
async def main():
# Initialize the queue
queue = AsyncIsraeliQueue(maxsize=10)
# Add items to the queue
await queue.put('group1', 'task1')
await queue.put('group1', 'task2')
await queue.put('group2', 'task3')
# Get items from the queue
group, task = await queue.get()
print(f"Processing {task} from {group}")
# Get all items from the same group
group, tasks = await queue.get_group()
print(f"Processing all tasks from {group}: {tasks}")
# Mark the task as done
queue.task_done()
# Wait for all tasks to complete
await queue.join()
# Run the async example
asyncio.run(main())
License
This project is licensed under the MIT 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 Distributions
Built Distributions
File details
Details for the file cisraeliqueue-0.0.1a2-cp313-cp313-win_amd64.whl
.
File metadata
- Download URL: cisraeliqueue-0.0.1a2-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 80.1 kB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9efc3dd4ddb2e3f57a60f282bbef4513d25eaf0a7c063f40765e02a54cc923eb |
|
MD5 | c03ff554cc60b03c7e5cd7f99862b0d6 |
|
BLAKE2b-256 | 837a99afd1b92c40f5b84487b4d8d926930e1a7acec193060735d5a5ac3d4a97 |
File details
Details for the file cisraeliqueue-0.0.1a2-cp313-cp313-win32.whl
.
File metadata
- Download URL: cisraeliqueue-0.0.1a2-cp313-cp313-win32.whl
- Upload date:
- Size: 70.7 kB
- Tags: CPython 3.13, Windows x86
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0cc11fd86d8f2d92cea0ac3c8371d6442bde8f3b3f02209d764a02d59ee38410 |
|
MD5 | 9dde199157884b41820754480f0cd20e |
|
BLAKE2b-256 | 41a92d218de1b86c4dddaf60506c97d155d0495fd14f8b3e7dce2de2c9eb78f3 |
File details
Details for the file cisraeliqueue-0.0.1a2-cp313-cp313-musllinux_1_2_x86_64.whl
.
File metadata
- Download URL: cisraeliqueue-0.0.1a2-cp313-cp313-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 513.0 kB
- Tags: CPython 3.13, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d0b0107a05b49692360214cf4ce7360cf3d3912b3ba1a826fab801424a18e63c |
|
MD5 | 2e1820a788203cd0b3d2268d285f656b |
|
BLAKE2b-256 | be6914d1ddb709ec8dc0b2ca1203828454fa3f569c167ef5e5a5f7930661b02f |
File details
Details for the file cisraeliqueue-0.0.1a2-cp313-cp313-musllinux_1_2_i686.whl
.
File metadata
- Download URL: cisraeliqueue-0.0.1a2-cp313-cp313-musllinux_1_2_i686.whl
- Upload date:
- Size: 491.9 kB
- Tags: CPython 3.13, musllinux: musl 1.2+ i686
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7555e5e6639e9bae5cdabb28a1bfca845f774d72e540780df1290b07f3f28da9 |
|
MD5 | 0f77081f7b4fb74615945b98c3f433aa |
|
BLAKE2b-256 | 4f75a8b7558f8d7432f8104d18d4fa8e7594bca76e156226d5e377dc30465133 |
File details
Details for the file cisraeliqueue-0.0.1a2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: cisraeliqueue-0.0.1a2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 504.9 kB
- Tags: CPython 3.13, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e6aab06c79058347c0482f723ea6ac7a45d6c8ec91a6c525720b209cf4d9e0f |
|
MD5 | 33d68cf34fb44be599363f474f5a4f62 |
|
BLAKE2b-256 | 44c6896912db41812dbc89144008f6a911a9d3704f65c20e80db9e8a8f022e59 |
File details
Details for the file cisraeliqueue-0.0.1a2-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
.
File metadata
- Download URL: cisraeliqueue-0.0.1a2-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
- Upload date:
- Size: 479.5 kB
- Tags: CPython 3.13, manylinux: glibc 2.17+ i686, manylinux: glibc 2.5+ i686
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f359720be3460193dcc93067bb396c10b0c6e0baf186024399bbb775d7eec8d4 |
|
MD5 | 1789eb3bca1e9036e360584df0426a9a |
|
BLAKE2b-256 | 7ce28d93a4f553777a9a6f659b1e485cc37ae5d0a0734641e0e682383f5747d2 |
File details
Details for the file cisraeliqueue-0.0.1a2-cp313-cp313-macosx_11_0_arm64.whl
.
File metadata
- Download URL: cisraeliqueue-0.0.1a2-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 89.8 kB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3fa37b0fccc08ffbd6fc9198123c6f7825b9004a158f358cd328df7804919238 |
|
MD5 | c82e6d351202976c381729761643307e |
|
BLAKE2b-256 | ddff9bff0f3ddb3a410b1153a660a30f6aa503d76327f493159823bc95dadaa5 |
File details
Details for the file cisraeliqueue-0.0.1a2-cp313-cp313-macosx_10_13_x86_64.whl
.
File metadata
- Download URL: cisraeliqueue-0.0.1a2-cp313-cp313-macosx_10_13_x86_64.whl
- Upload date:
- Size: 93.7 kB
- Tags: CPython 3.13, macOS 10.13+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c50bd5c8509231cc590dc795ae55fbcf5244e3b9263e62f97114dda5ee1f438 |
|
MD5 | 7ee3f3a67cbcc8453ab64575d55963cb |
|
BLAKE2b-256 | 19b179f0b493e65b8d7e362a9f8131dea1636ee20c7ce3fae01f82decb2b2881 |
File details
Details for the file cisraeliqueue-0.0.1a2-cp312-cp312-win_amd64.whl
.
File metadata
- Download URL: cisraeliqueue-0.0.1a2-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 80.4 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c2689ed47e94efb9c302ce85b9d450a6b926d9785f277ab93e8c536ca8ea83ea |
|
MD5 | 41c28131d7fc7ee408f67ebb1b713a80 |
|
BLAKE2b-256 | 8d27fa11d29b2ba4c1e21c8d0498c51ac9d299541fbc7a20f1cb342cb997a4f9 |
File details
Details for the file cisraeliqueue-0.0.1a2-cp312-cp312-win32.whl
.
File metadata
- Download URL: cisraeliqueue-0.0.1a2-cp312-cp312-win32.whl
- Upload date:
- Size: 70.7 kB
- Tags: CPython 3.12, Windows x86
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88e99f8ba3d502a164a97071a123821841235991b118c1ee3bd065ae78ae972c |
|
MD5 | 7a7a66dd028921a011d5a81f66fbfeb4 |
|
BLAKE2b-256 | 94104b35622de0a58c95f123a3f655ace94a1403d3acd1d5e278bd18331e6490 |
File details
Details for the file cisraeliqueue-0.0.1a2-cp312-cp312-musllinux_1_2_x86_64.whl
.
File metadata
- Download URL: cisraeliqueue-0.0.1a2-cp312-cp312-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 507.8 kB
- Tags: CPython 3.12, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | df781fee212090bf6c3e69a540a985ac4f1eff12cd3ebcc1363cedc59aacd043 |
|
MD5 | b638cca84964817ddde31948c5a297fb |
|
BLAKE2b-256 | 2992dff8c4d951ef02ea0a66f9b06128d2213958929ed33af2378e49a8e9bdd1 |
File details
Details for the file cisraeliqueue-0.0.1a2-cp312-cp312-musllinux_1_2_i686.whl
.
File metadata
- Download URL: cisraeliqueue-0.0.1a2-cp312-cp312-musllinux_1_2_i686.whl
- Upload date:
- Size: 491.3 kB
- Tags: CPython 3.12, musllinux: musl 1.2+ i686
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8831e83969cd1ac7daa1ca44e788cb4925ff9e091ba2d56b847c0c75c7bf98ee |
|
MD5 | 2812b31c8d812bec73d3c044076680a2 |
|
BLAKE2b-256 | ffe61bf618951af755d1bed88bbf6e929d0307bfe336971c32a7fd01f37a9df7 |
File details
Details for the file cisraeliqueue-0.0.1a2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: cisraeliqueue-0.0.1a2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 506.4 kB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e6ea8efea87ae28a8281a689bbf78e353750208cb18840ef3512f825a3baf933 |
|
MD5 | 2d9966286ac9fe4493e463087dd2d918 |
|
BLAKE2b-256 | 2ae96b7ddc5cd264445363baf08426866803951abf8a8629caeda4d5ad35bbbf |
File details
Details for the file cisraeliqueue-0.0.1a2-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
.
File metadata
- Download URL: cisraeliqueue-0.0.1a2-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
- Upload date:
- Size: 478.2 kB
- Tags: CPython 3.12, manylinux: glibc 2.17+ i686, manylinux: glibc 2.5+ i686
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30bdc2e4faa1b697d6c699fc7a87d971fa80f60a95cd6c12d60a3b19221d922b |
|
MD5 | 0b535f2907edb263d6cb888e9923d57a |
|
BLAKE2b-256 | c99af8c66a9d1ddd739ddcacc109c7393ec8656642e4f249a79433824e32fe79 |
File details
Details for the file cisraeliqueue-0.0.1a2-cp312-cp312-macosx_11_0_arm64.whl
.
File metadata
- Download URL: cisraeliqueue-0.0.1a2-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 90.5 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9cb3ceb43e54504b521f87a58ee39cd8e15cb10ef1d9f1c84391f71aa25f3963 |
|
MD5 | e9117c70f207dea50ee3b5fb54fede52 |
|
BLAKE2b-256 | dba73e1dc4a9d66e430b61a294f29e52cc4f7b03b423f143223bcf1bb963848d |
File details
Details for the file cisraeliqueue-0.0.1a2-cp312-cp312-macosx_10_13_x86_64.whl
.
File metadata
- Download URL: cisraeliqueue-0.0.1a2-cp312-cp312-macosx_10_13_x86_64.whl
- Upload date:
- Size: 95.0 kB
- Tags: CPython 3.12, macOS 10.13+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d0f8260d88f3abf3fb447f74038d208990541566e038c60998afb7cae628051 |
|
MD5 | 23899064af4a5d459aa890252523fe82 |
|
BLAKE2b-256 | df82988f7164db9e44cc6a3d0530042a8a22b36b2659bcde3c383f9bec92e198 |