Skip to main content

A fast implementation of an Israeli Queue

Project description

Israeli Queue

A fast Python (Cython) implementation of an Israeli Queue.

GitHub Actions Workflow Status Read the Docs PyPI PyPI - Python Version

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

Uploaded CPython 3.13 Windows x86-64

cisraeliqueue-0.0.1a1-cp313-cp313-win32.whl (70.3 kB view details)

Uploaded CPython 3.13 Windows x86

cisraeliqueue-0.0.1a1-cp313-cp313-musllinux_1_2_x86_64.whl (510.2 kB view details)

Uploaded CPython 3.13 musllinux: musl 1.2+ x86-64

cisraeliqueue-0.0.1a1-cp313-cp313-musllinux_1_2_i686.whl (487.5 kB view details)

Uploaded CPython 3.13 musllinux: musl 1.2+ i686

cisraeliqueue-0.0.1a1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (501.3 kB view details)

Uploaded CPython 3.13 manylinux: glibc 2.17+ x86-64

cisraeliqueue-0.0.1a1-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (476.0 kB view details)

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

cisraeliqueue-0.0.1a1-cp313-cp313-macosx_11_0_arm64.whl (89.3 kB view details)

Uploaded CPython 3.13 macOS 11.0+ ARM64

cisraeliqueue-0.0.1a1-cp313-cp313-macosx_10_13_x86_64.whl (93.3 kB view details)

Uploaded CPython 3.13 macOS 10.13+ x86-64

cisraeliqueue-0.0.1a1-cp312-cp312-win_amd64.whl (80.0 kB view details)

Uploaded CPython 3.12 Windows x86-64

cisraeliqueue-0.0.1a1-cp312-cp312-win32.whl (70.4 kB view details)

Uploaded CPython 3.12 Windows x86

cisraeliqueue-0.0.1a1-cp312-cp312-musllinux_1_2_x86_64.whl (505.7 kB view details)

Uploaded CPython 3.12 musllinux: musl 1.2+ x86-64

cisraeliqueue-0.0.1a1-cp312-cp312-musllinux_1_2_i686.whl (491.3 kB view details)

Uploaded CPython 3.12 musllinux: musl 1.2+ i686

