_import_module() — langchain Function Reference
Architecture documentation for the _import_module() function in base.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 9afc100b_d234_fc71_f9a4_299636599405["_import_module()"] 0dc60931_4ce3_cfa4_06b1_e0f8b1869e73["base.py"] 9afc100b_d234_fc71_f9a4_299636599405 -->|defined in| 0dc60931_4ce3_cfa4_06b1_e0f8b1869e73 f789b310_4d83_1f92_6308_7e4a7c84255b["_get_chat_model_creator()"] f789b310_4d83_1f92_6308_7e4a7c84255b -->|calls| 9afc100b_d234_fc71_f9a4_299636599405 style 9afc100b_d234_fc71_f9a4_299636599405 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain_v1/langchain/chat_models/base.py lines 99–123
def _import_module(module: str, class_name: str) -> ModuleType:
"""Import a module by name.
Args:
module: The fully qualified module name to import (e.g., `'langchain_openai'`).
class_name: The name of the class being imported, used for error messages.
Returns:
The imported module.
Raises:
ImportError: If the module cannot be imported, with a message suggesting
the pip package to install.
"""
try:
return importlib.import_module(module)
except ImportError as e:
# Extract package name from module path (e.g., "langchain_azure_ai.chat_models"
# becomes "langchain-azure-ai")
pkg = module.split(".", maxsplit=1)[0].replace("_", "-")
msg = (
f"Initializing {class_name} requires the {pkg} package. Please install it "
f"with `pip install {pkg}`"
)
raise ImportError(msg) from e
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does _import_module() do?
_import_module() is a function in the langchain codebase, defined in libs/langchain_v1/langchain/chat_models/base.py.
Where is _import_module() defined?
_import_module() is defined in libs/langchain_v1/langchain/chat_models/base.py at line 99.
What calls _import_module()?
_import_module() is called by 1 function(s): _get_chat_model_creator.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free