Registry / llm-agents / langchainplus-sdk

langchainplus-sdk

JSON →
library0.0.20pypypi✓ verified 22d ago

The `langchainplus-sdk` is the official Python client library designed to connect to the LangSmith LLM Tracing and Evaluation Platform. LangSmith is a unified developer platform that helps teams debug, evaluate, and monitor language models and intelligent agents. This SDK facilitates logging traces, creating datasets, and evaluating runs, offering seamless integration with the LangChain framework while also supporting standalone use with other LLM applications. The current version is 0.0.20, with updates to the underlying LangSmith platform being more frequent.

pip install langchainplus-sdk
INSTALL
IMPORT
SIG · LANGCHAINPLUS-SDK
L
langchainplus-sdk
llm-agentspythonv0.0.20
Install
2.8s avg
Import
521ms
Disk
28MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.0.20 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.528s · 29.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.8s · import 0.514s · 30MB
28MB installed
● package 28MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

LangChainPlusClient
from langchainplus_sdk import LangChainPlusClient

This quickstart demonstrates how to initialize the `LangChainPlusClient` and interact with the LangSmith platform by creating a dataset and an example. It highlights the use of environment variables for configuration, which is the recommended way for tracing. Replace 'YOUR_LANGCHAINPLUS_API_KEY' with your actual LangSmith API key.

import os from langchainplus_sdk import LangChainPlusClient # Set up LangSmith environment variables # Replace with your actual API key and optionally project name os.environ["LANGCHAIN_TRACING_V2"] = "true" os.environ["LANGCHAIN_ENDPOINT"] = os.environ.get("LANGCHAIN_ENDPOINT", "https://api.langchain.plus") os.environ["LANGCHAIN_API_KEY"] = os.environ.get("LANGCHAIN_API_KEY", "YOUR_LANGCHAINPLUS_API_KEY") # os.environ["LANGCHAIN_PROJECT"] = os.environ.get("LANGCHAIN_PROJECT", "My Default Project") # Initialize the client (optional, tracing often works via environment variables directly) client = LangChainPlusClient() # Example: Create a simple dataset entry dataset_name = "My Example Dataset" description = "A dataset for demonstrating langchainplus-sdk usage." # In a real application, you would log traces from your LLM calls # or manually create runs/examples. For this quickstart, we'll simulate a simple action. try: # This part would typically be driven by actual LLM runs being traced # For a direct client interaction, you can create datasets and examples. # Check if dataset exists, if not, create it existing_datasets = client.list_datasets(name=dataset_name) if not list(existing_datasets): dataset = client.create_dataset(name=dataset_name, description=description) print(f"Created dataset: {dataset.name} (ID: {dataset.id})") else: dataset = list(existing_datasets)[0] print(f"Using existing dataset: {dataset.name} (ID: {dataset.id})") # Example of creating a simple example within the dataset example_name = "Initial Example" example_inputs = {"question": "What is the capital of France?"} example_outputs = {"answer": "Paris"} # Check if example exists to avoid duplicates in quickstart re-runs existing_examples = client.list_examples(dataset_id=dataset.id) example_found = False for ex in existing_examples: if ex.inputs == example_inputs and ex.outputs == example_outputs: example_found = True break if not example_found: example = client.create_example( dataset_id=dataset.id, inputs=example_inputs, outputs=example_outputs, name=example_name ) print(f"Created example: {example.name} (ID: {example.id})") else: print(f"Example '{example_name}' already exists in dataset.") print("LangSmith client setup and basic interaction successful.") print("Check your LangSmith UI for traces and datasets.") except Exception as e: print(f"An error occurred: {e}") print("Please ensure your LANGCHAIN_API_KEY is correct and LangSmith service is accessible.")
Debug
Known issues
gotchaThe PyPI package `langchainplus-sdk` is the Python client for the LangSmith platform. Users might be confused by the different naming conventions (`langchainplus` vs. `langsmith`) and might search for `langsmith-sdk` on PyPI, which does not exist under that exact name. The active development and more frequent releases are seen in the `langchain-ai/langsmith-sdk` GitHub repository, indicating `langchainplus-sdk` on PyPI might be a less frequently updated wrapper or a specific version of that client.
fix
Be aware that `langchainplus-sdk` is the correct PyPI package for the LangSmith Python client. Refer to LangSmith documentation for the most up-to-date usage patterns.
affects: All versions
breakingThe `RunTree` API, used for logging traces outside of the main LangChain framework, is noted as 'experimental' and subject to future changes. This means code relying heavily on this specific API might require adjustments in newer versions.
fix
Monitor official LangSmith documentation for updates to the `RunTree` API when logging traces outside of LangChain. Decouple your core logic from `RunTree` where possible to minimize refactoring needs.
affects: All versions, especially future major releases
gotchaTracing and platform connection heavily rely on environment variables (e.g., `LANGCHAIN_TRACING_V2`, `LANGCHAIN_ENDPOINT`, `LANGCHAIN_API_KEY`). Incorrectly set or missing environment variables are a common source of connection or tracing failures.
fix
Always ensure that required environment variables are correctly set and accessible to your application. Double-check API keys and endpoint URLs. Use a `.env` file for local development and secure secrets management in production.
affects: All versions
gotchaThere have been reports of `LangchainCallbackHandler` (which the SDK utilizes for tracing LangChain operations) losing cache token metrics and inflating input token costs in non-streaming paths for certain models (e.g., Anthropic, OpenAI). This can lead to inaccurate cost estimations in LangSmith.
fix
Be aware of potential inaccuracies in token cost reporting, especially for non-streaming LLM calls with caching enabled. Cross-reference LangSmith reports with direct API usage metrics from your LLM provider if cost accuracy is critical. Monitor `langsmith-sdk` GitHub issues for fixes related to token parsing.
affects: Likely versions 0.0.20 and potentially newer client versions interacting with LangChain, as per GitHub issues.
Errors
Common errors & fixes
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. langchainplus-sdk 0.0.20 requires pydantic<2,>=1, but you have pydantic X.Y.Z which is incompatible.
Older versions of `langchainplus-sdk` (like 0.0.20) have a strict dependency on `pydantic` version 1.x, which conflicts with newer versions of `langchain` or other libraries that require `pydantic` 2.x.
fix
Upgrade both `langchainplus-sdk` and `langchain` to their latest versions to ensure compatibility with `pydantic` v2, or if forced to use older versions, explicitly install `pydantic==1.*` before installing other packages.

```python
# Recommended: Upgrade all relevant packages
pip install --upgrade langchain langchainplus-sdk pydantic

# Alternative (if older versions are strictly required):
pip install pydantic==1.* # Install pydantic v1 first
pip install langchainplus-sdk==0.0.20 # Install the compatible sdk version
```
LangChainPlusUserError: API key must be provided when using hosted LangChain+ API
The LangSmith platform requires an API key for authentication, which has not been correctly provided via environment variables or explicitly in the code.
fix
Set the `LANGCHAIN_API_KEY` environment variable with your LangSmith API key. Also, ensure `LANGCHAIN_TRACING_V2` is set to 'true' and `LANGCHAIN_ENDPOINT` points to the correct LangSmith URL.

```python
import os
os.environ["LANGCHAIN_API_KEY"] = "YOUR_LANGSMITH_API_KEY"
os.environ["LANGCHAIN_TRACING_V2"] = "true" # Enables v2 tracing
os.environ["LANGCHAIN_ENDPOINT"] = "https://api.langchain.plus" # Or your self-hosted instance
```
ImportError: cannot import name 'LangChainPlusClient' from 'langchainplus_sdk'
The `LangChainPlusClient` class, or similar client entry points, may have been renamed, moved, or removed in different versions of the `langchainplus-sdk` (now `langsmith`), leading to an import error.
fix
Check the official LangSmith SDK documentation for the correct import path and class name for the client in your installed version. As of current versions, the primary client is typically imported from `langsmith`.

```python
# For current versions of the LangSmith SDK:
from langsmith import Client
# client = Client(...) # Use the imported Client class

# If using an older version of langchain and its associated sdk,
# you might need to pin the langchainplus-sdk version, e.g.:
pip install langchainplus-sdk==0.0.20
```
Upgrade
Version history
0.0.20latest on PyPI · released Jul 3, 2023
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
10
OpenAI (training)
2
Resources
langchainplus-sdk — pip install langchainplus-sdk · libregistry