cisraeliqueue-0.0.1a1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (503.2 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

cisraeliqueue-0.0.1a1-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (476.1 kB view details)

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

cisraeliqueue-0.0.1a1-cp312-cp312-macosx_11_0_arm64.whl (90.0 kB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

cisraeliqueue-0.0.1a1-cp312-cp312-macosx_10_13_x86_64.whl (94.5 kB view details)

Uploaded CPython 3.12 macOS 10.13+ x86-64

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 bf01789eaed1f90705d4ce8583b52f5cece826b729f7437e51abf61963275ddf
MD5 d3796e850bec79c1e0f8284ab1800ca5
BLAKE2b-256 c6327a2b7247658745a7ff33ba32e1baab2b38535d2579397a45ee91a67f2a7b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a1-cp313-cp313-win32.whl
Algorithm Hash digest
SHA256 f4576feaf484e91a1890e7643052d9619d083052a8c20e1f70b3376c2380761e
MD5 4c303eeb2cbb5b84dcdba9f8092716f4
BLAKE2b-256 2b26d9d0863cdc2bbca63f352f04cb7bd1bcc9840b25aa9c2902262213cc4956

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a1-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 44695c5ebd50a5d9b659cbca8b4f1e3d767287fa778e6b9c240d908fbe70fcae
MD5 a34eb39096e566ee6440e5bd5597f2ab
BLAKE2b-256 a5cc2b34448d3e3f789aca3ce7e4796c995dfcaf12d6878e18217ac8838fcb15

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a1-cp313-cp313-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 1cea0058f874af02791a925e03546458a2991e6da6015a33b3a8b47ed89dee66
MD5 0b904bb3b630919f56ba2a77f12a8ff0
BLAKE2b-256 fe080ade963ca4b12bcb71ade0459a4ecf5473f66be6c0894f9b8275b69cb0af

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fbb925c5977555d3574037aca4b4fefa1ef5d9054307863df1a82df8b54a214e
MD5 8f528139b61c31e2fcbeba6a0a1a3bbc
BLAKE2b-256 2d291deeecb35df438321586fe8c18ecb83f21de47465763db2721243402b24c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a1-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 15649e5bba2978bdbfe92856ef521b5accf7085ef69a81779a01249f9ccaf34c
MD5 10a3a65d0ea9e220c54b7b8d101e2650
BLAKE2b-256 72c79cf3adf05f22a7f88f83415c354c55d5ec87d321c49ee078985a2405b3c0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9278c37f59ba7e7b323b579be2e3c37794b407fc11c80af0a9b10ad716263c05
MD5 de837230e2a5dc2fdaccf02f4d18c23f
BLAKE2b-256 f1851b45f2472f284f06a3bc7480ae79c27b9e6096745daa2d5dca75ca48b8bd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a1-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 7392cc9e2b26df8f80845d26167d41f1a6fdd6847eaae4d1e43b9af52c12bb39
MD5 257c3e2139135758dd3bd47b4488bf3f
BLAKE2b-256 eeac8de6982c71fbbbbcf7a18b8f687cdb20fa058cf2899008f82b7bc89393f7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 9bd3368da46badcff73272fa4e8357048537068dd544d2a56926734dac0e3cb1
MD5 7ad6dd2b6bba22d98e8dbf9151deb3e0
BLAKE2b-256 ad0ab8155eac103275bdb7c555f8c43cef3bd2d5b85c3a8c85a24b96d1a7f971

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a1-cp312-cp312-win32.whl
Algorithm Hash digest
SHA256 87fe7260b0bcceed3d0c7f105ca1a22dd51fcf656e8c58267394ccaa666e786c
MD5 baa05fb57be66b1bbc7890eea276f256
BLAKE2b-256 36d09f823567b4f5e0ca6c860f9718bfa5d618128b3d6bf9bc3985d005af637d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a1-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 937da4e033cd7d429acbeec9d8468b72844c10cf88d68986aacd50e86a215f38
MD5 6065e0661249c27042534717211988b0
BLAKE2b-256 5744429474c6002812c0cf02c923fbaaf9850fb30548fb76ffedb250e1f5b0d4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a1-cp312-cp312-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 e7106a0969c788714124fc83e69a090fc1e0597878f5ee84483f7dc7c6c5d82b
MD5 22852b19a22bea415ac10e0b661cc7ec
BLAKE2b-256 e34b749acac051045b9e0c114eba5120a1727e6167e9f902fcdb53994d64bb37

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3e4c8e1a5967317aa81b55e68a7a4c15a5ca890c409a533cbf2945ebc737f4fe
MD5 0e60d0c3b9a5b8c1e5c299a2cce2fe2e
BLAKE2b-256 83da9013078d43e4e6a8071cc331b1b397b5eadbd9d08326846f50a339f1ecee

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a1-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 fa22f93ea4361390c0604ea6ee0f5246e7d3496fa774bb533ae288d9c38ebb79
MD5 c1b8c5f30fff092adbcc1275e7952b12
BLAKE2b-256 ea7882b614399a5ead5b3d050b04b3b1b3c95a20b0e5ceaa8fda66d2ca49f458

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 519c837a7525f31699617b10af9762b86f6f319a55468949b7609741a7082e5d
MD5 b7fd9b40bacd8853b6dc4aef96d6e438
BLAKE2b-256 abf4f47852be4b081396fdfaae30e4014eb3e76540d23f4f627c36717c800ed7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cisraeliqueue-0.0.1a1-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 5ebf1bec6c62e425ea5b8fab80bdc01890b70f561381a500db5b31c2e3e24911
MD5 3a78ac69a78eb6b75ad5fd16714ac462
BLAKE2b-256 9bf420221c02db27d4833feb31d3973da5f0b84d21011195b799c6c40473ca29

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