Skip to content
This repository was archived by the owner on Nov 11, 2026. It is now read-only.

Commit ef6b767

Browse files
Add aread_project in python SDK (#3157)
## Summary - Removes the `projects` property accessor from the Python `Client` (`client.py`) and JS `Client` (`client.ts`), along with its dedicated integration test file. - Adds `aread_project`, an async counterpart to `read_project`, directly on the sync `Client`. It offloads the existing validated request logic (xor_args validation, UUID handling, retries) to a worker thread via `asyncio.to_thread` so it doesn't block the event loop, without touching `async_client.py`.
1 parent b5c9d01 commit ef6b767

4 files changed

Lines changed: 55 additions & 106 deletions

File tree

‎js/src/client.ts‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ import { OnlineEvaluators } from "./_openapi_client/resources/online-evaluators.
7979
import { Runs as OpenAPIRuns } from "./_openapi_client/resources/runs.js";
8080
import { Sandboxes } from "./_openapi_client/resources/sandboxes/sandboxes.js";
8181
import { Datasets } from "./_openapi_client/resources/datasets/datasets.js";
82-
import { Sessions } from "./_openapi_client/resources/sessions.js";
8382
import { assertUuid } from "./utils/_uuid.js";
8483
import { warnOnce } from "./utils/warn.js";
8584
import { _MIN_BACKEND_VERSION } from "./utils/constants.js";
@@ -1482,11 +1481,6 @@ export class Client implements LangSmithTracingClientInterface {
14821481
return this.openAPIClient.sandboxes;
14831482
}
14841483

1485-
/** Access the projects resource. */
1486-
public get projects(): Sessions {
1487-
return this.openAPIClient.sessions;
1488-
}
1489-
14901484
/** Access the v2 datasets resource (experimentRuns, etc.). */
14911485
public get datasets(): Datasets {
14921486
return this.openAPIClient.datasets;

‎python/langsmith/client.py‎

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import collections
1818
import concurrent.futures as cf
1919
import contextlib
20+
import contextvars
2021
import datetime
2122
import functools
2223
import importlib
@@ -69,6 +70,7 @@
6970
from langsmith import env as ls_env
7071
from langsmith import schemas as ls_schemas
7172
from langsmith import utils as ls_utils
73+
from langsmith._internal import _aiter as aitertools
7274
from langsmith._internal import _orjson, _profiles
7375
from langsmith._internal._backend_version import _check_backend_version
7476
from langsmith._internal._background_thread import (
@@ -274,7 +276,6 @@ class TracerProvider: # type: ignore[no-redef]
274276
from langsmith._openapi_client.resources.sandboxes.sandboxes import (
275277
AsyncSandboxesResource,
276278
)
277-
from langsmith._openapi_client.resources.sessions import AsyncSessionsResource
278279

279280
# OTEL imports for type hints
280281
try:
@@ -1478,12 +1479,6 @@ def sandboxes(self) -> AsyncSandboxesResource:
14781479
_check_backend_version(self.info.version)
14791480
return self._get_langsmith_api().sandboxes
14801481

1481-
@property
1482-
def projects(self) -> AsyncSessionsResource:
1483-
"""Access the projects resource."""
1484-
_check_backend_version(self.info.version)
1485-
return self._get_langsmith_api().sessions
1486-
14871482
@property
14881483
def datasets(self) -> AsyncDatasetsResource:
14891484
"""Access the v2 datasets resource (experiment_runs, etc.)."""
@@ -4982,6 +4977,34 @@ def read_project(
49824977
**response.json(), _host_url=self._host_url
49834978
)
49844979

4980+
async def aread_project(
4981+
self,
4982+
*,
4983+
project_id: Optional[str] = None,
4984+
project_name: Optional[str] = None,
4985+
include_stats: bool = False,
4986+
) -> ls_schemas.TracerSessionResult:
4987+
"""Asynchronously read a project from the LangSmith API.
4988+
4989+
Args:
4990+
project_id (Optional[str]):
4991+
The ID of the project to read.
4992+
project_name (Optional[str]): The name of the project to read.
4993+
Only one of project_id or project_name may be given.
4994+
include_stats (bool, default=False):
4995+
Whether to include a project's aggregate statistics in the response.
4996+
4997+
Returns:
4998+
TracerSessionResult: The project.
4999+
"""
5000+
return await aitertools.aio_to_thread(
5001+
contextvars.copy_context(),
5002+
self.read_project,
5003+
project_id=project_id,
5004+
project_name=project_name,
5005+
include_stats=include_stats,
5006+
)
5007+
49855008
def has_project(
49865009
self, project_name: str, *, project_id: Optional[str] = None
49875010
) -> bool:

‎python/tests/integration_tests/test_client.py‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,31 @@ async def test_online_evaluators_generated_client_crud(
172172
)
173173

174174

175+
async def test_aread_project(langchain_client: Client) -> None:
176+
"""Exercise the async aread_project method against the LangSmith API."""
177+
project_name = "__sdk_aread_project_integration_" + "".join(
178+
random.sample(string.ascii_lowercase, 10)
179+
)
180+
created = langchain_client.create_project(project_name)
181+
try:
182+
project = await langchain_client.aread_project(project_name=project_name)
183+
assert project.id == created.id
184+
assert project.name == project_name
185+
186+
project_by_id = await langchain_client.aread_project(
187+
project_id=str(created.id), include_stats=True
188+
)
189+
assert project_by_id.id == created.id
190+
191+
nonexistent_name = "__sdk_aread_project_missing_" + "".join(
192+
random.sample(string.ascii_lowercase, 10)
193+
)
194+
with pytest.raises(LangSmithNotFoundError):
195+
await langchain_client.aread_project(project_name=nonexistent_name)
196+
finally:
197+
langchain_client.delete_project(project_name=project_name)
198+
199+
175200
def test_datasets(parameterized_multipart_client: Client) -> None:
176201
"""Test datasets."""
177202
csv_content = "col1,col2\nval1,val2"

‎python/tests/integration_tests/test_projects.py‎

Lines changed: 0 additions & 93 deletions
This file was deleted.

0 commit comments

Comments
 (0)