LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
  • LangGraph Checkpoint
    LangGraph Store
    Checkpoint Postgres
    Store Postgres
    Checkpoint SQLite
    LangGraph Prebuilt
    LangGraph CLI
    LangGraph SDK
    LangGraph Supervisor
    LangGraph Swarm
    ⌘I

    LangChain Assistant

    Ask a question to get started

    Enter to send•Shift+Enter new line

    Menu

    LangGraph Checkpoint
    LangGraph Store
    Checkpoint Postgres
    Store Postgres
    Checkpoint SQLite
    LangGraph Prebuilt
    LangGraph CLI
    LangGraph SDK
    LangGraph Supervisor
    LangGraph Swarm
    Language
    Theme
    Pythonlanggraph-sdk

    langgraph-sdk

    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

    Classes

    Class

    LangSmithTracing

    Configuration for LangSmith tracing.

    Class

    Config

    Configuration options for a call.

    Class

    Checkpoint

    Represents a checkpoint in the execution process.

    Class

    GraphSchema

    Defines the structure and properties of a graph.

    Class

    AssistantBase

    Base model for an assistant.

    Class

    AssistantVersion

    Represents a specific version of an assistant.

    Class

    Assistant

    Represents an assistant with additional properties.

    Class

    AssistantsSearchResponse

    Paginated response for assistant search results.

    Class

    Interrupt

    Represents an interruption in the execution flow.

    Class

    Thread

    Represents a conversation thread.

    Class

    ThreadTask

    Represents a task within a thread.

    Class

    ThreadState

    Represents the state of a thread.

    Class

    ThreadUpdateStateResponse

    Represents the response from updating a thread's state.

    Class

    Run

    Represents a single execution run.

    Class

    Cron

    Represents a scheduled task.

    Class

    CronUpdate

    Payload for updating a cron job. All fields are optional.

    Class

    RunCreate

    Defines the parameters for initiating a background run.

    Class

    Item

    Represents a single document or data entry in the graph's Store.

    Class

    ListNamespaceResponse

    Response structure for listing namespaces.

    Class

    SearchItem

    Item with an optional relevance score from search operations.

    Class

    SearchItemsResponse

    Response structure for searching items.

    Class

    StreamPart

    Represents a part of a stream response.

    Class

    TaskPayload

    Payload for a task start event.

    Class

    TaskResultPayload

    Payload for a task result event.

    Class

    CheckpointTaskPayload

    A task entry within a CheckpointPayload.

    Class

    CheckpointPayload

    Payload for a checkpoint event.

    Class

    RunMetadataPayload

    Payload for the metadata control event.

    Class

    ValuesStreamPart

    Stream part emitted for stream_mode="values".

    Class

    UpdatesStreamPart

    Stream part emitted for stream_mode="updates".

    Class

    MessagesPartialStreamPart

    Stream part emitted for partial message chunks (messages/partial).

    Class

    MessagesCompleteStreamPart

    Stream part emitted for complete messages (messages/complete).

    Class

    MessagesMetadataStreamPart

    Stream part emitted for message metadata (messages/metadata).

    Class

    MessagesTupleStreamPart

    Stream part emitted for stream_mode="messages" (raw message+metadata pair).

    Class

    CustomStreamPart

    Stream part emitted for stream_mode="custom".

    Class

    CheckpointsStreamPart

    Stream part emitted for stream_mode="checkpoints".

    Class

    TasksStreamPart

    Stream part emitted for stream_mode="tasks".

    Class

    DebugStreamPart

    Stream part emitted for stream_mode="debug".

    Class

    MetadataStreamPart

    Control event with run_id and other run metadata.

    Class

    Send

    Represents a message to be sent to a specific node in the graph.

    Class

    Command

    Represents one or more commands to control graph execution flow and state.

    Class

    RunCreateMetadata

    Metadata for a run creation request.

    Class

    BytesLineDecoder

    Handles incrementally reading lines from text.

    Class

    SSEDecoder

    Class

    LangGraphError

    Class

    APIError

    Class

    APIResponseValidationError

    Class

    APIStatusError

    Class

    APIConnectionError

    Class

    APITimeoutError

    Class

    BadRequestError

    Class

    AuthenticationError

    Class

    PermissionDeniedError

    Class

    NotFoundError

    Class

    ConflictError

    Class

    UnprocessableEntityError

    Class

    RateLimitError

    Class

    InternalServerError

    Class

    SWRResult

    Result wrapper returned by :func:swr.

    Class

    StreamController

    Manages subscriptions and fan-out against one shared SSE connection.

    Class

    MultiCursorBuffer

    Class

    SyncStreamController

    Owns the sync shared SSE handle, subscription registry, and fan-out thread.

    Class

    Decoder

    Class

    DataDecoder

    Yields params.data from events of a single method.

    Class

    MessagesDecoder

    Yields one chat-model stream per message-start event.

    Class

    ToolCallsDecoder

    Yields one tool-call handle per tool-started event.

    Class

    SubgraphsDecoder

    Discovers child subgraph handles and fans out events to active ones.

    Class

    ExtensionsDecoder

    Yields params.data from one named custom channel.

    Class

    SyncProtocolSseTransport

    Sync v3 protocol transport bound to one thread id.

    Class

    ProtocolWebSocketTransport

    v3 protocol transport using HTTP commands and WebSocket events.

    Class

    ProtocolSseTransport

    v3 protocol transport bound to a single thread_id.

    Class

    SyncProtocolWebSocketTransport

    Sync v3 protocol transport using HTTP commands and WebSocket events.

    Class

    EventStreamHandle

    Handle for one async filtered event stream.

    Class

    SyncEventStreamHandle

    Handle for one sync filtered event stream.

    Class

    AsyncProtocolTransport

    Protocol implemented by async SSE and WebSocket transports.

    Class

    SyncProtocolTransport

    Protocol implemented by sync SSE and WebSocket transports.

    Class

    SyncLangGraphClient

    Synchronous client for interacting with the LangGraph API.

    Class

    SyncThreadsClient

    Synchronous client for managing threads in LangGraph.

    Class

    SyncHttpClient

    Handle synchronous requests to the LangGraph API.

    Class

    SyncRunsClient

    Synchronous client for managing runs in LangGraph.

    Class

    SyncStoreClient

    A client for synchronous operations on a key-value store.

    Class

    SyncCronClient

    Synchronous client for managing cron jobs in LangGraph.

    Class

    SyncAssistantsClient

    Client for managing assistants in LangGraph synchronously.

    Class

    InterruptPayload

    Payload surfaced when the server requests human input for a thread.

    Class

    SyncRunModule

    Command dispatcher for run.start.

    Class

    SyncToolCallHandle

    Sync handle for one root-scope tool call.

    Class

    SyncScopedStreamHandle

    Scoped streaming handle for one discovered child invocation.

    Class

    SyncThreadStream

    Synchronous context manager for one thread's v3 streaming session.

    Class

    LangGraphBetaWarning

    Warning for beta features in LangGraph SDK.

    Class

    DuplicateHandlerError

    Raised when attempting to register a duplicate encryption/decryption handler.

    Class

    Encryption

    Add custom at-rest encryption to your LangGraph application.

    Class

    EncryptionContext

    Context passed to encryption/decryption handlers.

    Class

    LangGraphClient

    Top-level client for LangGraph API.

    Class

    ThreadsClient

    Client for managing threads in LangGraph.

    Class

    HttpClient

    Handle async requests to the LangGraph API.

    Class

    RunsClient

    Client for managing runs in LangGraph.

    Class

    StoreClient

    Client for interacting with the graph's shared storage.

    Class

    CronClient

    Client for managing recurrent runs (cron jobs) in LangGraph.

    Class

    AssistantsClient

    Client for managing assistants in LangGraph.

    Class

    InterruptPayload

    Payload surfaced when the server requests human input for a thread.

    Class

    RunModule

    Command dispatcher for run.start.

    Class

    ScopedStreamHandle

    Scoped streaming handle for one discovered child invocation.

    Class

    ToolCallHandle

    Async handle for one root-scope tool call.

    Class

    AsyncThreadStream

    Async context manager for one thread's v3 streaming session.

    Class

    Auth

    Add custom authentication and authorization management to your LangGraph application.

    Class

    HTTPException

    HTTP exception that you can raise to return a specific HTTP error response.

    Class

    MinimalUser

    User objects must at least expose the identity property.

    Class

    MinimalUserDict

    The dictionary representation of a user.

    Class

    BaseUser

    The base ASGI user protocol

    Class

    StudioUser

    A user object that's populated from authenticated requests from the LangGraph studio.

    Class

    BaseAuthContext

    Base class for authentication context.

    Class

    AuthContext

    Complete authentication context with resource and action information.

    Class

    ThreadTTL

    Time-to-live configuration for a thread.

    Class

    ThreadsCreate

    Parameters for creating a new thread.

    Class

    ThreadsRead

    Parameters for reading thread state or run information.

    Class

    ThreadsUpdate

    Parameters for updating a thread or run.

    Class

    ThreadsDelete

    Parameters for deleting a thread.

    Class

    ThreadsSearch

    Parameters for searching threads.

    Class

    RunsCreate

    Payload for creating a run.

    Class

    AssistantsCreate

    Payload for creating an assistant.

    Class

    AssistantsRead

    Payload for reading an assistant.

    Class

    AssistantsUpdate

    Payload for updating an assistant.

    Class

    AssistantsDelete

    Payload for deleting an assistant.

    Class

    AssistantsSearch

    Payload for searching assistants.

    Class

    CronsCreate

    Payload for creating a cron job.

    Class

    CronsDelete

    Payload for deleting a cron job.

    Class

    CronsRead

    Payload for reading a cron job.

    Class

    CronsUpdate

    Payload for updating a cron job.

    Class

    CronsSearch

    Payload for searching cron jobs.

    Class

    StoreGet

    Operation to retrieve a specific item by its namespace and key.

    Class

    StoreSearch

    Operation to search for items within a specified namespace hierarchy.

    Class

    StoreListNamespaces

    Operation to list and filter namespaces in the store.

    Class

    StorePut

    Operation to store, update, or delete an item in the store.

    Class

    StoreDelete

    Operation to delete an item from the store.

    Class

    on

    Namespace for type definitions of different API operations.

    Class

    threads

    Types for thread-related operations.

    Class

    create

    Type for thread creation parameters.

    Class

    create_run

    Type for creating or streaming a run.

    Class

    read

    Type for thread read parameters.

    Class

    update

    Type for thread update parameters.

    Class

    delete

    Type for thread deletion parameters.

    Class

    search

    Type for thread search parameters.

    Class

    assistants

    Types for assistant-related operations.

    Class

    create

    Type for assistant creation parameters.

    Class

    read

    Type for assistant read parameters.

    Class

    update

    Type for assistant update parameters.

    Class

    delete

    Type for assistant deletion parameters.

    Class

    search

    Type for assistant search parameters.

    Class

    crons

    Types for cron-related operations.

    Class

    create

    Type for cron creation parameters.

    Class

    read

    Type for cron read parameters.

    Class

    update

    Type for cron update parameters.

    Class

    delete

    Type for cron deletion parameters.

    Class

    search

    Type for cron search parameters.

    Class

    store

    Types for store-related operations.

    Class

    put

    Type for store put parameters.

    Class

    get

    Type for store get parameters.

    Class

    search

    Type for store search parameters.

    Class

    delete

    Type for store delete parameters.

    Class

    list_namespaces

    Type for store list namespaces parameters.

    Functions

    Function

    aiter_lines_raw

    Function

    iter_lines_raw

    Function

    cache_get

    Get a value from the cache.

    Function

    cache_set

    Set a value in the cache.

    Function

    swr

    Load a cached value using stale-while-revalidate semantics.

    Function

    normalize_segment

    Strip the dynamic suffix after : from a namespace segment.

    Function

    is_prefix_match

    Whether event_namespace starts with prefix.

    Function

    namespace_matches

    Whether event_namespace matches any of prefixes within depth.

    Function

    infer_channel

    Map a protocol event's method to its subscription channel.

    Function

    matches_subscription

    Whether event should be delivered for definition.

    Function

    compute_union_filter

    Aggregate a set of subscription filters into one covering filter.

    Function

    filter_covers

    Whether coverer is a superset of target.

    Function

    validate_interleave_channels

    Reject reserved protocol channel names before they hit the fallback.

    Function

    build_event_stream_body

    Function

    build_websocket_url

    Convert an HTTP base URL plus API path into a WebSocket URL.

    Function

    websocket_headers

    Function

    get_sync_client

    Get a synchronous LangGraphClient instance.

    Function

    get_client

    Create and configure a LangGraphClient.

    Function

    configure_loopback_transports

    Function

    get_asgi_transport

    Function

    is_studio_user

    Modules

    Module

    langgraph_sdk

    Module

    schema

    Data models for interacting with the LangGraph API.

    Module

    client

    The LangGraph client implementations connect to the LangGraph API.

    Module

    sse

    Adapted from httpx_sse to split lines on

    Module

    runtime

    Module

    errors

    Module

    cache

    Key/value cache for use inside LangGraph deployments.

    Module

    stream

    Stream module for LangGraph SDK v3.

    Module

    subscription

    Subscription matching: channel inference + namespace prefix filtering.

    Module

    controller

    Stream controller: subscription registry and fan-out for AsyncThreadStream.

    Module

    multi_cursor_buffer

    Unbounded async-iterable append-only log with per-iterator cursors.

    Module

    sync_controller

    Synchronous shared-stream fan-out controller for v3 thread streaming.

    Module

    decoders

    Per-channel event → items state machines.

    Module

    transport

    Public exports for the v3 streaming transport layer.

    Module

    sync_http

    Synchronous HTTP/SSE transport for the v3 thread-centric protocol.

    Module

    ws

    Async WebSocket transport for the v3 thread-centric protocol.

    Module

    http

    HTTP/SSE transport for the v3 thread-centric protocol.

    Module

    sync_ws

    Sync WebSocket transport for the v3 thread-centric protocol.

    Module

    base

    Shared transport contracts for v3 thread-centric streaming.

    Module

    client

    Sync LangGraph client.

    Module

    threads

    Synchronous client for managing threads in LangGraph.

    Module

    http

    Synchronous HTTP client for LangGraph API.

    Module

    runs

    Synchronous client for managing runs in LangGraph.

    Module

    store

    Synchronous store client for LangGraph SDK.

    Module

    cron

    Synchronous cron client for LangGraph SDK.

    Module

    assistants

    Synchronous client for managing assistants in LangGraph.

    Module

    stream

    Synchronous thread-centric streaming surface for the v3 protocol.

    Module

    encryption

    Custom encryption support for LangGraph.

    Module

    types

    Encryption and decryption types for LangGraph.

    Module

    client

    Async LangGraph client.

    Module

    threads

    Async client for managing threads in LangGraph.

    Module

    http

    HTTP client for async operations.

    Module

    runs

    Async client for managing runs in LangGraph.

    Module

    store

    Async Store client for LangGraph SDK.

    Module

    cron

    Async client for managing recurrent runs (cron jobs) in LangGraph.

    Module

    assistants

    Async client for managing assistants in LangGraph.

    Module

    stream

    Async thread-centric streaming surface for the v3 protocol.

    Module

    utilities

    Shared utility functions for async and sync clients.

    Module

    types

    Type aliases and constants.

    Module

    auth

    Module

    exceptions

    Exceptions used in the auth system.

    Module

    types

    Authentication and authorization types for LangGraph.

    Types

    Type

    Json

    Represents a JSON-like structure, which can be None or a dictionary with string keys and any values.

    Type

    PrimitiveData

    Type

    QueryParamTypes

    Type

    DebugPayload

    Wrapper payload for debug events. Discriminate on type.

    Type

    StreamPartV2

    Discriminated union of all v2 stream part types.

    Type

    Input

    Type

    Context

    Type

    BytesLike

    Type

    TimeoutTypes

    Type

    FilterType

    Response type for authorization handlers.

    Type

    HandlerResult

    The result of a handler can be: