perf(sdk): lazy-load langgraph_sdk top-level exports

Converting __init__.py to use __getattr__ defers loading of Auth,
get_client/get_sync_client, Encryption, and EncryptionContext until
first access. This removes ~13ms from langgraph.runtime import time,
since importing BaseUser from langgraph_sdk.auth.types no longer
triggers the full client/auth/encryption module graph.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Sydney Runkle
2026-04-21 12:56:32 -04:00
co-authored by Claude Sonnet 4.6
parent c459079e52
commit 186d045947
+26 -4
View File
@@ -1,8 +1,30 @@
from langgraph_sdk.auth import Auth
from langgraph_sdk.client import get_client, get_sync_client
from langgraph_sdk.encryption import Encryption
from langgraph_sdk.encryption.types import EncryptionContext
from __future__ import annotations
import importlib
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from langgraph_sdk.auth import Auth
from langgraph_sdk.client import get_client, get_sync_client
from langgraph_sdk.encryption import Encryption
from langgraph_sdk.encryption.types import EncryptionContext
__version__ = "0.3.13"
__all__ = ["Auth", "Encryption", "EncryptionContext", "get_client", "get_sync_client"]
_LAZY: dict[str, str] = {
"Auth": "langgraph_sdk.auth",
"get_client": "langgraph_sdk.client",
"get_sync_client": "langgraph_sdk.client",
"Encryption": "langgraph_sdk.encryption",
"EncryptionContext": "langgraph_sdk.encryption.types",
}
def __getattr__(name: str) -> object:
if name in _LAZY:
mod = importlib.import_module(_LAZY[name])
return getattr(mod, name)
msg = f"module {__name__!r} has no attribute {name!r}"
raise AttributeError(msg)