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.2.tar.gz (16.8 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.2-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: streamingpool-1.1.2.tar.gz
  • Upload date:
  • Size: 16.8 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.2.tar.gz
Algorithm Hash digest
SHA256 6d853f0fded56359007f62d25ee1adc75d69ccf8e4206f5f578afdb42dc61b9b
MD5 eafcfaa455ff87d89bdf0f3e5f10eafa
BLAKE2b-256 a3660d4ed40f9b84aea203bebda7fde964d1b64fe135412dd4625584238c4345

See more details on using hashes here.

File details

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

File metadata

  • Download URL: streamingpool-1.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 943d5f231c7fc854b8eec7c1ab1f77ae4af97a71fc878ba6d905be5a99cdb4dd
MD5 ed2c3992fd2b1a27ac65dd2733f2ed96
BLAKE2b-256 43b4c3adfd6fd355ec4df8ef60280f790974dce33c95de4717b5f1c381a33b34

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