Skip to main content

Microsoft OneDrive Loader

pip install llama-index-readers-microsoft-onedrive

This loader reads files from:

It supports recursively traversing and downloading files from subfolders and provides capability to download only files with specific mime types. To use this loader, you need to pass in a list of file/folder id or file/folder paths.

Subfolder traversing (enabled by default)

To disable: loader.load_data(recursive = False)

Mime types

You can also filter the files by the mimeType e.g.: mime_types=["application/vnd.openxmlformats-officedocument.wordprocessingml.document"]

Authentication

OneDriveReader supports following two MSAL authentication:

1. User Authentication: Browser based authentication:

  • You need to create a app registration in Microsoft Entra (formerly Azure Active Directory)
  • For interactive authentication to work, a browser is used to authenticate, hence the registered application should have a redirect URI set to 'https://localhost' under mobile and native applications.
  • This mode of authentication is not suitable for CI/CD or other background service scenarios where manual authentication isn't feasible.
  • API Permission required for registered app:

    Microsoft Graph --> Delegated Permission -- > Files.Read.All

2. App Authentication: Client ID & Client Secret based authentication

  • You need to create a app registration in Microsoft Entra (formerly Azure Active Directory)

  • For silent authentication to work, You need to create a client secret as well for the app.

  • This mode of authnetication is not supported by Microsoft currently for OneDrive Personal, hence this can be used only for OneDrive for Business(Microsoft 365).

  • API Permission required for registered app:

    Microsoft Graph --> Application Permissions -- > Files.Read.All (Grant Admin Consent)

    Microsoft Graph --> Application Permissions -- > User.Read.All (Grant Admin Consent)

Usage

OneDrive Personal

https://onedrive.live.com/

Note: If you trying to connect to OneDrive Personal you can initialize OneDriveReader with just your clientid and interactive login. Microsoft _doesn't support App authentication for OneDrive Personal currently.

folder_id

You can extract a folder_id directly from its URL.

For example, the folder_id of https://onedrive.live.com/?id=B5AF52B769DFDE4%216107&cid=0B5AF52B769DFDdRE4 is B5AF52B769DFDE4%216107.

file_id

You can extract a file_id directly from its preview URL.

For example, the file_id of https://onedrive.live.com/?cid=0B5AF52BE769DFDE4&id=B5AF52B769DFDE4%216106&parId=root&o=OneUp is B5AF52B769DFDE4%216106.

OneDrive Personal Example Usage:

from llama_index.readers.microsoft_onedrive import OneDriveReader

# User Authentication flow: Replace client id with your own id
loader = OneDriveReader(client_id="82ee706e-2439-47fa-877a-95048ead9318")

# APP Authentication flow: NOT SUPPORTED By Microsoft

#### Get all documents including subfolders.
documents = loader.load_data()

#### Get documents using folder_id , to exclude traversing subfolders explicitly set the recursive flag to False, default is True
documents = loader.load_data(folder_id="folderid", recursive=False)

#### Using file ids
documents = loader.load_data(file_ids=["fileid1", "fileid2"])

OneDrive For Business

https://portal.office.com/onedrive

Note: If you are an organization trying to connect to OneDrive for Business (Part of Microsoft 365), you need to:

  1. Initialize OneDriveReader with correct tenant_id, along with a client_id and client_Secret registered for the tenant.
  2. Invoke the load_data method with userprincipalname (org provided email in most cases)

folder_path

The relative pathof subfolder from the root folder(Documents).

For example:

  • The path of 1st level subfolder with name "drice co" (within root folder) with URL of https://foobar-my.sharepoint.com/personal/godwin_foobar_onmicrosoft_com/_layouts/15/onedrive.aspx?id=/personal/godwin_foobar_onmicrosoft_com/Documents/drice%20co/test is drice%20co

  • The path of 2nd level subfolder "test" (within drice co subfolder) with URL of https://foobar-my.sharepoint.com/personal/godwin_foobar_onmicrosoft_com/_layouts/15/onedrive.aspx?id=/personal/godwin_foobar_onmicrosoft_com/Documents/drice%20co/test is drice%20co/test

file_path

The relatve path of files from the root folder(Documents).

For example, the path of file "demo_doc.docx" within test subfolder from previous example with url of https://foobar-my.sharepoint.com/personal/godwin_foobar_onmicrosoft_com/_layouts/15/onedrive.aspx?id=/personal/godwin_foobar_onmicrosoft_com/Documents/drice%20co/test/demo_doc.docx is drice%20co/test/demo_doc.docx

OneDrive For Business Example Usage:

from llama_index.readers.microsoft_onedrive import OneDriveReader

loader = OneDriveReader(
    client_id="82ee706e-2439-47fa-877a-95048ead9318",
    tenant_id="02ee706f-2439-47fa-877a-95048ead9318",
    client_secret="YOUR_SECRET",
)

#### Get all docx or pdf documents (subfolders included).
documents = loader.load_data(
    mime_types=[
        "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
        "application/pdf",
    ],
    userprincipalname="godwin@foobar.onmicrosoft.com",
)

#### Get all documents from a folder of mentioned user's onedrive for business
documents = loader.load_data(
    folder_path="subfolder/subfolder2",
    userprincipalname="godwin@foobar.onmicrosoft.com",
)

#### Using file paths and userprincipalname(org provided email) of user
documents = loader.load_data(
    file_ids=[
        "subfolder/subfolder2/fileid1.pdf",
        "subfolder/subfolder3/fileid2.docx",
    ],
    userprincipalname="godwin@foobar.onmicrosoft.com",
)

Author

Godwin Paul Vincent

This loader is designed to be used as a way to load data into LlamaIndex.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llama_index_readers_microsoft_onedrive-0.5.0.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file llama_index_readers_microsoft_onedrive-0.5.0.tar.gz.

File metadata

  • Download URL: llama_index_readers_microsoft_onedrive-0.5.0.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for llama_index_readers_microsoft_onedrive-0.5.0.tar.gz
Algorithm Hash digest
SHA256 8a8d22c7001939d766ae11bc07255e47a43453f5dda4b6b6208fc1df2816de31
MD5 3401a435439485ac2d210cd382a7d4e9
BLAKE2b-256 f3fe5a40109a734409225449fe5d15f09cc027ed0e64bd798f4043eabf6854d7

See more details on using hashes here.

File details

Details for the file llama_index_readers_microsoft_onedrive-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: llama_index_readers_microsoft_onedrive-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for llama_index_readers_microsoft_onedrive-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 96454f05d5eb3d48bbe4c2e422b4b44a20622974de6f3841b811249ad9e7019c
MD5 231cfa5bb21046747acb00172e432c06
BLAKE2b-256 bd199098b26a90b3acf0189173a48681c5c98d79a4c942bda57f8267c68f3680

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 files

0.4.1

2 files

0.4.0

2 files

0.3.0

2 files

0.2.3

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.9

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

1 file

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

0.0.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page