SharePoint Integration
Load files and folders from SharePoint document libraries into your Knowledge base.
"""
SharePoint Integration
=======================
Load files and folders from SharePoint document libraries into your Knowledge base.
Features:
- Load single files or entire folders from SharePoint
- Uses Azure AD client credentials with Sites.Read.All permission
Requirements:
- Azure AD App Registration with Sites.Read.All permission
- Client ID, Client Secret, and Tenant ID
Environment Variables:
AZURE_TENANT_ID - Azure AD tenant ID
AZURE_CLIENT_ID - App registration client ID
AZURE_CLIENT_SECRET - App registration client secret
SHAREPOINT_HOSTNAME - SharePoint hostname (e.g. contoso.sharepoint.com)
"""
import asyncio
from os import getenv
from agno.knowledge.knowledge import Knowledge
from agno.knowledge.remote_content import SharePointConfig
from agno.vectordb.qdrant import Qdrant
# ---------------------------------------------------------------------------
# Setup
# ---------------------------------------------------------------------------
sharepoint = SharePointConfig(
id="company-sharepoint",
name="Company SharePoint",
tenant_id=getenv("AZURE_TENANT_ID"),
client_id=getenv("AZURE_CLIENT_ID"),
client_secret=getenv("AZURE_CLIENT_SECRET"),
hostname=getenv("SHAREPOINT_HOSTNAME"),
)
knowledge = Knowledge(
name="SharePoint Knowledge",
vector_db=Qdrant(
collection="sharepoint_knowledge",
url="http://localhost:6333",
),
content_sources=[sharepoint],
)
# ---------------------------------------------------------------------------
# Run Demo
# ---------------------------------------------------------------------------
if __name__ == "__main__":
async def main():
# Single file
print("\n" + "=" * 60)
print("SharePoint: single file")
print("=" * 60 + "\n")
await knowledge.ainsert(
name="Policy Doc",
remote_content=sharepoint.file("Shared Documents/policy.pdf"),
)
# Folder
print("\n" + "=" * 60)
print("SharePoint: folder")
print("=" * 60 + "\n")
await knowledge.ainsert(
name="All Shared Docs",
remote_content=sharepoint.folder("Shared Documents/"),
)
results = knowledge.search("What is the policy?")
for doc in results:
print("- %s" % doc.name)
asyncio.run(main())Grant the app Microsoft Graph application permission Sites.Read.All with administrator consent. Paths are relative to the selected site’s default document library, so Shared Documents/policy.pdf means a folder named Shared Documents inside that library. For a policy file at the library root, change the file argument to policy.pdf; use a real folder for the folder call. Set site_path or site_id on the config when targeting a site other than the hostname’s root site.
Run the Example
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U agno msal openai pypdf qdrant-clientExport environment variables
export AZURE_CLIENT_ID="your_azure_client_id_here"
export AZURE_CLIENT_SECRET="your_azure_client_secret_here"
export AZURE_TENANT_ID="your_azure_tenant_id_here"
export OPENAI_API_KEY="your_openai_api_key_here"
export SHAREPOINT_HOSTNAME="your_sharepoint_hostname_here"Run Qdrant
docker run -d --name qdrant -p 6333:6333 qdrant/qdrant:latestRun the example
Save the code above as sharepoint.py, then run:
python sharepoint.pyFull source: cookbook/07_knowledge/05_integrations/cloud/04_sharepoint.py