{"library":"pondpond","title":"Pond","description":"Pond is a high-performance object-pooling library for Python, designed to reduce memory usage and improve object borrow hit rates. It provides thread-safe and coroutine-safe mechanisms for managing a pool of objects, automatically recycling infrequently used instances. Currently at version 1.4.1, Pond maintains an active development and release cadence, with its latest update in February 2024.","language":"python","status":"active","last_verified":"Sat May 16","install":{"commands":["pip install pondpond"],"cli":null},"imports":["from pond import Pond","from pond import PooledObjectFactory"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import time\nimport threading\nfrom pond import Pond, PooledObjectFactory\n\n# Define a factory for the objects to be pooled\nclass MyObject:\n    def __init__(self, name):\n        self.name = name\n        self.created_at = time.time()\n        self.is_active = True\n\n    def do_work(self):\n        return f\"Object {self.name} working. Active: {self.is_active}\"\n\n    def cleanup(self):\n        self.is_active = False\n        return f\"Object {self.name} cleaned up.\"\n\nclass MyObjectFactory(PooledObjectFactory):\n    def __init__(self, name_prefix):\n        self.name_prefix = name_prefix\n        self._counter = 0\n        self._lock = threading.Lock()\n\n    def create(self):\n        with self._lock:\n            self._counter += 1\n            obj = MyObject(f\"{self.name_prefix}-{self._counter}\")\n            print(f\"Created: {obj.name}\")\n            return obj\n\n    def destroy(self, obj):\n        print(f\"Destroyed: {obj.cleanup()}\")\n\n    def validate(self, obj):\n        # Example validation: object must be active\n        return obj.is_active\n\n    def activate(self, obj):\n        # Reset object state if necessary before borrowing\n        obj.is_active = True\n        print(f\"Activated: {obj.name}\")\n        return obj\n\n    def passivate(self, obj):\n        # Prepare object for recycling (e.g., clear transient data)\n        obj.is_active = False\n        print(f\"Passivated: {obj.name}\")\n\n# Instantiate the Pond with our factory\n# max_size: maximum number of objects to keep in the pool\n# time_between_eviction_runs: interval in seconds for cleaning up idle objects\nfactory = MyObjectFactory(\"worker\")\npool = Pond(factory, max_size=5, time_between_eviction_runs=5)\n\n# Borrow objects\nobj1 = pool.borrow()\nprint(obj1.do_work())\nobj2 = pool.borrow()\nprint(obj2.do_work())\n\n# Recycle objects\npool.recycle(obj1)\npool.recycle(obj2)\n\n# Borrow again (should get recycled objects first)\nobj3 = pool.borrow()\nprint(obj3.do_work())\n\n# Simulate some time for eviction to run (if time_between_eviction_runs > -1)\nprint(\"Waiting for potential eviction...\")\ntime.sleep(7)\n\n# Close the pool to destroy all remaining objects\npool.close()\nprint(\"Pool closed.\")\n","lang":"python","description":"This quickstart demonstrates how to set up an object pool using `pond`. It involves defining a `PooledObjectFactory` to manage the lifecycle (creation, destruction, validation, activation, passivation) of your custom objects. An instance of `Pond` is then created with this factory, allowing objects to be borrowed from and recycled back into the pool.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-16","installed_version":"1.4.1","pypi_latest":"1.4.1","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":1.7,"avg_import_s":0.21,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"pondpond","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.09,"mem_mb":4.2,"disk_size":"23.9M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"pondpond","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.8,"import_time_s":0.06,"mem_mb":4.2,"disk_size":"22M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"pondpond","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.16,"mem_mb":5.2,"disk_size":"25.8M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"pondpond","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.7,"import_time_s":0.14,"mem_mb":5.2,"disk_size":"23M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"pondpond","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.4,"mem_mb":8.2,"disk_size":"17.7M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"pondpond","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.5,"import_time_s":0.36,"mem_mb":8.2,"disk_size":"15M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"pondpond","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.4,"mem_mb":8.7,"disk_size":"17.4M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"pondpond","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.7,"import_time_s":0.33,"mem_mb":8.7,"disk_size":"15M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"pondpond","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.08,"mem_mb":4.1,"disk_size":"23.4M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"pondpond","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.9,"import_time_s":0.07,"mem_mb":4.1,"disk_size":"21M"}]}}