Home / File/ module_import.py — langchain Source File

module_import.py — langchain Source File

Architecture documentation for module_import.py, a python file in the langchain codebase. 5 imports, 0 dependents.

File python CoreAbstractions Serialization 5 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  f2577f80_a1dd_151c_7f15_b2441d25b10c["module_import.py"]
  3888b2bf_bffe_7c16_770f_a406d400119c["importlib"]
  f2577f80_a1dd_151c_7f15_b2441d25b10c --> 3888b2bf_bffe_7c16_770f_a406d400119c
  cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7["collections.abc"]
  f2577f80_a1dd_151c_7f15_b2441d25b10c --> cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  f2577f80_a1dd_151c_7f15_b2441d25b10c --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  b19a8b7e_fbee_95b1_65b8_509a1ed3cad7["langchain_core._api"]
  f2577f80_a1dd_151c_7f15_b2441d25b10c --> b19a8b7e_fbee_95b1_65b8_509a1ed3cad7
  38f8ae75_22d8_c191_ce06_b3bf6df6902f["langchain_classic._api.interactive_env"]
  f2577f80_a1dd_151c_7f15_b2441d25b10c --> 38f8ae75_22d8_c191_ce06_b3bf6df6902f
  style f2577f80_a1dd_151c_7f15_b2441d25b10c fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import importlib
from collections.abc import Callable
from typing import Any

from langchain_core._api import internal, warn_deprecated

from langchain_classic._api.interactive_env import is_interactive_env

ALLOWED_TOP_LEVEL_PKGS = {
    "langchain_community",
    "langchain_core",
    "langchain_classic",
}


def create_importer(
    package: str,
    *,
    module_lookup: dict[str, str] | None = None,
    deprecated_lookups: dict[str, str] | None = None,
    fallback_module: str | None = None,
) -> Callable[[str], Any]:
    """Create a function that helps retrieve objects from their new locations.

    The goal of this function is to help users transition from deprecated
    imports to new imports.

    The function will raise deprecation warning on loops using
    `deprecated_lookups` or `fallback_module`.

    Module lookups will import without deprecation warnings (used to speed
    up imports from large namespaces like llms or chat models).

    This function should ideally only be used with deprecated imports not with
    existing imports that are valid, as in addition to raising deprecation warnings
    the dynamic imports can create other issues for developers (e.g.,
    loss of type information, IDE support for going to definition etc).

    Args:
        package: Current package. Use `__package__`
        module_lookup: Maps name of object to the module where it is defined.
            e.g.,
            ```json
            {
                "MyDocumentLoader": (
                    "langchain_community.document_loaders.my_document_loader"
                )
            }
            ```
        deprecated_lookups: Same as module look up, but will raise
            deprecation warnings.
        fallback_module: Module to import from if the object is not found in
            `module_lookup` or if `module_lookup` is not provided.

    Returns:
        A function that imports objects from the specified modules.
    """
    all_module_lookup = {**(deprecated_lookups or {}), **(module_lookup or {})}

    def import_by_name(name: str) -> Any:
// ... (97 more lines)

Subdomains

Functions

Dependencies

  • collections.abc
  • importlib
  • langchain_classic._api.interactive_env
  • langchain_core._api
  • typing

Frequently Asked Questions

What does module_import.py do?
module_import.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, Serialization subdomain.
What functions are defined in module_import.py?
module_import.py defines 1 function(s): create_importer.
What does module_import.py depend on?
module_import.py imports 5 module(s): collections.abc, importlib, langchain_classic._api.interactive_env, langchain_core._api, typing.
Where is module_import.py in the architecture?
module_import.py is located at libs/langchain/langchain_classic/_api/module_import.py (domain: CoreAbstractions, subdomain: Serialization, directory: libs/langchain/langchain_classic/_api).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free