Skip to main content

A fast implementation of an Israeli Queue

Project description

Israeli Queue

Table of Contents

  1. Overview
  2. What is an Israeli Queue?
  3. Installation
  4. Classes
  5. Documentation
  6. Complexity
  7. Synchronous Example
  8. Asynchronous Example
  9. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

cisraeliqueue-0.0.1a0.post1-cp313-cp313-win_amd64.whl (79.3 kB view details)

Uploaded CPython 3.13 Windows x86-64

cisraeliqueue-0.0.1a0.post1-cp313-cp313-win32.whl (70.2 kB view details)

Uploaded CPython 3.13 Windows x86

cisraeliqueue-0.0.1a0.post1-cp313-cp313-musllinux_1_2_x86_64.whl (507.1 kB view details)

Uploaded CPython 3.13 musllinux: musl 1.2+ x86-64

cisraeliqueue-0.0.1a0.post1-cp313-cp313-musllinux_1_2_i686.whl (485.3 kB view details)

Uploaded CPython 3.13 musllinux: musl 1.2+ i686

cisraeliqueue-0.0.1a0.post1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (499.7 kB view details)

Uploaded CPython 3.13 manylinux: glibc 2.17+ x86-64

cisraeliqueue-0.0.1a0.post1-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (474.5 kB view details)

Uploaded CPython 3.13 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

cisraeliqueue-0.0.1a0.post1-cp313-cp313-macosx_11_0_arm64.whl (89.2 kB view details)

Uploaded CPython 3.13 macOS 11.0+ ARM64

cisraeliqueue-0.0.1a0.post1-cp313-cp313-macosx_10_13_x86_64.whl (93.0 kB view details)

Uploaded CPython 3.13 macOS 10.13+ x86-64

cisraeliqueue-0.0.1a0.post1-cp312-cp312-win_amd64.whl (79.7 kB view details)

Uploaded CPython 3.12 Windows x86-64

cisraeliqueue-0.0.1a0.post1-cp312-cp312-win32.whl (70.2 kB view details)

Uploaded CPython 3.12 Windows x86

cisraeliqueue-0.0.1a0.post1-cp312-cp312-musllinux_1_2_x86_64.whl (506.1 kB view details)

Uploaded CPython 3.12 musllinux: musl 1.2+ x86-64

cisraeliqueue-0.0.1a0.post1-cp312-cp312-musllinux_1_2_i686.whl (489.3 kB view details)

Uploaded CPython 3.12 musllinux: musl 1.2+ i686

