Skill

Read SharePoint Files and Site Pages

Load files or Site Pages from a SharePoint folder into LlamaIndex, recursively, via Microsoft Entra ID auth.

Works with microsoft sharepointmicrosoft graphmicrosoft entra id

92
Spark score
out of 100
Updated 15 days ago
Version 0.14.23
Models

Add to Favorites

Why it matters

Access and extract data from your Microsoft SharePoint environment, including files from specified folders and content from site pages, for further processing or analysis.

Outcomes

What it gets done

01

Load files from SharePoint folders recursively.

02

Extract content from SharePoint site pages.

03

Authenticate securely using Microsoft Entra ID.

04

Support for Sites.Selected permission for granular access.

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/li-reader-readers-microsoft-sharepoint | bash

Overview

Microsoft SharePoint Reader

A LlamaIndex reader that loads files or Site Pages from a SharePoint site, recursively through sub-folders, authenticated via a Microsoft Entra ID app registration. Use it to index SharePoint folder files or Site Pages. Requires an Entra ID app with Sites.Read.All or Sites.Selected, Files.Read.All, and BrowserSiteLists.Read.All permissions, admin-consented.

What it does

Microsoft SharePoint Reader loads files from a folder in a SharePoint site, or SharePoint Site Pages themselves, into LlamaIndex documents, with support for recursively traversing sub-folders. It authenticates as an app registered in Microsoft Entra ID (formerly Azure AD), rather than as an individual user.

When to use - and when NOT to

Use this reader when your source documents or pages live in SharePoint and you want to index a folder (recursively or not) or the site's own pages. It requires an Entra ID app registration with specific Microsoft Graph application permissions - Sites.Read.All (access to every site in the tenant) or the narrower Sites.Selected (access only to specific sites you explicitly grant), plus Files.Read.All and BrowserSiteLists.Read.All - all granted admin consent, so it isn't usable without SharePoint admin involvement to set up the app and permissions. If you use Sites.Selected, an admin must additionally grant the app access to each specific SharePoint site through the SharePoint admin center, on top of the Graph permission grant itself.

Inputs and outputs

SharePointReader is created with client_id, client_secret, and tenant_id, then load_data() takes sharepoint_site_name, sharepoint_folder_path, and a recursive flag:

loader = SharePointReader(
    client_id="<Client ID of the app>",
    client_secret="<Client Secret of the app>",
    tenant_id="<Tenant ID of the Microsoft Azure Directory>",
)

documents = loader.load_data(
    sharepoint_site_name="<Sharepoint Site Name>",
    sharepoint_folder_path="<Folder Path>",
    recursive=True,
)

The sharepoint_folder_path argument is relative to the site's root directory - for example, files sitting in a Test folder directly under root are addressed with a file_path of just "Test". If your app only has Sites.Selected access, pass sharepoint_host_name and sharepoint_relative_url instead of a site name. Setting sharepoint_type=SharePointType.PAGE switches the reader to load Site Pages instead of files - either all pages, or one specific page by setting loader.sharepoint_file_id to a page ID.

Integrations

Pages can be filtered with a process_document_callback function that returns True or False per page name, for example to skip pages whose name starts with "Draft" rather than indexing every page unconditionally. Install with pip install llama-index-readers-microsoft-sharepoint, and see Microsoft's own Graph permissions reference for the full detail behind each required permission and how to register the app in the first place.

Who it's for

Teams building LlamaIndex search or Q&A over SharePoint content - documents in a site folder, or the site's own pages - who are able to get SharePoint admin sign-off on the required Entra ID app permissions.

Source README

Microsoft SharePoint Reader

pip install llama-index-readers-microsoft-sharepoint

The loader loads the files from a folder in SharePoint site or SharePoint Site Pages.

It also supports traversing recursively through the sub-folders.

Prerequisites

App Authentication using Microsoft Entra ID (formerly Azure AD)

  1. You need to create an App Registration in Microsoft Entra ID. Refer here
  2. API Permissions for the created app:
    • Microsoft Graph → Application Permissions → Sites.Read.All (Grant Admin Consent)
      (Allows access to all sites in the tenant)
    • OR
      Microsoft Graph → Application Permissions → Sites.Selected (Grant Admin Consent)
      (Allows access only to specific sites you select and grant permissions for)
    • Microsoft Graph → Application Permissions → Files.Read.All (Grant Admin Consent)
    • Microsoft Graph → Application Permissions → BrowserSiteLists.Read.All (Grant Admin Consent)

Note:
If you use Sites.Selected, you must grant your app access to the specific SharePoint site(s) via the SharePoint admin center.
See Grant access to a specific site for details.

More info on Microsoft Graph APIs - Refer here

Usage

To use this loader client_id, client_secret and tenant_id of the registered app in Microsoft Azure Portal is required.

Loading Files from SharePoint Drive

This loader loads the files present in a specific folder in SharePoint.

If the files are present in the Test folder in SharePoint Site under root directory, then the input for the loader for file_path is Test

from llama_index.readers.microsoft_sharepoint import SharePointReader

loader = SharePointReader(
    client_id="<Client ID of the app>",
    client_secret="<Client Secret of the app>",
    tenant_id="<Tenant ID of the Microsoft Azure Directory>",
)

documents = loader.load_data(
    sharepoint_site_name="<Sharepoint Site Name>",
    sharepoint_folder_path="<Folder Path>",
    recursive=True,
)

Using Sites.Selected Permission

If you have only been granted access to a specific site (using Sites.Selected), you can use the site host name and relative URL instead of the site name:

from llama_index.readers.microsoft_sharepoint import SharePointReader

loader = SharePointReader(
    client_id="<Client ID of the app>",
    client_secret="<Client Secret of the app>",
    tenant_id="<Tenant ID of the Microsoft Azure Directory>",
    sharepoint_host_name="contoso.sharepoint.com",
    sharepoint_relative_url="sites/YourSiteName",
)

documents = loader.load_data(
    sharepoint_folder_path="<Folder Path>",
    recursive=True,
)

Loading SharePoint Site Pages

You can also load SharePoint Site Pages as documents by setting sharepoint_type to PAGE:

from llama_index.readers.microsoft_sharepoint import (
    SharePointReader,
    SharePointType,
)

loader = SharePointReader(
    client_id="<Client ID of the app>",
    client_secret="<Client Secret of the app>",
    tenant_id="<Tenant ID of the Microsoft Azure Directory>",
    sharepoint_site_name="<Sharepoint Site Name>",
    sharepoint_host_name="<your-tenant>.sharepoint.com",
    sharepoint_relative_url="/sites/<YourSite>",
    sharepoint_type=SharePointType.PAGE,
)

### Load all pages
documents = loader.load_data()

### Or load a specific page by ID
loader.sharepoint_file_id = "<page_id>"
documents = loader.load_data()

Filtering Pages with Callbacks

You can filter which pages to process using the process_document_callback:

def page_filter(page_name: str) -> bool:
    # Only process pages that don't start with "Draft"
    return not

FAQ

Common questions

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.