SDK for interacting with LangGraph API
Project description
LangGraph Python SDK
This repository contains the Python SDK for interacting with the LangSmith Deployment REST API.
Quick Start
To get started with the Python SDK, install the package
pip install -U langgraph-sdk
You will need a running LangGraph API server. If you're running a server locally using langgraph-cli, SDK will automatically point at http://localhost:8123, otherwise
you would need to specify the server URL when creating a client.
from langgraph_sdk import get_client
# If you're using a remote server, initialize the client with `get_client(url=REMOTE_URL)`
client = get_client()
# List all assistants
assistants = await client.assistants.search()
# We auto-create an assistant for each graph you register in config.
agent = assistants[0]
# Start a new thread
thread = await client.threads.create()
# Start a streaming run
input = {"messages": [{"role": "human", "content": "what's the weather in la"}]}
async for chunk in client.runs.stream(thread['thread_id'], agent['assistant_id'], input=input):
print(chunk)
Known Limitations
- WebSocket transport requires
websockets>=14and is only available on the async client (AsyncThreadStream). The sync client (SyncThreadStream) uses SSE exclusively. thread.extensions[name]opens a new subscription each time the same name is accessed. Assign the projection to a variable and reuse it within a single session rather than re-indexing across multiple iterations.- Sync streaming drives the lifecycle watcher in a background thread. Long-lived sync sessions will hold that thread open until the context manager exits.
- Reconnect attempts are limited to 5 by default for both the shared SSE fan-out and the lifecycle watcher. Persistent network partitions will surface as
RuntimeErroron in-flight projections.
Thread-Centric Streaming (v3)
client.threads.stream() returns a context manager that owns the SSE session for one
thread. Typed projections — values snapshots, message streams, tool calls, custom
events — all share the same underlying connection.
from langgraph_sdk import get_client
import asyncio
client = get_client()
async with client.threads.stream(
thread_id="my-thread",
assistant_id="agent",
) as thread:
await thread.run.start(input={"messages": [{"role": "user", "content": "hi"}]})
# Start all consumers concurrently so they share one SSE connection.
async def get_messages():
return [s async for s in thread.messages]
async def get_tool_calls():
return [c async for c in thread.tool_calls]
messages, tool_calls = await asyncio.gather(get_messages(), get_tool_calls())
for stream in messages:
print(await stream.text) # accumulated text
final = await thread.output # terminal state values
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langgraph_sdk-0.4.0.tar.gz.
File metadata
- Download URL: langgraph_sdk-0.4.0.tar.gz
- Upload date:
- Size: 332.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd84612d215d6dca11cdfc8c0835df2910c7e51a0b0150b950fc7a928c76a2eb
|
|
| MD5 |
dd50c697d65d25c3699d9e632a519a0a
|
|
| BLAKE2b-256 |
613710d16618ca3e57e465f2e614ba5130261e8791c6359ca5122b1422d053ca
|
File details
Details for the file langgraph_sdk-0.4.0-py3-none-any.whl.
File metadata
- Download URL: langgraph_sdk-0.4.0-py3-none-any.whl
- Upload date:
- Size: 154.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e79d05c01b2a04039af27ef4ee5707334d8676fc18645b20ad8dc5cddba55086
|
|
| MD5 |
c0462f7e9c26649e40029bd7b9b670a0
|
|
| BLAKE2b-256 |
f6a5a9626ea27e1369b5b8a39b92f4eb42aa64e781f40323241b1247c50873fc
|