_import_utils.py — langchain Source File
Architecture documentation for _import_utils.py, a python file in the langchain codebase. 1 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR a635ef7c_881f_22dd_4254_c1034294acf3["_import_utils.py"] 3888b2bf_bffe_7c16_770f_a406d400119c["importlib"] a635ef7c_881f_22dd_4254_c1034294acf3 --> 3888b2bf_bffe_7c16_770f_a406d400119c style a635ef7c_881f_22dd_4254_c1034294acf3 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
from importlib import import_module
def import_attr(
attr_name: str,
module_name: str | None,
package: str | None,
) -> object:
"""Import an attribute from a module located in a package.
This utility function is used in custom `__getattr__` methods within `__init__.py`
files to dynamically import attributes.
Args:
attr_name: The name of the attribute to import.
module_name: The name of the module to import from.
If `None`, the attribute is imported from the package itself.
package: The name of the package where the module is located.
Raises:
ImportError: If the module cannot be found.
AttributeError: If the attribute does not exist in the module or package.
Returns:
The imported attribute.
"""
if module_name == "__module__" or module_name is None:
try:
result = import_module(f".{attr_name}", package=package)
except ModuleNotFoundError:
msg = f"module '{package!r}' has no attribute {attr_name!r}"
raise AttributeError(msg) from None
else:
try:
module = import_module(f".{module_name}", package=package)
except ModuleNotFoundError as err:
msg = f"module '{package!r}.{module_name!r}' not found ({err})"
raise ImportError(msg) from None
result = getattr(module, attr_name)
return result
Domain
Subdomains
Functions
Dependencies
- importlib
Source
Frequently Asked Questions
What does _import_utils.py do?
_import_utils.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 _import_utils.py?
_import_utils.py defines 1 function(s): import_attr.
What does _import_utils.py depend on?
_import_utils.py imports 1 module(s): importlib.
Where is _import_utils.py in the architecture?
_import_utils.py is located at libs/core/langchain_core/_import_utils.py (domain: CoreAbstractions, subdomain: Serialization, directory: libs/core/langchain_core).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free