SharePlum: Python SharePoint Library

0.5.1 · active · verified Sat Apr 11

shareplum is a Python library designed to simplify interaction with Microsoft SharePoint sites. It provides functionalities for managing files, lists, and users, supporting various SharePoint versions. As of version 0.5.1, the library is actively maintained with a focus on API stability, particularly for file operations.

Warnings

Install

Imports

Quickstart

Demonstrates how to connect to a SharePoint site using environment variables for credentials and retrieve a list of all available lists on the site. Highlights common issues and their troubleshooting.

import os
from shareplum import Site
from shareplum.site import Version

# Use environment variables for sensitive data
SHAREPOINT_URL = os.environ.get('SHAREPOINT_URL', 'https://yourcompany.sharepoint.com/sites/yourteam')
SHAREPOINT_USERNAME = os.environ.get('SHAREPOINT_USERNAME', 'your_username')
SHAREPOINT_PASSWORD = os.environ.get('SHAREPOINT_PASSWORD', 'your_password')

if not all([SHAREPOINT_URL, SHAREPOINT_USERNAME, SHAREPOINT_PASSWORD]):
    print("Error: Please set SHAREPOINT_URL, SHAREPOINT_USERNAME, and SHAREPOINT_PASSWORD environment variables.")
    print("Example: export SHAREPOINT_URL='https://yourcompany.sharepoint.com/sites/yourteam'")
else:
    try:
        # Initialize the Site object with the SharePoint URL, username, password, and version
        # Version.v365 is typically used for SharePoint Online (Office 365)
        # The constructor handles authentication if username/password are provided
        site = Site(SHAREPOINT_URL, username=SHAREPOINT_USERNAME, password=SHAREPOINT_PASSWORD, version=Version.v365)
        
        # Example: Get a list of all lists on the SharePoint site
        all_lists = site.GetListCollection()
        print(f"Successfully connected to SharePoint at {SHAREPOINT_URL}.")
        print(f"Found {len(all_lists)} lists:")
        for sp_list in all_lists:
            print(f"- {sp_list.get('Title')} (ID: {sp_list.get('ID')})")

    except Exception as e:
        print(f"An error occurred while connecting or fetching lists: {e}")
        print("Common issues:")
        print("1. Incorrect SHAREPOINT_URL (ensure it includes the full site collection path, e.g., /sites/yourteam).")
        print("2. Incorrect SHAREPOINT_USERNAME or SHAREPOINT_PASSWORD.")
        print("3. SharePoint site requires ADFS/MFA or other advanced authentication not supported by basic username/password.")
        print("4. Network issues or SharePoint API rate limits.")

view raw JSON →