Skip to main content

Handy Python Queue utilies

Project description

Python package codecov

Queutils

Queutils [Queue Utils] is a package of handy Python queue classes:

  • AsyncQueue - An async wrapper for non-async queue.Queue
  • IterableQueue - An AsyncIterable queue that terminates when finished
  • EventCounterQueue - An IterableQueue for counting events in async threads
  • FileQueue - Builds an IterableQueue[pathlib.Path] of filenames from files/dirs given as input

AsyncQueue

AsyncQueue is a async wrapper for non-async queue.Queue. It can be used to create an asyncio.Queue compatible interface to a (non-async) managed multiprocessing.Queue and thus enable async code in parent/child processes to communicate over multiprocessing.Queue as it were an asyncio.Queue. Uses sleep() for get()/put() if the queue is empty/full.

Features

  • asyncio.Queue compatible
  • queue.Queue support
  • multiprocessing.Queue support

IterableQueue

IterableQueue is an asyncio.Queue subclass that is AsyncIterable[T] i.e. it can be iterated in async for loop. IterableQueue terminates automatically when the queue has been filled and emptied.

The IterableQueue requires "producers" (functions adding items to the queue) to register themselves with add_producer() call. It keeps count of registered producers. When a producer "finishes" adding items to the queue, it needs to unregister itself with finish_producer() call. Once all the registered producers are "finished", the queue enters into "filled" state and no new items can be added. Once a "filled" queue has been emptied, the queue becomes "done" and all new get() calls to the queue will raise QueueDone exception.

Features

  • asyncio.Queue interface, _nowait() methods are experimental
  • AsyncIterable support: async for item in queue:
  • Automatic termination of the consumers with QueueDone exception when the queue has been emptied
  • Producers must be registered with add_producer() and they must notify the queue with finish_producer() once they have finished adding items
  • Countable interface to count number of items task_done() through count property

EventCounterQueue

EventCounterQueue can be used to count named events (default event is count) between async threads. async worker threads call queue.send(event="event_name", N=amount). The receving end can either receive() a single event or listen() all events and return collections.defaultdict[str, int] as a result.

Features

  • Supports multiple producers and a single listener
  • Default event is count

FileQueue

FileQueue builds a queue (IterableQueue[pathlib.Path]) of the matching files found based on search parameters given. It can search both list of files or directories or mixed. Async method FileQueue.mk_queue() searches subdirectories of given directories.

Features

  • Input can be given both as str and pathlib.Path
  • exclude: bool exclusive or inclusive filtering. Default is False.
  • case_sensitive: bool case sensitive filtering (use of fnmatch or fnmatchcase). Default is True.
  • follow_symlinks: bool whether to follow symlinks. Default is False.

Project details


Download files

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

Source Distribution

queutils-0.11.0.tar.gz (21.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

queutils-0.11.0-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file queutils-0.11.0.tar.gz.

File metadata

  • Download URL: queutils-0.11.0.tar.gz
  • Upload date:
  • Size: 21.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for queutils-0.11.0.tar.gz
Algorithm Hash digest
SHA256 20cae7635be867cff83ec4617b6a36d82f1e717d89635e9168f7e04aa70d412a
MD5 a8f2ba0b97756e1d7ec3d82f066795d7
BLAKE2b-256 bb589867d2024a73a9139b413e2629032197874657016c640bf207ccf2d3a0a1

See more details on using hashes here.

Provenance

The following attestation bundles were made for queutils-0.11.0.tar.gz:

Publisher: python-publish.yml on Jylpah/queutils

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file queutils-0.11.0-py3-none-any.whl.

File metadata

  • Download URL: queutils-0.11.0-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for queutils-0.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fa96fe7524b2f359a4eb72b95cd9335d79abb483d0fec4ecc84ce571f42de188
MD5 c8415523a7b246f339f9c2907b684922
BLAKE2b-256 edd4279cf99506cad628f8523d5f3a56764cdd94432cb14ad77de9c763efaea9

See more details on using hashes here.

Provenance

The following attestation bundles were made for queutils-0.11.0-py3-none-any.whl:

Publisher: python-publish.yml on Jylpah/queutils

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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