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

Uploaded CPython 3.13 Windows x86-64

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

Uploaded CPython 3.13 Windows x86

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

Uploaded CPython 3.13 musllinux: musl 1.2+ x86-64

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

Uploaded CPython 3.13 musllinux: musl 1.2+ i686

cisraeliqueue-0.0.1a0-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-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (474.4 kB view details)

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

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

Uploaded CPython 3.13 macOS 11.0+ ARM64

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

Uploaded CPython 3.12 Windows x86-64

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

Uploaded CPython 3.12 Windows x86

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

Uploaded CPython 3.12 musllinux: musl 1.2+ x86-64

cisraeliqueue-0.0.1a0-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-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (501.5 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

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

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

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

Uploaded CPython 3.12 macOS 11.0+ ARM64

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

Uploaded CPython 3.12 macOS 10.13+ x86-64

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 c7d5dc3d271230ad315e341ce241afb23b93a8f38c879097c834ef015e5f8b1b
MD5 d5a5fdfc75b9c30473884b4f830e2d76
BLAKE2b-256 13464963aca5be23d9e0fde441d168a0a3fa0dc87b35aacf3930d72a95ebd5e0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0-cp313-cp313-win32.whl
Algorithm Hash digest
SHA256 2c80d748b2bf0ef3c7d2b7da48f17749caa3d9af2ffe72c2959a88a853bfca6a
MD5 3f47cdde2f1df04c8ea60c486c1bd1ea
BLAKE2b-256 1d2db55d447ba3cb92139c5c7a206e88b27723196614df71a7497e90a1a88ec8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 05341a7762a96c68ab16899cdab71788914605fa08eecee953075d94cff41d27
MD5 559282942453df5c2d9e1ad715a8513d
BLAKE2b-256 a7f22dfe3ce2905fbd101f3a7c453c02d3cc96c20978a5ca20ce798aa255aaf0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0-cp313-cp313-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 283087d5b990c1ecec0f91c2c62376b1c0fb41f1c35d0166ad3d4a494fcdcfb5
MD5 075b937c091c67170f6f22954fb8fcac
BLAKE2b-256 38d99e94f0f362295ba646a8938c8ad437ab3c17d5758ea16e21508d0142afbd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a79e90a6c8c5356b98b7a88833c87f8b6b1c7b32da9e83e42750fbcbc9b163b0
MD5 0f14a9ad1e82f0f169e7a7a92668c9cb
BLAKE2b-256 f3e3189e637ba740fd505b5cba84ed0e97f5757057afd2c472cf5dbc2af82d41

See more details on using hashes here.

File details

Details for the file cisraeliqueue-0.0.1a0-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-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 9f4f4101d6242337b1cbb575017296180ed386ac0ada8dd9d74841dbf86bf906
MD5 d02f66a2ec23190cc264dcb241cd2e8b
BLAKE2b-256 629487e7e5a8af25c3cbdac1cb2c3ab9a588950a3a8259733d2698a11a5dc37f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 68fb63dea31bd311a8018d9f6a6d37d95501d89a11e927b1d7983d31d68d6a28
MD5 23242a450423cd85efc92219a034bb5e
BLAKE2b-256 f7a8ed972f96416c265016bbb79cda0554e3397d5d47c10e28829b4282039a62

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 d5f9404bdaec173630132b1b74b7589abec76860cf42fbc898e521dc4c00f6bf
MD5 a3db864d304dd3444d44aaea9e53254a
BLAKE2b-256 e9a32303c4e711bed48e3736b7e602592939e28afd2c31619962b265b5f9fa13

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 605a711f5e848f2044060777468ec29632c9c44d552b2c8cff5286a459160ebc
MD5 ba742408095839bd52ab6e8135581234
BLAKE2b-256 15be72f4a6ed2e11e71523d7f02687d2242333fb0848eacc3a74541db23b1958

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0-cp312-cp312-win32.whl
Algorithm Hash digest
SHA256 8673ce53a30036609e217396cec4268853b072c43db48e7fdb1a92449db754de
MD5 c0fdf8c1f1e61257455ccd092d603de4
BLAKE2b-256 42a9a462e03a1af63e00639396eb6fd5923bff1e71a17f05002308912e68c173

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d52ee7f3643f210a70f1688c2835f512faa5fd05999b391bd0845ed92dc27368
MD5 b25e510ebffe78444698f30f966ba960
BLAKE2b-256 674fd37756fbf9dcf8d7cb07d48a15d1b3c422b9a82f24e168dfecb7bfdd5453

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0-cp312-cp312-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 924111f881af183c018c5d595ade71b2790d2e344a498b2704d255d16e9521bf
MD5 adec3ef5ef981d3fa95117920a33b7d3
BLAKE2b-256 b96730e4e920f85c9776cbb3dfb1a87df8de148a730e8858f8a5b0e75fadd82a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 560443ca815a13d8bcce39b1bed85a1b2e67c6c9933d964337e1e89b962c9347
MD5 46c371394e27fe1af5ad168cbbd613de
BLAKE2b-256 84a8393d4d5e919f261691a645f397a0e683aeaa7c2a728d7b984f51e042f867

See more details on using hashes here.

File details

Details for the file cisraeliqueue-0.0.1a0-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-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 48de0adf606a67ec193d382964228a07e94f0f970a3d1c8fe62bb2cc8b247b2e
MD5 44092e84c7f568a29311c5ee89c5d3da
BLAKE2b-256 ed063488da8b61ba08d249c204a40ffd00748e8e78abece66cb35c227162098d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c5572655917b3139eb283752b9cf937b9311321a242b4e9e92733e3cc21dbc9b
MD5 db8ff4c7a648267bdc6f7cafb580b4fc
BLAKE2b-256 bf98e4a6e08f74dee62b13133e0db5e5c727361205564da8940d6fee112af14d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a0-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 9917fe3e641770c41c8715253de5c93ee4c5235618768661bbd8f13b0ea8e7a1
MD5 89404d5675f683094978832556b8a5c0
BLAKE2b-256 d736ec54a1d72c1d0788e9bf6198becc98ecd612ea3b8d279a45d34f4d7100d6

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