langchain_community.document_loaders.directory.DirectoryLoaderΒΆ

class langchain_community.document_loaders.directory.DirectoryLoader(path: str, glob: ~typing.Union[~typing.List[str], ~typing.Tuple[str], str] = '**/[!.]*', silent_errors: bool = False, load_hidden: bool = False, loader_cls: ~typing.Union[~typing.Type[~langchain_community.document_loaders.unstructured.UnstructuredFileLoader], ~typing.Type[~langchain_community.document_loaders.text.TextLoader], ~typing.Type[~langchain_community.document_loaders.html_bs.BSHTMLLoader], ~typing.Type[~langchain_community.document_loaders.csv_loader.CSVLoader]] = <class 'langchain_community.document_loaders.unstructured.UnstructuredFileLoader'>, loader_kwargs: ~typing.Optional[dict] = None, recursive: bool = False, show_progress: bool = False, use_multithreading: bool = False, max_concurrency: int = 4, *, exclude: ~typing.Union[~typing.Sequence[str], str] = (), sample_size: int = 0, randomize_sample: bool = False, sample_seed: ~typing.Optional[int] = None)[source]ΒΆ

Load from a directory.

Initialize with a path to directory and how to glob over it.

Parameters
  • path (str) – Path to directory.

  • glob (Union[List[str], Tuple[str], str]) – A glob pattern or list of glob patterns to use to find files. Defaults to β€œ**/[!.]*” (all files except hidden).

  • exclude (Union[Sequence[str], str]) – A pattern or list of patterns to exclude from results. Use glob syntax.

  • silent_errors (bool) – Whether to silently ignore errors. Defaults to False.

  • load_hidden (bool) – Whether to load hidden files. Defaults to False.

  • loader_cls (Union[Type[UnstructuredFileLoader], Type[TextLoader], Type[BSHTMLLoader], Type[CSVLoader]]) – Loader class to use for loading files. Defaults to UnstructuredFileLoader.

  • loader_kwargs (Optional[dict]) – Keyword arguments to pass to loader_cls. Defaults to None.

  • recursive (bool) – Whether to recursively search for files. Defaults to False.

  • show_progress (bool) – Whether to show a progress bar. Defaults to False.

  • use_multithreading (bool) – Whether to use multithreading. Defaults to False.

  • max_concurrency (int) – The maximum number of threads to use. Defaults to 4.

  • sample_size (int) – The maximum number of files you would like to load from the directory.

  • randomize_sample (bool) – Shuffle the files to get a random sample.

  • sample_seed (Optional[int]) – set the seed of the random shuffle for reproducibility.

Examples

Methods

__init__(path[,Β glob,Β silent_errors,Β ...])

Initialize with a path to directory and how to glob over it.

alazy_load()

A lazy loader for Documents.

aload()

Load data into Document objects.

lazy_load()

Load documents lazily.

load()

Load documents.

load_and_split([text_splitter])

Load Documents and split into chunks.

__init__(path: str, glob: ~typing.Union[~typing.List[str], ~typing.Tuple[str], str] = '**/[!.]*', silent_errors: bool = False, load_hidden: bool = False, loader_cls: ~typing.Union[~typing.Type[~langchain_community.document_loaders.unstructured.UnstructuredFileLoader], ~typing.Type[~langchain_community.document_loaders.text.TextLoader], ~typing.Type[~langchain_community.document_loaders.html_bs.BSHTMLLoader], ~typing.Type[~langchain_community.document_loaders.csv_loader.CSVLoader]] = <class 'langchain_community.document_loaders.unstructured.UnstructuredFileLoader'>, loader_kwargs: ~typing.Optional[dict] = None, recursive: bool = False, show_progress: bool = False, use_multithreading: bool = False, max_concurrency: int = 4, *, exclude: ~typing.Union[~typing.Sequence[str], str] = (), sample_size: int = 0, randomize_sample: bool = False, sample_seed: ~typing.Optional[int] = None)[source]ΒΆ

Initialize with a path to directory and how to glob over it.

Parameters
  • path (str) – Path to directory.

  • glob (Union[List[str], Tuple[str], str]) – A glob pattern or list of glob patterns to use to find files. Defaults to β€œ**/[!.]*” (all files except hidden).

  • exclude (Union[Sequence[str], str]) – A pattern or list of patterns to exclude from results. Use glob syntax.

  • silent_errors (bool) – Whether to silently ignore errors. Defaults to False.

  • load_hidden (bool) – Whether to load hidden files. Defaults to False.

  • loader_cls (Union[Type[UnstructuredFileLoader], Type[TextLoader], Type[BSHTMLLoader], Type[CSVLoader]]) – Loader class to use for loading files. Defaults to UnstructuredFileLoader.

  • loader_kwargs (Optional[dict]) – Keyword arguments to pass to loader_cls. Defaults to None.

  • recursive (bool) – Whether to recursively search for files. Defaults to False.

  • show_progress (bool) – Whether to show a progress bar. Defaults to False.

  • use_multithreading (bool) – Whether to use multithreading. Defaults to False.

  • max_concurrency (int) – The maximum number of threads to use. Defaults to 4.

  • sample_size (int) – The maximum number of files you would like to load from the directory.

  • randomize_sample (bool) – Shuffle the files to get a random sample.

  • sample_seed (Optional[int]) – set the seed of the random shuffle for reproducibility.

Examples

async alazy_load() AsyncIterator[Document]ΒΆ

A lazy loader for Documents.

Return type

AsyncIterator[Document]

async aload() List[Document]ΒΆ

Load data into Document objects.

Return type

List[Document]

lazy_load() Iterator[Document][source]ΒΆ

Load documents lazily.

Return type

Iterator[Document]

load() List[Document][source]ΒΆ

Load documents.

Return type

List[Document]

load_and_split(text_splitter: Optional[TextSplitter] = None) List[Document]ΒΆ

Load Documents and split into chunks. Chunks are returned as Documents.

Do not override this method. It should be considered to be deprecated!

Parameters

text_splitter (Optional[TextSplitter]) – TextSplitter instance to use for splitting documents. Defaults to RecursiveCharacterTextSplitter.

Returns

List of Documents.

Return type

List[Document]

Examples using DirectoryLoaderΒΆ