Skip to content

Commit

Permalink
Add session param to SDK client. (#243)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
langchain-infra authored Oct 5, 2023
1 parent c7f0ff9 commit fa43f2f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion python/langsmith/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
------
Expand All @@ -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
Expand Down

0 comments on commit fa43f2f

Please sign in to comment.