# UnstructuredMarkdownLoader

> **Class** in `langchain_community`

📖 [View in docs](https://reference.langchain.com/python/langchain-community/document_loaders/markdown/UnstructuredMarkdownLoader)

Load `Markdown` files using `Unstructured`.

You can run the loader in one of two modes: "single" and "elements".
If you use "single" mode, the document will be returned as a single
langchain Document object. If you use "elements" mode, the unstructured
library will split the document into elements such as Title and NarrativeText.
You can pass in additional unstructured kwargs after mode to apply
different unstructured settings.

## Signature

```python
UnstructuredMarkdownLoader(
    self,
    file_path: Union[str, Path],
    mode: str = 'single',
    **unstructured_kwargs: Any = {},
)
```

## Description

**Setup:**

Install ``langchain-community``.

.. code-block:: bash

    pip install -U langchain-community

**Instantiate:**

.. code-block:: python

from langchain_community.document_loaders import UnstructuredMarkdownLoader

loader = UnstructuredMarkdownLoader(
    "./example_data/example.md",
    mode="elements",
    strategy="fast",
)

**Lazy load:**

.. code-block:: python

    docs = []
    docs_lazy = loader.lazy_load()

    # async variant:
    # docs_lazy = await loader.alazy_load()

    for doc in docs_lazy:
        docs.append(doc)
    print(docs[0].page_content[:100])
    print(docs[0].metadata)

.. code-block:: python

    Sample Markdown Document
    {'source': './example_data/example.md', 'category_depth': 0, 'last_modified': '2024-08-14T15:04:18', 'languages': ['eng'], 'filetype': 'text/markdown', 'file_directory': './example_data', 'filename': 'example.md', 'category': 'Title', 'element_id': '3d0b313864598e704aa26c728ecb61e5'}

**Async load:**

.. code-block:: python

    docs = await loader.aload()
    print(docs[0].page_content[:100])
    print(docs[0].metadata)

.. code-block:: python

    Sample Markdown Document
    {'source': './example_data/example.md', 'category_depth': 0, 'last_modified': '2024-08-14T15:04:18', 'languages': ['eng'], 'filetype': 'text/markdown', 'file_directory': './example_data', 'filename': 'example.md', 'category': 'Title', 'element_id': '3d0b313864598e704aa26c728ecb61e5'}

References
----------
https://docs.unstructured.io/open-source/core-functionality/partitioning#partition-md

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `file_path` | `Union[str, Path]` | Yes | The path to the Markdown file to load. |
| `mode` | `str` | No | The mode to use when loading the file. Can be one of "single", "multi", or "all". Default is "single". (default: `'single'`) |
| `**unstructured_kwargs` | `Any` | No | Any kwargs to pass to the unstructured. (default: `{}`) |

## Extends

- `UnstructuredFileLoader`

## Constructors

```python
__init__(
    self,
    file_path: Union[str, Path],
    mode: str = 'single',
    **unstructured_kwargs: Any = {},
)
```

| Name | Type |
|------|------|
| `file_path` | `Union[str, Path]` |
| `mode` | `str` |


---

[View source on GitHub](https://github.com/langchain-ai/langchain-community/blob/4b280287bd55b99b44db2dd849f02d66c89534d5/libs/community/langchain_community/document_loaders/markdown.py#L10)