cisraeliqueue-0.0.1a0.post1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (501.6 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

cisraeliqueue-0.0.1a0.post1-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (473.5 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

cisraeliqueue-0.0.1a0.post1-cp312-cp312-macosx_11_0_arm64.whl (89.8 kB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

cisraeliqueue-0.0.1a0.post1-cp312-cp312-macosx_10_13_x86_64.whl (94.4 kB view details)

Uploaded CPython 3.12 macOS 10.13+ x86-64

File details

Details for the file cisraeliqueue-0.0.1a0.post1-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0.post1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 1473fe53c53312e6ac0e3ddf6540f59d04fe408610b9e27d639d34d3dc1c9a61
MD5 864b4e28fc2d331626cd0ad7d01f36fe
BLAKE2b-256 2ea4e0e2bde442088faa2950163a9cf843ceebc0f5571eaa1b38240da117c13b

See more details on using hashes here.

File details

Details for the file cisraeliqueue-0.0.1a0.post1-cp313-cp313-win32.whl.

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0.post1-cp313-cp313-win32.whl
Algorithm Hash digest
SHA256 e4dd0160eb99103b1cd081aaf10a4b6d6ce11fbccd98996b8fe20390f532b89f
MD5 d2e581f0a80c2d51ca03aae7ba5e5435
BLAKE2b-256 7e1bec5764e11808b0f4297b0043a9f44bbc00ff054642ae6ab7331f0833684b

See more details on using hashes here.

File details

Details for the file cisraeliqueue-0.0.1a0.post1-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0.post1-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 15eaa6cf9eb7fb46860ed8f87805d7eae9fc5eb44f63391d358fdd50257af1b9
MD5 8f800c6d3511c7f27c077e168157e72e
BLAKE2b-256 a32e4c84e819a2b63c8963c35146a1920df96b351db8c077be21f0e204e53056

See more details on using hashes here.

File details

Details for the file cisraeliqueue-0.0.1a0.post1-cp313-cp313-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0.post1-cp313-cp313-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 7920fb8a853d76037b708cf0e8866023f718790e319734f7743bd75c8f927b9a
MD5 f7e292ba84df4c87834e040f9acfce6a
BLAKE2b-256 5af492f054737c6b53f64eb5070ee5f1194fb709ef200c71abc7f0ce025ec90a

See more details on using hashes here.

File details

Details for the file cisraeliqueue-0.0.1a0.post1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0.post1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7653feb0c20b036fbdf4ed51beb3902eed8439c7343189e2bfff06b4951d99bc
MD5 3accc95c7ae522c33d940b68ad6fd762
BLAKE2b-256 7a704a0f4551757fcaff092fc77ebd6a2af5b06845680ec6898e04aec777a45e

See more details on using hashes here.

File details

Details for the file cisraeliqueue-0.0.1a0.post1-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0.post1-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 f4b5ef12ecb2731fbe2bde2a99055d0056a4313a2316cc52a63339782534ba8d
MD5 bf18a11976c528179a2c428807e4d385
BLAKE2b-256 f204ead5fee49fdec497ed225014bd79f1e6b29b03aa6e733384f2f67e04627e

See more details on using hashes here.

File details

Details for the file cisraeliqueue-0.0.1a0.post1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0.post1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b7989438f7aa3bfc96c41b4602bfb335e4a47c7a3a4c76861e584a49168de4ed
MD5 e21274f84a9dccaec89ce66533fe4559
BLAKE2b-256 8556cf4a077ddf7cdc4ba8b442974eb0287f0aa101e6b3a1fcb8e3e5e0e66d74

See more details on using hashes here.

File details

Details for the file cisraeliqueue-0.0.1a0.post1-cp313-cp313-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0.post1-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 2c94b05040cdca30e38e633ba4705ccb29eefcee0eeff3731997aa870d40928d
MD5 50b21424e4384755bef4068b5a1ce466
BLAKE2b-256 fb04f45fe1d455e983f456c78d324dc9f83299bd02f95f55d6734269af08c13b

See more details on using hashes here.

File details

Details for the file cisraeliqueue-0.0.1a0.post1-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0.post1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 d3d4ee8b50be8a2b16b42b61c5a9dbd776c1cd4fe9b37468e7fe3c6e5be41a63
MD5 ebcd1b884d4cea00b7b52e823ada664d
BLAKE2b-256 62796ce6dc156ed622155a4a58a6a20b6e875c90d43eef0e7bba5d53f078b760

See more details on using hashes here.

File details

Details for the file cisraeliqueue-0.0.1a0.post1-cp312-cp312-win32.whl.

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0.post1-cp312-cp312-win32.whl
Algorithm Hash digest
SHA256 787b3219e78821da226648e7ef8309b86fe1e1be4d36ef5bd9ee2c1b8e768f3e
MD5 20fab874f6c483f637970e03d41f0196
BLAKE2b-256 bbbc4d6f7db2f8726c4a1a9377d0e4788e48d1e7332edb1d20f66a1524aaa322

See more details on using hashes here.

File details

Details for the file cisraeliqueue-0.0.1a0.post1-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0.post1-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 21279731f3a556d3d229b9c2024f3200b5f02246708b5ebb4ec2ce4c3949082d
MD5 0b101a0a7fd42b38cdc904a7eaf2c644
BLAKE2b-256 ae227d4eb9394c4a55486b8c44bef5f188928e580e032b9c1fbd369766749812

See more details on using hashes here.

File details

Details for the file cisraeliqueue-0.0.1a0.post1-cp312-cp312-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0.post1-cp312-cp312-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 83081805a2ed168cfeecac752df5b6d32224301e52e2481ad805422cd5433731
MD5 b4a461fbf453e23fc89653079fb5447a
BLAKE2b-256 86f6b50f826aea5ba7336886a50eafa881324889034fc8dcfafb05c924d5a243

See more details on using hashes here.

File details

Details for the file cisraeliqueue-0.0.1a0.post1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0.post1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 501baf762374f698ecf75fc7ddbfd788196989591efb5e584f2c00f3ed4f96cb
MD5 4fe74eb71dafeb6f3fd36898b771db03
BLAKE2b-256 c0d0cb1bf5dc78705116c067c84c1954947f36a7b56318611c06609c34da4d89

See more details on using hashes here.

File details

Details for the file cisraeliqueue-0.0.1a0.post1-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0.post1-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 3f0fbd47404d32711fdb592476627ed891127502a6b1a5bacef5cd731fcfde53
MD5 c1fedc220e9002600c0b1626e0d0ee1d
BLAKE2b-256 b00f98d9b8ea9cb8bbe9ee2f0c13e6771bbf21873e331100a88bac2308236ab1

See more details on using hashes here.

File details

Details for the file cisraeliqueue-0.0.1a0.post1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0.post1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 67ea3de4be463a0edf73d6076bcf350fc00ad60a6fd69059023e9cd3efa38f87
MD5 affe5607460c43e8e6ad629dd742e932
BLAKE2b-256 6a9a274cefe03acd19f64407dced3bfe6e839d3862c1270a6010262f9861d945

See more details on using hashes here.

File details

Details for the file cisraeliqueue-0.0.1a0.post1-cp312-cp312-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0.post1-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 4259d2fa5c40e73820ca9310832947f7eb242547f3acccb2227260699de4cf41
MD5 e89d5c861de7806e17d2ad5ac4729645
BLAKE2b-256 159f03d23f6885e280eca7957dea93157eb0060f8ab62d5937fdfa0406f98a24

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page