Metadata-Version: 2.1
Name: generic-pool
Version: 0.1.2
Summary: A generic object pool implementation
Home-page: https://github.com/gfmio/generic-pool
License: MIT
Keywords: pool,generic
Author: Frédérique Mittelstaedt
Author-email: pypi@gfm.io
Requires-Python: >=3.8
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Project-URL: Documentation, https://github.com/gfmio/generic-pool
Project-URL: Repository, https://github.com/gfmio/generic-pool
Description-Content-Type: text/markdown

# generic-pool

generic-pool is a generic object pool for python inspired by the node.js library.

You can use it to build your own resource pools, e.g. to manage file handles, connections or similar.

## Install

Install `generic-pool` from pypi using your favourite package manager.

```sh
# If you use poetry
poetry add generic-pool

# If you use pip
pip install generic-pool
```

## Usage

```py3
from random

from generic_pool import Factory
from generic_pool import Pool

class IntValue:
    def __init__(self):
        self.value = random.rand
    pass

class FortyTwoFactory(Factory):
    def create(self) -> IntValue:
        return IntValue()

    def validate(self, item: IntValue) -> bool:
        return item.value == 42

    def destroy(self):
        # free resources, not applicable here
        pass

factory = FortyTwoFactory()
pool = Pool(factory)

item = pool.acquire()
try:
    assert item.value == 42
finally:
    pool.release(item)

with pool.acquire(item):
    assert item.value == 42
```

## License

[MIT](LICENSE)

