CLI for interacting with LangChain templates and applications
npx @tessl/cli install tessl/pypi-langchain-cli@0.0.0A command-line interface for interacting with LangChain templates and applications. The CLI enables developers to create, manage, and serve LangChain applications through simple commands, supporting template management, project scaffolding, and application deployment in the LangChain ecosystem.
pip install langchain-cliImport the CLI programmatically (though primarily used as CLI tool):
from langchain_cli.cli import app
from langchain_cli import __version__The primary interface is through command-line commands:
# Create a new LangServe application
langchain app new my-app
# Add a template to your app
langchain app add my-template
# Serve your application locally
langchain app serve --port 8000 --host 0.0.0.0
# Create a new template package
langchain template new my-template
# Create integration packages
langchain integration new my-integration
# Migrate LangChain code to newer versions
langchain migrate --diff
# Serve application (auto-detects template vs app)
langchain serve --port 8000 --host 0.0.0.0While primarily a CLI tool, some components can be used programmatically:
from langchain_cli.utils.packages import get_package_root, get_langserve_export
from langchain_cli.utils.git import parse_dependencies
from langchain_cli import __version__
# Get version information
print(__version__)
# Find package root directory
project_root = get_package_root()
# Parse dependency specifications
deps = parse_dependencies(["template-name"], [], [], [])The CLI is built using Typer and organized into functional namespaces:
Create, manage, and serve LangServe applications with template integration, dependency management, and local development server functionality.
# CLI Commands (app namespace)
# langchain app new [name] [options]
# langchain app add [dependencies] [options]
# langchain app remove [api_paths] [options]
# langchain app serve [options]Create and develop installable LangChain template packages with scaffolding, development server, and template discovery capabilities.
# CLI Commands (template namespace)
# langchain template new [name] [options]
# langchain template serve [options]
# langchain template list [contains]Create LangChain integration packages with automated scaffolding, template processing, and documentation generation for various component types.
# CLI Commands (integration namespace)
# langchain integration new [options]
# langchain integration create-doc [options]Migrate LangChain code to newer versions using Grit pattern matching with interactive and diff modes for safe code transformation.
# CLI Commands (migrate)
# langchain migrate [grit-args] [options]Auto-detect and serve LangServe applications or templates with smart detection of project type and configuration.
# CLI Commands (root level)
# langchain serve [options]This root-level serve command automatically detects whether the current directory contains a LangServe application or template and serves accordingly, providing a unified interface for development servers.
Core utility functions for package management, git operations, project configuration, and event tracking used throughout the CLI.
def get_package_root(cwd: Optional[Path] = None) -> Path: ...
def get_langserve_export(filepath: Path) -> LangServeExport: ...
def parse_dependencies(dependencies: Optional[list[str]], repo: list[str], branch: list[str], api_path: list[str]) -> list[DependencySource]: ...
def update_repo(gitstring: str, ref: Optional[str], repo_dir: Path) -> Path: ...class LangServeExport(TypedDict):
"""Fields from pyproject.toml relevant to LangServe."""
module: str
attr: str
package_name: str
class DependencySource(TypedDict):
"""Dependency source information."""
git: str
ref: Optional[str]
subdirectory: Optional[str]
api_path: Optional[str]
event_metadata: dict[str, Any]
class EventDict(TypedDict):
"""Event data structure for analytics tracking."""
event: str
properties: Optional[dict[str, Any]]