The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
Fix: make `pondpond` as optional dependency for `proxy` extras, disable object pooling gracefully (#14863)
Alex Shoope75d8b711e15
diff --git a/litellm/litellm_core_utils/object_pooling.py b/litellm/litellm_core_utils/object_pooling.pyindex 846e6536f80..81c3ec2e133 100644--- a/litellm/litellm_core_utils/object_pooling.py+++ b/litellm/litellm_core_utils/object_pooling.py@@ -16,11 +16,35 @@ Memory Management Strategy:from typing import Any, Callable, Optional, Type, TypeVar-from pond import Pond, PooledObject, PooledObjectFactory+try:+ from pond import Pond, PooledObject, PooledObjectFactory # type: ignore+ POND_AVAILABLE = True+except ImportError: # pragma: no cover+ POND_AVAILABLE = False+ class Pond: # type: ignore+ def __init__(self, *args: Any, **kwargs: Any) -> None:+ pass++ def register(self, *args: Any, **kwargs: Any) -> None:+ pass++ def borrow(self, *args: Any, **kwargs: Any) -> Any:+ pass++ def recycle(self, *args: Any, **kwargs: Any) -> None:+ pass++ class PooledObject: # type: ignore+ def __init__(self, keeped_object: Any = None) -> None:+ self.keeped_object = keeped_object++ class PooledObjectFactory: # type: ignore+ def __init__(self, *args: Any, **kwargs: Any) -> None:+ passT = TypeVar('T')-class GenericPooledObjectFactory(PooledObjectFactory):+class GenericPooledObjectFactory(PooledObjectFactory): # type: ignore[misc]"""Generic factory class for creating pooled objects of any type."""def __init__(@@ -79,7 +103,7 @@ def get_object_pool(time_between_eviction_runs: int = 300, # Less frequent eviction to maintain high reuse ratioeviction_weight: float = 0.3, # Less aggressive eviction for better reuseprewarm_count: int = 5 # Lower pre-warm count to reduce initial memory usage-) -> Pond:+) -> Pond | None:"""Get or create a global object pool instance with balanced eviction-based memory control.Memory is controlled through moderate eviction to balance reuse ratio and memory usage:@@ -98,9 +122,13 @@ def get_object_pool(prewarm_count: Number of objects to pre-warm the pool with (default: 5)Returns:- Pond instance for the specified object type+ Pond instance for the specified object type or None if pond is not available"""+ # If pond is not available, disable pooling gracefully+ if not POND_AVAILABLE:+ return None+if pool_name in _pools:return _pools[pool_name]@@ -134,4 +162,4 @@ def _prewarm_pool(pond: Pond, pool_name: str, prewarm_count: int = 20) -> None:pond.recycle(pooled_obj, name=f"{pool_name}Factory")except Exception:# If pre-warming fails, just continue- break\ No newline at end of file+ breakdiff --git a/poetry.lock b/poetry.lockindex a8ef9ee79df..87599768db6 100644--- a/poetry.lock+++ b/poetry.lock@@ -2730,9 +2730,10 @@ files = [name = "madoka"version = "0.7.1"description = "Memory-efficient CountMin Sketch key-value structure (based on Madoka C++ library)"-optional = false+optional = truepython-versions = "*"groups = ["main"]+markers = "extra == \"proxy\""files = [{file = "madoka-0.7.1-cp37-cp37m-macosx_10_14_x86_64.whl", hash = "sha256:7521eee9ace30b376bb54fdcb2cb42bf6b7a0346b0d0b612f25f3299aa4a95af"},{file = "madoka-0.7.1.tar.gz", hash = "sha256:e258baa84fc0a3764365993b8bf5e1b065383a6ca8c9f862fb3e3e709843fae7"},@@ -4044,9 +4045,10 @@ xlsxwriter = ["xlsxwriter"]name = "pondpond"version = "1.4.1"description = "Pond is a high performance object-pooling library for Python."-optional = false+optional = truepython-versions = ">=3.8"groups = ["main"]+markers = "extra == \"proxy\""files = [{file = "pondpond-1.4.1-py3-none-any.whl", hash = "sha256:641028ead4e8018ca6de1220c660ddd6d6fbf62a60e72f410655dd0451d82880"},{file = "pondpond-1.4.1.tar.gz", hash = "sha256:8afa34b869d1434d21dd2ec12644abc3b1733fcda8fcf355300338a13a79bb7b"},@@ -6747,11 +6749,11 @@ type = ["pytest-mypy"]caching = ["diskcache"]extra-proxy = ["azure-identity", "azure-keyvault-secrets", "google-cloud-iam", "google-cloud-kms", "prisma", "redisvl", "resend"]mlflow = ["mlflow"]-proxy = ["PyJWT", "apscheduler", "azure-identity", "azure-storage-blob", "backoff", "boto3", "cryptography", "fastapi", "fastapi-sso", "fastuuid", "gunicorn", "litellm-enterprise", "litellm-proxy-extras", "mcp", "orjson", "polars", "pynacl", "python-multipart", "pyyaml", "rich", "rq", "uvicorn", "uvloop", "websockets"]+proxy = ["PyJWT", "apscheduler", "azure-identity", "azure-storage-blob", "backoff", "boto3", "cryptography", "fastapi", "fastapi-sso", "fastuuid", "gunicorn", "litellm-enterprise", "litellm-proxy-extras", "mcp", "orjson", "polars", "pondpond", "pynacl", "python-multipart", "pyyaml", "rich", "rq", "uvicorn", "uvloop", "websockets"]semantic-router = ["semantic-router"]utils = ["numpydoc"][metadata]lock-version = "2.1"python-versions = ">=3.8.1,<4.0, !=3.9.7"-content-hash = "75004c6a23b70be86622fa417fd0d62fa3843e6e61c8dff8507ae5c967b7205d"+content-hash = "16fdc1044b4bb316803cbf1825bc970895526949a8bef93eab741777b7210ca8"diff --git a/pyproject.toml b/pyproject.tomlindex b11b1a1c2e2..4113714415c 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -31,7 +31,7 @@ jinja2 = "^3.1.2"aiohttp = ">=3.10"pydantic = "^2.5.0"jsonschema = "^4.22.0"-pondpond = "^1.4.1"+pondpond = {version = "^1.4.1", optional = true}numpydoc = {version = "*", optional = true} # used in utils.pyfastuuid = {version = ">=0.12.0", optional = true}@@ -94,6 +94,7 @@ proxy = ["rich","polars","fastuuid",+ "pondpond",]extra_proxy = [diff --git a/tests/litellm_utils_tests/test_object_pooling.py b/tests/litellm_utils_tests/test_object_pooling.pyindex 5cdc38ee452..8d0272e92b9 100644--- a/tests/litellm_utils_tests/test_object_pooling.py+++ b/tests/litellm_utils_tests/test_object_pooling.py@@ -3,6 +3,7 @@ Simplified tests for object pooling utilities in litellm."""import pytest+pytest.importorskip("pond")from litellm.litellm_core_utils.object_pooling import (get_object_pool,@@ -103,4 +104,4 @@ class TestObjectPooling:if __name__ == "__main__":- pytest.main([__file__])\ No newline at end of file+ pytest.main([__file__])