Skip to main content

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>=14 and 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 RuntimeError on 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

This version

0.4.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langgraph_sdk-0.4.1.tar.gz (347.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langgraph_sdk-0.4.1-py3-none-any.whl (160.4 kB view details)

Uploaded Python 3

File details

Details for the file langgraph_sdk-0.4.1.tar.gz.

File metadata

  • Download URL: langgraph_sdk-0.4.1.tar.gz
  • Upload date:
  • Size: 347.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for langgraph_sdk-0.4.1.tar.gz
Algorithm Hash digest
SHA256 c7a2bd4ae4abad2bd5fef7a624d768ea9a173ec8c0ab86cf7504f9c8552cd51b
MD5 6d00c904e6bab00d462ea55c5a06b2a0
BLAKE2b-256 803a814cec4c7b218316edccd7cccb8890109e5c7d8eabd650a75ae79a57cfff

See more details on using hashes here.

File details

Details for the file langgraph_sdk-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: langgraph_sdk-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 160.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for langgraph_sdk-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2357f39018a4349ad9c1823a40f17cd97add8164abcc5f838da9255b1c4f801a
MD5 90b70a5725d18f5a6446d4a6a7c20d08
BLAKE2b-256 263b1fadf956cc02ac54b8769cb6d8f3d84fd649338ada36f9dcf185e86d7de8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page