Skip to content

Commit c51e0fc

Browse files
committed
fastuuid optional dependency
1 parent 52a56bd commit c51e0fc

File tree

10 files changed

+52
-13
lines changed

10 files changed

+52
-13
lines changed

litellm/_uuid.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""
2+
Internal unified UUID helper.
3+
4+
Tries to use fastuuid (performance) and falls back to stdlib uuid if unavailable.
5+
"""
6+
7+
FASTUUID_AVAILABLE = False
8+
9+
try:
10+
import fastuuid as _uuid # type: ignore
11+
12+
FASTUUID_AVAILABLE = True
13+
except Exception: # pragma: no cover - fallback path
14+
import uuid as _uuid # type: ignore
15+
16+
17+
# Expose a module-like alias so callers can use: uuid.uuid4()
18+
uuid = _uuid
19+
20+
21+
def uuid4():
22+
"""Return a UUID4 using the selected backend."""
23+
return uuid.uuid4()

litellm/litellm_core_utils/litellm_logging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
cast,
2727
)
2828

29-
import fastuuid as uuid
29+
from .._uuid import uuid
3030
from httpx import Response
3131
from pydantic import BaseModel
3232

litellm/llms/bedrock/common_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ def generate_unique_job_name(self, model: str, prefix: str = "litellm") -> str:
774774
Returns:
775775
Unique job name (≤ 63 characters for Bedrock compatibility)
776776
"""
777-
import fastuuid as uuid
777+
from ..._uuid import uuid
778778
unique_id = str(uuid.uuid4())[:8]
779779
# Format: {prefix}-batch-{model}-{uuid}
780780
# Example: litellm-batch-claude-266c398e

litellm/proxy/common_request_processing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
Union,
1515
)
1616

17-
import fastuuid as uuid
17+
from .._uuid import uuid
1818
import httpx
1919
import orjson
2020
from fastapi import HTTPException, Request, status

litellm/types/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
Union,
1414
)
1515

16-
import fastuuid as uuid
16+
from .._uuid import uuid
1717
from aiohttp import FormData
1818
from openai._models import BaseModel as OpenAIObject
1919
from openai.types.audio.transcription_create_params import FileTypes # type: ignore

litellm/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
import aiohttp
4242
import dotenv
43-
import fastuuid as uuid
43+
from ._uuid import uuid
4444
import httpx
4545
import openai
4646
import tiktoken

poetry.lock

Lines changed: 7 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ Documentation = "https://docs.litellm.ai"
2020

2121
[tool.poetry.dependencies]
2222
python = ">=3.8.1,<4.0, !=3.9.7"
23-
fastuuid = ">=0.12.0"
2423
httpx = ">=0.23.0"
2524
openai = ">=1.99.5"
2625
python-dotenv = ">=0.2.0"
@@ -34,6 +33,7 @@ pydantic = "^2.5.0"
3433
jsonschema = "^4.22.0"
3534
pondpond = "^1.4.1"
3635
numpydoc = {version = "*", optional = true} # used in utils.py
36+
fastuuid = {version = ">=0.12.0", optional = true}
3737

3838
uvicorn = {version = "^0.29.0", optional = true}
3939
uvloop = {version = "^0.21.0", optional = true, markers="sys_platform != 'win32'"}
@@ -115,6 +115,8 @@ semantic-router = ["semantic-router"]
115115

116116
mlflow = ["mlflow"]
117117

118+
perf = ["fastuuid"]
119+
118120
[tool.isort]
119121
profile = "black"
120122

requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ backoff==2.2.1 # server dep
88
pyyaml==6.0.2 # server dep
99
uvicorn==0.29.0 # server dep
1010
gunicorn==23.0.0 # server dep
11-
fastuuid==0.12.0 # for uuid4
11+
# Optional performance extra: install via `pip install litellm[perf]`
12+
# fastuuid==0.12.0 # for uuid4
1213
uvloop==0.21.0 # uvicorn dep, gives us much better performance under load
1314
boto3==1.36.0 # aws bedrock/sagemaker calls
1415
redis==5.2.1 # redis caching
@@ -58,7 +59,7 @@ tenacity==8.2.3 # for retrying requests, when litellm.num_retries set
5859
pydantic==2.10.2 # proxy + openai req.
5960
jsonschema==4.22.0 # validating json schema
6061
websockets==13.1.0 # for realtime API
61-
pondpond==1.4.1 # for object pooling
62+
# pondpond==1.4.1 # for object pooling
6263

6364
########################
6465
# LITELLM ENTERPRISE DEPENDENCIES

tests/test_uuid_fallback.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import importlib
2+
3+
4+
def test_fastuuid_flag_exposed():
5+
mod = importlib.import_module("litellm._uuid")
6+
assert hasattr(mod, "FASTUUID_AVAILABLE")
7+
assert hasattr(mod, "uuid4")
8+
# Ensure uuid4 returns something that looks like a UUID string
9+
val = str(mod.uuid4())
10+
assert isinstance(val, str)
11+
assert len(val) >= 8

0 commit comments

Comments
 (0)