Skip to main content

No project description provided

Project description

StreamingPool 🌊

StreamingPool is a Python library that allow user to implement custom pipelines to treat datas asynchronously.
You can add and treat datas at the same time based on Python's concurrent.futures.ThreadPoolExecutor class.

Available pools 🐋

  • FIFOPool : A First In First Out pool.
  • LIFOPool : A Last In First Out pool.
  • BasePool : A base class to let you implement your own logic of pooling from scratch.

How to use 💯

Create your pool 🐟

First you'll need to implement your own pool to describe the logic that you want :

from streamingpool import FIFOPool

class SamplePool(FIFOPool[int]):
    """
    This is a sample pool that print int values
    """
    def __init__(self):
        super().__init__()

    def process_segment(self, segment: int) -> None:
        print(segment)

NB : You can specify any type of data that you need, here for the exemple I have choosed int

And the you can start your pool !

Pool usage 🐳

To use a pool you have two choices :

Disposable usage ✔️

with SamplePool() as pool:
    for i in range(10):
        pool.enqueue_segment(i)

    pool.pause() # Pause the pool
    # ...
    pool.start() # In this case resume the pool

Inline usage ✔️

pool = SamplePool()
pool.start()
for i in range(10):
    pool.enqueue_segment(i)

pool.pause() # Pause the pool
# ...
pool.start() # In this case resume the pool
pool.stop() # Stop the pool when all it's data have been treated (block the thread)

Creating your own pool 🐬

As it have been said before, you can also implement your own pooling logic.

from streamingpool import BasePool, Discard

class ListPool(BasePool[int]):
    __buffer: list

    def __init__(self):
        super().__init__()

    def __init__(self):
        super().__init__()
        self.__buffer = list()

    def enqueue_segment(self, datas: int) -> None:
        self.__buffer.append(datas)

    def retrieve_segment(self) -> int | Discard:
        try:
            return self.__buffer.pop()
        except IndexError:
            return Discard()

    def is_empty(self) -> bool:
        return len(self.__buffer) == 0

    def clear_buffer(self) -> None:
        self.__buffer = list()

    def process_segment(self, segment: int) -> None:
        print(segment)

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

streamingpool-1.1.1.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

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

streamingpool-1.1.1-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file streamingpool-1.1.1.tar.gz.

File metadata

  • Download URL: streamingpool-1.1.1.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.11

File hashes

Hashes for streamingpool-1.1.1.tar.gz
Algorithm Hash digest
SHA256 c852e5bf4d83ffb92f4b891a50a3ffc5a8f99dfbf3b40aeaad935b559af2d0ff
MD5 39967dbe2e0770c0ab419fc9142c4dd6
BLAKE2b-256 e18fcea0c33c7c1dc8c39b77ec8c14a0f9f088a67bf9ae77ba585dc4b1ee771a

See more details on using hashes here.

File details

Details for the file streamingpool-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: streamingpool-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 18.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.11

File hashes

Hashes for streamingpool-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e4aa4e3de179ce21f04beeb379d9aff605251d59433a04da3ba8ef1e19e7c70b
MD5 dd37e3f39d22fd376a3fc72c4165e543
BLAKE2b-256 0613dc56fe593a4dc02f247a7c29ed099ea92f6607aa7a1b5106c833b6091785

See more details on using hashes here.

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