CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-langchain-cli

CLI for interacting with LangChain templates and applications

Pending
Overview
Eval results
Files

integration-development.mddocs/

Integration Development

Create LangChain integration packages with automated scaffolding, template processing, and documentation generation for various component types. This namespace provides tools for building LangChain integrations with external services and libraries.

Capabilities

Create New Integration

Creates a new integration package with standardized structure, template processing, and development dependencies.

langchain integration new [options]

Options:
  --name TEXT          The name of the integration to create (required, prompt if not provided)
  --name-class TEXT    The PascalCase name for classes (e.g. MyIntegration)
  --src TEXT          Template file to copy (can be repeated)
  --dst TEXT          Destination path for template file (can be repeated)

Usage Examples:

# Create full integration package interactively
langchain integration new --name my-integration

# Create with specific class name
langchain integration new --name my-integration --name-class MyCustomIntegration

# Copy specific template files
langchain integration new --name my-integration --src chat_models.py --dst my_integration/chat_models.py

# Copy multiple template files
langchain integration new --name my-integration \
  --src chat_models.py --dst my_integration/chat.py \
  --src embeddings.py --dst my_integration/embeddings.py

Name Processing:

Integration names are automatically processed:

  • Input: my-custom-integration
  • Package name: langchain-my-custom-integration
  • Module name: langchain_my_custom_integration
  • Class prefix: MyCustomIntegration

Create Integration Documentation

Generate integration documentation using pre-built templates for different component types.

langchain integration create-doc [options]

Options:
  --name TEXT           Kebab-case integration name (required, prompt if not provided)
  --name-class TEXT     PascalCase integration name
  --component-type TEXT Component type (default: ChatModel)
  --destination-dir TEXT Relative path to docs directory (required, prompt if not provided)

Supported Component Types:

  • ChatModel: Chat model implementations
  • DocumentLoader: Document loading utilities
  • Tool: LangChain tools
  • VectorStore: Vector storage implementations
  • Embeddings: Text embedding models
  • ByteStore: Key-value storage
  • LLM: Language model implementations
  • Provider: Service provider integrations
  • Toolkit: Tool collections
  • Retriever: Document retrieval systems

Usage Examples:

# Create chat model documentation
langchain integration create-doc --name openai --component-type ChatModel --destination-dir docs/docs/integrations/chat/

# Create vector store documentation
langchain integration create-doc --name pinecone --component-type VectorStore --destination-dir docs/docs/integrations/vectorstores/

# Create documentation with custom class name
langchain integration create-doc --name vertex-ai --name-class VertexAI --component-type ChatModel --destination-dir docs/docs/integrations/chat/

Programmatic API

Integration Namespace Functions

def new(
    name: str,
    name_class: Optional[str] = None,
    src: Optional[list[str]] = None,
    dst: Optional[list[str]] = None,
) -> None:
    """Create a new integration package."""

def create_doc(
    name: str,
    name_class: Optional[str] = None,
    component_type: str = "ChatModel",
    destination_dir: str = "docs/docs/integrations/chat/",
) -> None:
    """Create a new integration doc."""

def _process_name(name: str, *, community: bool = False) -> Replacements:
    """
    Process integration name into various template replacement formats.
    
    Args:
        name: Raw integration name  
        community: Whether this is a community integration
        
    Returns:
        Replacements dictionary with processed name variants
        
    Raises:
        ValueError: If name doesn't match required pattern
    """

Type Definitions

class Replacements(TypedDict):
    """Template replacement mappings."""
    __package_name__: str
    __module_name__: str
    __ModuleName__: str
    __MODULE_NAME__: str
    __package_name_short__: str
    __package_name_short_snake__: str

