Skip to content

Commit 473afd5

Browse files
committed
refactor: make Redis an optional dependency with better error handling
- Move redis and orjson to optional dependencies under [redis] extra - Add clear ImportError messages guiding users to install with [redis] extra - Reduce base package size by making Redis dependencies opt-in
1 parent d564649 commit 473afd5

2 files changed

Lines changed: 25 additions & 9 deletions

File tree

pyproject.toml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ dependencies = [
2828
"google-genai>=1.21.1, <2.0.0", # Google GenAI SDK
2929
"google-adk", # Google ADK
3030
"httpx>=0.27.0, <1.0.0", # For OpenMemory service
31-
"redis >= 7.0.0", # Redis for session storage
3231
# go/keep-sorted end
33-
"orjson>=3.11.4",
3432
]
3533
dynamic = ["version"]
3634

@@ -41,9 +39,13 @@ changelog = "https://github.com/google/adk-python-community/blob/main/CHANGELOG.
4139
documentation = "https://google.github.io/adk-docs/"
4240

4341
[project.optional-dependencies]
42+
redis = [
43+
"redis>=5.0.0", # Redis for session storage
44+
"orjson>=3.11.4", # Fast JSON serialization for Redis
45+
]
4446
test = [
45-
"pytest>=8.4.2",
46-
"pytest-asyncio>=1.2.0",
47+
"pytest>=8.4.2",
48+
"pytest-asyncio>=1.2.0",
4749
]
4850

4951

@@ -72,8 +74,8 @@ build-backend = "flit_core.buildapi"
7274

7375
[dependency-groups]
7476
dev = [
75-
"pytest>=8.4.2",
76-
"pytest-asyncio>=1.2.0",
77+
"pytest>=8.4.2",
78+
"pytest-asyncio>=1.2.0",
7779
]
7880

7981

src/google/adk_community/sessions/redis_session_service.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,25 @@
2020
import uuid
2121
from typing import Any, Optional
2222

23-
import orjson
24-
import redis.asyncio as redis
25-
from redis.crc import key_slot
2623
from typing_extensions import override
2724

25+
try:
26+
import redis.asyncio as redis
27+
from redis.crc import key_slot
28+
except ImportError as exc:
29+
raise ImportError(
30+
"redis is required to use RedisSessionService. "
31+
"Install it with: pip install google-adk-community[redis]"
32+
) from exc
33+
34+
try:
35+
import orjson
36+
except ImportError as exc:
37+
raise ImportError(
38+
"orjson is required to use RedisSessionService. "
39+
"Install it with: pip install google-adk-community[redis]"
40+
) from exc
41+
2842
from google.adk.events.event import Event
2943
from google.adk.sessions.base_session_service import (
3044
BaseSessionService,

0 commit comments

Comments
 (0)