CLI for interacting with LangChain templates and applications
npx @tessl/cli install tessl/pypi-langchain-cli@0.0.00
# LangChain CLI
1
2
A 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.
3
4
## Package Information
5
6
- **Package Name**: langchain-cli
7
- **Package Type**: pypi
8
- **Language**: Python
9
- **Installation**: `pip install langchain-cli`
10
11
## Core Imports
12
13
Import the CLI programmatically (though primarily used as CLI tool):
14
15
```python
16
from langchain_cli.cli import app
17
from langchain_cli import __version__
18
```
19
20
## Basic Usage
21
22
### Command Line Interface
23
24
The primary interface is through command-line commands:
25
26
```bash
27
# Create a new LangServe application
28
langchain app new my-app
29
30
# Add a template to your app
31
langchain app add my-template
32
33
# Serve your application locally
34
langchain app serve --port 8000 --host 0.0.0.0
35
36
# Create a new template package
37
langchain template new my-template
38
39
# Create integration packages
40
langchain integration new my-integration
41
42
# Migrate LangChain code to newer versions
43
langchain migrate --diff
44
45
# Serve application (auto-detects template vs app)
46
langchain serve --port 8000 --host 0.0.0.0
47
```
48
49
### Programmatic Usage
50
51
While primarily a CLI tool, some components can be used programmatically:
52
53
```python
54
from langchain_cli.utils.packages import get_package_root, get_langserve_export
55
from langchain_cli.utils.git import parse_dependencies
56
from langchain_cli import __version__
57
58
# Get version information
59
print(__version__)
60
61
# Find package root directory
62
project_root = get_package_root()
63
64
# Parse dependency specifications
65
deps = parse_dependencies(["template-name"], [], [], [])
66
```
67
68
## Architecture
69
70
The CLI is built using Typer and organized into functional namespaces:
71
72
- **Main CLI**: Entry point with global commands and namespace routing
73
- **App Namespace**: LangServe application lifecycle management
74
- **Template Namespace**: Template development and serving
75
- **Integration Namespace**: LangChain integration package creation
76
- **Migration Namespace**: Code migration utilities using Grit
77
- **Utilities**: Shared functionality for git operations, package management, and file processing
78
79
## Capabilities
80
81
### Application Management
82
83
Create, manage, and serve LangServe applications with template integration, dependency management, and local development server functionality.
84
85
```python { .api }
86
# CLI Commands (app namespace)
87
# langchain app new [name] [options]
88
# langchain app add [dependencies] [options]
89
# langchain app remove [api_paths] [options]
90
# langchain app serve [options]
91
```
92
93
[Application Management](./app-management.md)
94
95
### Template Development
96
97
Create and develop installable LangChain template packages with scaffolding, development server, and template discovery capabilities.
98
99
```python { .api }
100
# CLI Commands (template namespace)
101
# langchain template new [name] [options]
102
# langchain template serve [options]
103
# langchain template list [contains]
104
```
105
106
[Template Development](./template-development.md)
107
108
### Integration Development
109
110
Create LangChain integration packages with automated scaffolding, template processing, and documentation generation for various component types.
111
112
```python { .api }
113
# CLI Commands (integration namespace)
114
# langchain integration new [options]
115
# langchain integration create-doc [options]
116
```
117
118
[Integration Development](./integration-development.md)
119
120
### Code Migration
121
122
Migrate LangChain code to newer versions using Grit pattern matching with interactive and diff modes for safe code transformation.
123
124
```python { .api }
125
# CLI Commands (migrate)
126
# langchain migrate [grit-args] [options]
127
```
128
129
[Code Migration](./code-migration.md)
130
131
### Application Serving
132
133
Auto-detect and serve LangServe applications or templates with smart detection of project type and configuration.
134
135
```python { .api }
136
# CLI Commands (root level)
137
# langchain serve [options]
138
```
139
140
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.
141
142
### Utility Functions
143
144
Core utility functions for package management, git operations, project configuration, and event tracking used throughout the CLI.
145
146
```python { .api }
147
def get_package_root(cwd: Optional[Path] = None) -> Path: ...
148
def get_langserve_export(filepath: Path) -> LangServeExport: ...
149
def parse_dependencies(dependencies: Optional[list[str]], repo: list[str], branch: list[str], api_path: list[str]) -> list[DependencySource]: ...
150
def update_repo(gitstring: str, ref: Optional[str], repo_dir: Path) -> Path: ...
151
```
152
153
[Utility Functions](./utilities.md)
154
155
## Types
156
157
```python { .api }
158
class LangServeExport(TypedDict):
159
"""Fields from pyproject.toml relevant to LangServe."""
160
module: str
161
attr: str
162
package_name: str
163
164
class DependencySource(TypedDict):
165
"""Dependency source information."""
166
git: str
167
ref: Optional[str]
168
subdirectory: Optional[str]
169
api_path: Optional[str]
170
event_metadata: dict[str, Any]
171
172
class EventDict(TypedDict):
173
"""Event data structure for analytics tracking."""
174
event: str
175
properties: Optional[dict[str, Any]]
176
```