Overview
The hub module provides push and pull functions for sharing and retrieving LangChain objects (primarily prompts) to and from the LangChain Hub.
Description
This module contains two primary public functions, push and pull, along with a private helper _get_client. These functions interface with the LangChain Hub (hosted at smith.langchain.com) to enable users to share and retrieve serialized LangChain objects. The module supports both the modern langsmith client and the legacy langchainhub client for backward compatibility.
Usage
Import push to upload a LangChain object (such as a prompt template) to the Hub, or import pull to download an existing prompt from the Hub. Requires either the langsmith or langchainhub package to be installed.
Code Reference
Source Location
Signature
def push(
repo_full_name: str,
object: Any,
*,
api_url: str | None = None,
api_key: str | None = None,
parent_commit_hash: str | None = None,
new_repo_is_public: bool = False,
new_repo_description: str | None = None,
readme: str | None = None,
tags: Sequence[str] | None = None,
) -> str: ...
def pull(
owner_repo_commit: str,
*,
include_model: bool | None = None,
api_url: str | None = None,
api_key: str | None = None,
) -> Any: ...
Import
from langchain_classic.hub import push, pull
I/O Contract
Inputs (push)
| Name |
Type |
Required |
Description
|
| repo_full_name |
str |
Yes |
Full name of the prompt in the format owner/prompt_name or prompt_name.
|
| object |
Any |
Yes |
The LangChain object to serialize and push to the Hub.
|
| api_url |
None |
No |
URL of the LangChain Hub API.
|
| api_key |
None |
No |
API key for authentication.
|
| parent_commit_hash |
None |
No |
Commit hash of the parent commit to push to.
|
| new_repo_is_public |
bool |
No |
Whether the prompt should be public.
|
| new_repo_description |
None |
No |
Description of the prompt.
|
| readme |
None |
No |
README content for the repository.
|
| tags |
None |
No |
Tags to associate with the prompt.
|
Inputs (pull)
| Name |
Type |
Required |
Description
|
| owner_repo_commit |
str |
Yes |
Full name in the format owner/prompt_name:commit_hash or owner/prompt_name.
|
| include_model |
None |
No |
Whether to include the model configuration in the pulled prompt.
|
| api_url |
None |
No |
URL of the LangChain Hub API.
|
| api_key |
None |
No |
API key for authentication.
|
Outputs
| Name |
Type |
Description
|
| push return |
str |
URL where the pushed object can be viewed in a browser.
|
| pull return |
Any |
The deserialized LangChain object (typically a BasePromptTemplate).
|
Usage Examples
Basic Usage
from langchain_classic.hub import push, pull
from langchain_core.prompts import ChatPromptTemplate
# Pull a prompt from the hub
prompt = pull("rlm/rag-prompt")
# Push a prompt to the hub
my_prompt = ChatPromptTemplate.from_template("Tell me about {topic}")
url = push("my-org/my-prompt", my_prompt, new_repo_is_public=True)
print(url)
Related Pages
Page Connections
Double-click a node to navigate. Hold to expand connections.