Home / File/ path.py — langchain Source File

path.py — langchain Source File

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

File python LangChainCore ApiManagement 2 imports 2 functions

Entity Profile

Dependency Diagram

graph LR
  4bb957a1_a6a7_9d55_e08d_eca787aa72ef["path.py"]
  0029f612_c503_ebcf_a452_a0fae8c9f2c3["os"]
  4bb957a1_a6a7_9d55_e08d_eca787aa72ef --> 0029f612_c503_ebcf_a452_a0fae8c9f2c3
  927570d8_11a6_5c17_0f0d_80baae0c733e["pathlib"]
  4bb957a1_a6a7_9d55_e08d_eca787aa72ef --> 927570d8_11a6_5c17_0f0d_80baae0c733e
  style 4bb957a1_a6a7_9d55_e08d_eca787aa72ef fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import os
from pathlib import Path

HERE = Path(__file__).parent

# Get directory of langchain package
PACKAGE_DIR = HERE.parent
SEPARATOR = os.sep


def get_relative_path(file: Path | str, *, relative_to: Path = PACKAGE_DIR) -> str:
    """Get the path of the file as a relative path to the package directory.

    Args:
        file: The file path to convert.
        relative_to: The base path to make the file path relative to.

    Returns:
        The relative path as a string.
    """
    if isinstance(file, str):
        file = Path(file)
    return str(file.relative_to(relative_to))


def as_import_path(
    file: Path | str,
    *,
    suffix: str | None = None,
    relative_to: Path = PACKAGE_DIR,
) -> str:
    """Path of the file as a LangChain import exclude langchain top namespace.

    Args:
        file: The file path to convert.
        suffix: An optional suffix to append to the import path.
        relative_to: The base path to make the file path relative to.

    Returns:
        The import path as a string.
    """
    if isinstance(file, str):
        file = Path(file)
    path = get_relative_path(file, relative_to=relative_to)
    if file.is_file():
        path = path[: -len(file.suffix)]
    import_path = path.replace(SEPARATOR, ".")
    if suffix:
        import_path += "." + suffix
    return import_path

Domain

Subdomains

Dependencies

  • os
  • pathlib

Frequently Asked Questions

What does path.py do?
path.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, ApiManagement subdomain.
What functions are defined in path.py?
path.py defines 2 function(s): as_import_path, get_relative_path.
What does path.py depend on?
path.py imports 2 module(s): os, pathlib.
Where is path.py in the architecture?
path.py is located at libs/core/langchain_core/_api/path.py (domain: LangChainCore, subdomain: ApiManagement, directory: libs/core/langchain_core/_api).

Analyze Your Own Codebase

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

Try Supermodel Free