TEMPLATE_MAP: dict[str, str] = {
    "ChatModel": "chat.ipynb",
    "DocumentLoader": "document_loaders.ipynb", 
    "Tool": "tools.ipynb",
    "VectorStore": "vectorstores.ipynb",
    "Embeddings": "text_embedding.ipynb",
    "ByteStore": "kv_store.ipynb",
    "LLM": "llms.ipynb",
    "Provider": "provider.ipynb",
    "Toolkit": "toolkits.ipynb",
    "Retriever": "retrievers.ipynb",
}

Integration Package Structure

Full integration packages have the following structure:

langchain-my-integration/
├── pyproject.toml                    # Package configuration
├── README.md                         # Package documentation
├── langchain_my_integration/         # Main package
│   ├── __init__.py                  # Package exports
│   ├── chat_models.py               # Chat model implementations
│   ├── embeddings.py                # Embedding implementations
│   ├── vectorstores.py              # Vector store implementations
│   └── ...                          # Other component types
├── tests/                           # Test suite
│   ├── integration_tests/           # Integration tests
│   └── unit_tests/                  # Unit tests
└── docs/                            # Documentation

Template Processing

Available Templates

The integration template system includes:

  • Chat Models: chat_models.py - Chat completion interfaces
  • Embeddings: embeddings.py - Text embedding models
  • Vector Stores: vectorstores.py - Vector database integrations
  • Document Loaders: document_loaders.py - Document ingestion
  • Tools: tools.py - LangChain tool implementations
  • Toolkits: toolkits.py - Tool collections
  • Retrievers: retrievers.py - Document retrieval systems

Template Variables

Templates use these replacement variables:

  • __package_name__: Full package name (e.g., langchain-my-integration)
  • __module_name__: Python module name (e.g., langchain_my_integration)
  • __ModuleName__: PascalCase class prefix (e.g., MyIntegration)
  • __MODULE_NAME__: Uppercase constant prefix (e.g., MY_INTEGRATION)
  • __package_name_short__: Short name (e.g., my-integration)
  • __package_name_short_snake__: Snake case short name (e.g., my_integration)

File Processing

Template processing includes:

  1. Directory Structure: Complete package scaffolding
  2. File Copying: Template files with variable replacement
  3. Dependency Installation: Poetry setup with dev dependencies
  4. Configuration: Pre-configured linting, typing, and testing

Development Dependencies

Integration packages include comprehensive development tooling:

[dependency-groups]
dev = ["pytest", "pytest-watcher"]
lint = ["ruff", "mypy"] 
test = ["langchain-core", "langchain"]
typing = ["langchain"]
test_integration = []

Validation and Quality

Name Validation

Integration names must follow strict patterns:

  • Start with lowercase letter
  • Contain only lowercase letters, numbers, and hyphens
  • No consecutive hyphens
  • No trailing hyphens
  • Automatic langchain- prefix handling

Class Name Validation

Class names must follow Python conventions:

  • Start with uppercase letter
  • Contain only letters and numbers
  • Used for generating component class names

Template Validation

The system validates:

  • Template file existence
  • Destination path uniqueness
  • Variable replacement completeness
  • Package structure integrity

Integration Best Practices

Component Implementation

Follow LangChain patterns for each component type:

from langchain_core.chat_models import BaseChatModel

class MyIntegrationChatModel(BaseChatModel):
    """Chat model implementation."""
    # Implementation details

Configuration Management

Use Pydantic for configuration:

from pydantic import BaseModel, Field

class MyIntegrationConfig(BaseModel):
    api_key: str = Field(..., description="API key for service")
    base_url: str = Field(default="https://api.example.com")

Error Handling

Implement comprehensive error handling:

from langchain_core.exceptions import LangChainException

class MyIntegrationError(LangChainException):
    """Integration-specific errors."""

Testing Strategy

Include both unit and integration tests:

  • Unit Tests: Component logic without external dependencies
  • Integration Tests: Full workflow with real or mocked services
  • Type Tests: MyPy validation for type safety

Install with Tessl CLI

npx tessl i tessl/pypi-langchain-cli

docs

app-management.md

code-migration.md

index.md

integration-development.md

template-development.md

utilities.md

tile.json