Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Langchain ai Langchain Package Init Exports

From Leeroopedia

Template:Metadata

Overview

Concrete __init__.py pattern for defining the public API surface of a LangChain partner package, provided by the langchain-deepseek package.

Description

The langchain_deepseek/__init__.py file demonstrates the canonical pattern for exporting a LangChain partner package's public API. It is minimal by design, containing only imports, version resolution, and the __all__ declaration.

Structure (17 lines total):

  1. A module docstring identifying the package.
  2. Import metadata from importlib.
  3. Import the public class (ChatDeepSeek) from the internal module.
  4. Resolve __version__ via metadata.version(__package__) with a PackageNotFoundError fallback.
  5. Delete the metadata reference to keep the namespace clean.
  6. Declare __all__ listing every public symbol.

This pattern ensures that:

  • from langchain_deepseek import ChatDeepSeek works correctly.
  • langchain_deepseek.__version__ returns the installed package version.
  • dir(langchain_deepseek) only shows public symbols.

Usage

Use this file as a template when creating the __init__.py for any new LangChain partner integration. The only changes needed are the module docstring, the import path, the class name, and the __all__ entries.

Code Reference

Source Location: libs/partners/deepseek/langchain_deepseek/__init__.py, Lines 1-17

Full source:

"""LangChain DeepSeek integration."""

from importlib import metadata

from langchain_deepseek.chat_models import ChatDeepSeek

try:
    __version__ = metadata.version(__package__)
except metadata.PackageNotFoundError:
    # Case where package metadata is not available.
    __version__ = ""
del metadata  # optional, avoids polluting the results of dir(__package__)

__all__ = [
    "ChatDeepSeek",
    "__version__",
]

Import:

from langchain_deepseek import ChatDeepSeek
from langchain_deepseek import __version__

I/O Contract

Input Type Description
Package installation N/A The package must be installed (via pip/uv) for __version__ to resolve
langchain_deepseek.chat_models module Python module Must export ChatDeepSeek
Output Type Description
ChatDeepSeek type[BaseChatOpenAI] The public chat model class
__version__ str Installed package version (e.g., "1.1.0") or "" if metadata unavailable
__all__ list[str] ["ChatDeepSeek", "__version__"]

Usage Examples

Standard import:

from langchain_deepseek import ChatDeepSeek

model = ChatDeepSeek(model="deepseek-chat")

Checking installed version:

import langchain_deepseek

print(langchain_deepseek.__version__)
# Output: "1.1.0"

Verifying public API surface:

import langchain_deepseek

print(langchain_deepseek.__all__)
# Output: ['ChatDeepSeek', '__version__']

Template for a new package:

"""LangChain MyProvider integration."""

from importlib import metadata

from langchain_myprovider.chat_models import ChatMyProvider

try:
    __version__ = metadata.version(__package__)
except metadata.PackageNotFoundError:
    __version__ = ""
del metadata

__all__ = [
    "ChatMyProvider",
    "__version__",
]

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment