From fa43f2fd69752f789677b2958edd94ce2dbebc69 Mon Sep 17 00:00:00 2001 From: langchain-infra <144731603+langchain-infra@users.noreply.github.com> Date: Thu, 5 Oct 2023 01:04:38 -0400 Subject: [PATCH] Add session param to SDK client. (#243) Some people want to override our request session. We should enable them to do this when creating their client by creating their own session and passing it in. TODO to port to javascript. --- python/langsmith/client.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/python/langsmith/client.py b/python/langsmith/client.py index 0ea255271..c86f787af 100644 --- a/python/langsmith/client.py +++ b/python/langsmith/client.py @@ -236,6 +236,7 @@ def __init__( retry_config: Optional[Retry] = None, timeout_ms: Optional[int] = None, web_url: Optional[str] = None, + session: Optional[requests.Session] = None, ) -> None: """Initialize a Client instance. @@ -254,6 +255,9 @@ def __init__( web_url : str or None, default=None URL for the LangSmith web app. Default is auto-inferred from the ENDPOINT. + session: requests.Session or None, default=None + The session to use for requests. If None, a new session will be + created. Raises ------ @@ -268,7 +272,7 @@ def __init__( self._web_url = web_url self._tenant_id: Optional[uuid.UUID] = None # Create a session and register a finalizer to close it - self.session = requests.Session() + self.session = session if session else requests.Session() weakref.finalize(self, close_session, self.session) # Mount the HTTPAdapter with the retry configuration