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.post0-cp313-cp313-win_amd64.whl (79.3 kB view details)

Uploaded CPython 3.13 Windows x86-64

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

Uploaded CPython 3.13 Windows x86

cisraeliqueue-0.0.1a0.post0-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.post0-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.post0-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.post0-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.post0-cp313-cp313-macosx_11_0_arm64.whl (89.2 kB view details)

Uploaded CPython 3.13 macOS 11.0+ ARM64

cisraeliqueue-0.0.1a0.post0-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.post0-cp312-cp312-win_amd64.whl (79.7 kB view details)

Uploaded CPython 3.12 Windows x86-64

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

Uploaded CPython 3.12 Windows x86

cisraeliqueue-0.0.1a0.post0-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.post0-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.post0-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.post0-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.post0-cp312-cp312-macosx_11_0_arm64.whl (89.8 kB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

cisraeliqueue-0.0.1a0.post0-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.post0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0.post0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 a960764d139861340ac580fb583345c0593f0a78f9bb3b75cfc1c9aa08a15b93
MD5 cd45101bb1c1455ef18ff711ce4dd014
BLAKE2b-256 2a427873f9a4372f3a7a1c4812fd0577c377099b3f10842b8f27cd2f18dc0819

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0.post0-cp313-cp313-win32.whl
Algorithm Hash digest
SHA256 353eb4b30367aaf57a8b5b4f8ff21c3aad66f0586fe2b1755dce822b3e2c1c3f
MD5 12c1dbb5e5e174969f3ea1ad9cebef0d
BLAKE2b-256 78eed643330ddc7970d5d406e3b2ca0f67d283c5d3adedf34e62846d683bec7b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0.post0-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c486ecf2200ae778bb8b251645ac775cc03ae96ffc717034abdc8f615027ff8e
MD5 69a11e0454115917c3b320dba92670b6
BLAKE2b-256 91893d6e0944d6f20624afdb0dd1f6a9385fc84ae4d62b6c8d39b3b1f78e397b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0.post0-cp313-cp313-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 43aa616048448022e79c59bdd9df7cd4065a3299d54177be50b2b9ab46aa0e87
MD5 507025923e1c9272abcbffafb8719cb1
BLAKE2b-256 7943e1a1d85597eceab99c9f21f65f9909ccd12909ef420925a49b930b60dc01

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0.post0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 148f08982207846a6105187d4a40da6a7181e11edeb486dde3f0fab2244b3c37
MD5 cdc8ebe10c9534ffdda93cf5446bf135
BLAKE2b-256 831e3e3490145f7b87536500d0fe90e402e8916abe8cf0344e32e913de40bbcf

See more details on using hashes here.

File details

Details for the file cisraeliqueue-0.0.1a0.post0-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.post0-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 0cd29aab9cb74215cfb4c0b192379831c2802e22b7e50efcd6755f4024de8560
MD5 aae657f0f4c2275ee7e30527e5922efd
BLAKE2b-256 bdecaf792da29846faaa51c8099508279bf125f811a622e5c231bd596b8c9a03

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0.post0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 76c190efbb28d41ea06931debc81e1eea3586848371fdb3233e0faaa6ea50036
MD5 1677c3ccf237b97d397c0b44c88463c6
BLAKE2b-256 445e7d6c111a6b33c04b4f32134aa92bf9f2d50efdf45c6cc8bb5b64eb229561

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0.post0-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 3f8c51988e0a9c237562d1947a5f302a6e0000c09b7202308316dfc53c28c7cf
MD5 a44f4609b967da908b50360ef61275d7
BLAKE2b-256 e25ec7412c535d57a9731815924d1b148acf55eebdc06ed52561098f5feff375

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0.post0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 601179e51910b7ea14bd8a62fdd36b21d2ff4a2b224b9e68af152c2f80af2de6
MD5 068570ffc56ddddc84f604b7659a9268
BLAKE2b-256 4ca450b14435d3c63285fe88ee07d278a03b45988efeb0b447a67a57fc5a86ae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0.post0-cp312-cp312-win32.whl
Algorithm Hash digest
SHA256 9504dd7bd90a3100b40ccb8fe37d08013e34386f00455f76fc671d799e385fa3
MD5 06df77081979f68485f5a24b524bd55e
BLAKE2b-256 815570d6b7042a9dc78c78ce9754d957e600e7cddd0c00f96426ae6ad80499cd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0.post0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 ef33673eb795253090115f98aeb981a2b674ebe6f22596401051af304713b715
MD5 6f6d899f8517c412a9acbad42ff5a69c
BLAKE2b-256 dbcb43763722039da3b1ad3398814323662a6c3b44f099f908685f12aa4acba3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0.post0-cp312-cp312-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 d651c30880312afebe6278d7c9b1569d4c4382aafea1e6448b8e56d67fb40797
MD5 0db1585e1fc8d823d379d5d2ed834c52
BLAKE2b-256 99a538ed0f581a08934bb0441fe908f85710c834c9f5e1f8da2337fa756d3d6f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0.post0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d32058dc7c372cfee476fd2b9b230e8a51363e4112791c3ac9fc6647d32462d1
MD5 e4f72e3fc306266ca3aa94bcb6b8e24d
BLAKE2b-256 80184e235a78e91cd2c38d5961c86478c9edb2e2e3637afef6b11d3b518f1408

See more details on using hashes here.

File details

Details for the file cisraeliqueue-0.0.1a0.post0-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.post0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 3bc2ba84efb114d3c96afa9195814af3cd65208c680c7b00f21fb00dfb504865
MD5 06d5f5e20134fa22366e89164521adb7
BLAKE2b-256 bc746fb711812a1f9c25de723208bbd84216b2adbfa5041b5d38e88c945af2ef

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0.post0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 458dd4ce3ca89b45cf06413f6f4632ca2eccffea78371a149de761cf083ed161
MD5 29489533558a23f82ff9a2a0d42cca86
BLAKE2b-256 3918a9a2e3d160bb5e1973bfd2e8e339c79c4e07227512b8754a37d286c1d78d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0.post0-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 4bdd246aae8664ccd360e8542cb87d8e92d107916c10db584599961a5d7c58bd
MD5 38f0a589df1939688d21412b5d384a0a
BLAKE2b-256 283516af35535bee8566668efd516157a7d00cf0d9402772437bbe313a1d4c58

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