Home / File/ hub.py — langchain Source File

hub.py — langchain Source File

Architecture documentation for hub.py, a python file in the langchain codebase. 8 imports, 0 dependents.

File python CoreAbstractions Serialization 8 imports 3 functions

Entity Profile

Dependency Diagram

graph LR
  cd6f9d54_0eea_9f32_8ed0_3fc87054a5e8["hub.py"]
  7025b240_fdc3_cf68_b72f_f41dac94566b["json"]
  cd6f9d54_0eea_9f32_8ed0_3fc87054a5e8 --> 7025b240_fdc3_cf68_b72f_f41dac94566b
  cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7["collections.abc"]
  cd6f9d54_0eea_9f32_8ed0_3fc87054a5e8 --> cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  cd6f9d54_0eea_9f32_8ed0_3fc87054a5e8 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  f10c7807_dbfb_545d_042b_5250f9fd7d51["langchain_core.load.dump"]
  cd6f9d54_0eea_9f32_8ed0_3fc87054a5e8 --> f10c7807_dbfb_545d_042b_5250f9fd7d51
  553b7d61_3a8f_8bb0_a4d7_a5aed262f254["langchain_core.load.load"]
  cd6f9d54_0eea_9f32_8ed0_3fc87054a5e8 --> 553b7d61_3a8f_8bb0_a4d7_a5aed262f254
  e6b4f61e_7b98_6666_3641_26b069517d4a["langchain_core.prompts"]
  cd6f9d54_0eea_9f32_8ed0_3fc87054a5e8 --> e6b4f61e_7b98_6666_3641_26b069517d4a
  023156c8_e306_6129_d953_9f1dac71e6fd["langsmith"]
  cd6f9d54_0eea_9f32_8ed0_3fc87054a5e8 --> 023156c8_e306_6129_d953_9f1dac71e6fd
  c570f8f0_3075_8201_f48d_7cce7aaa0160["langchainhub"]
  cd6f9d54_0eea_9f32_8ed0_3fc87054a5e8 --> c570f8f0_3075_8201_f48d_7cce7aaa0160
  style cd6f9d54_0eea_9f32_8ed0_3fc87054a5e8 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Interface with the [LangChain Hub](https://smith.langchain.com/hub)."""

from __future__ import annotations

import json
from collections.abc import Sequence
from typing import Any, Literal

from langchain_core.load.dump import dumps
from langchain_core.load.load import loads
from langchain_core.prompts import BasePromptTemplate


def _get_client(
    api_key: str | None = None,
    api_url: str | None = None,
) -> Any:
    """Get a client for interacting with the LangChain Hub.

    Attempts to use LangSmith client if available, otherwise falls back to
    the legacy `langchainhub` client.

    Args:
        api_key: API key to authenticate with the LangChain Hub API.
        api_url: URL of the LangChain Hub API.

    Returns:
        Client instance for interacting with the hub.

    Raises:
        ImportError: If neither `langsmith` nor `langchainhub` can be imported.
    """
    try:
        from langsmith import Client as LangSmithClient

        ls_client = LangSmithClient(api_url, api_key=api_key)
        if hasattr(ls_client, "push_prompt") and hasattr(ls_client, "pull_prompt"):
            return ls_client
        from langchainhub import Client as LangChainHubClient

        return LangChainHubClient(api_url, api_key=api_key)
    except ImportError:
        try:
            from langchainhub import Client as LangChainHubClient

            return LangChainHubClient(api_url, api_key=api_key)
        except ImportError as e:
            msg = (
                "Could not import langsmith or langchainhub (deprecated),"
                "please install with `pip install langsmith`."
            )
            raise ImportError(msg) from e


def push(
    repo_full_name: str,
    object: Any,  # noqa: A002
    *,
    api_url: str | None = None,
    api_key: str | None = None,
// ... (95 more lines)

Subdomains

Dependencies

  • collections.abc
  • json
  • langchain_core.load.dump
  • langchain_core.load.load
  • langchain_core.prompts
  • langchainhub
  • langsmith
  • typing

Frequently Asked Questions

What does hub.py do?
hub.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, Serialization subdomain.
What functions are defined in hub.py?
hub.py defines 3 function(s): _get_client, pull, push.
What does hub.py depend on?
hub.py imports 8 module(s): collections.abc, json, langchain_core.load.dump, langchain_core.load.load, langchain_core.prompts, langchainhub, langsmith, typing.
Where is hub.py in the architecture?
hub.py is located at libs/langchain/langchain_classic/hub.py (domain: CoreAbstractions, subdomain: Serialization, directory: libs/langchain/langchain_classic).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free