{"id":5720,"library":"sharepy","title":"SharePy - Simple SharePoint Online authentication for Python","description":"SharePy is a Python library designed for simple authentication with SharePoint Online (Office 365) sites, enabling straightforward HTTP requests. It extends the popular Requests library, providing a familiar interface for interacting with SharePoint APIs. The current stable version is 2.0.0, released on February 4, 2022. The library has a slow release cadence, with major updates being infrequent, and there are growing concerns about its compatibility with modern Microsoft 365 authentication flows.","status":"maintenance","version":"2.0.0","language":"en","source_language":"en","source_url":"https://github.com/JonathanHolvey/sharepy","tags":["sharepoint","authentication","office365","requests","microsoft365"],"install":[{"cmd":"pip install sharepy","lang":"bash","label":"Latest stable version"}],"dependencies":[{"reason":"SharePy extends and relies on the Requests library for HTTP operations.","package":"requests","optional":false},{"reason":"Needed for robust SSL certificate verification to avoid common authentication errors.","package":"certifi","optional":false},{"reason":"Requires Python 3.6 or higher, but less than Python 4.","package":"python","optional":false}],"imports":[{"note":"The `sharepy.connect` function is the primary entry point for establishing a SharePoint session.","symbol":"connect","correct":"import sharepy\ns = sharepy.connect(...)"},{"note":"For advanced usage or explicit authentication class instantiation, import directly from `sharepy.auth`.","wrong":"import sharepy.auth.SharePointOnline","symbol":"SharePointOnline","correct":"from sharepy.auth import SharePointOnline"}],"quickstart":{"code":"import os\nimport sharepy\n\nSHAREPOINT_SITE = os.environ.get('SHAREPOINT_SITE', 'example.sharepoint.com')\nSHAREPOINT_USERNAME = os.environ.get('SHAREPOINT_USERNAME', 'user@example.com')\nSHAREPOINT_PASSWORD = os.environ.get('SHAREPOINT_PASSWORD', 'your_password')\n\nif not all([SHAREPOINT_SITE, SHAREPOINT_USERNAME, SHAREPOINT_PASSWORD]):\n    print(\"Please set SHAREPOINT_SITE, SHAREPOINT_USERNAME, and SHAREPOINT_PASSWORD environment variables.\")\n    exit(1)\n\ntry:\n    # Establish a connection to SharePoint Online\n    # Note: For MFA-enabled accounts, username/password might not work reliably.\n    # See warnings for more details.\n    s = sharepy.connect(SHAREPOINT_SITE, username=SHAREPOINT_USERNAME, password=SHAREPOINT_PASSWORD)\n    print(f\"Successfully connected to {SHAREPOINT_SITE}\")\n\n    # Example: Make an API call to get lists from the site\n    response = s.get(f'https://{SHAREPOINT_SITE}/_api/web/lists')\n    response.raise_for_status() # Raise an exception for bad status codes\n\n    print(\"SharePoint Lists:\")\n    for item in response.json()['d']['results']:\n        print(f\"- {item['Title']}\")\n\n    # Example: Download a file (replace with a real URL)\n    # file_url = f'https://{SHAREPOINT_SITE}/Shared Documents/MyDocument.pdf'\n    # s.getfile(file_url, 'downloaded_file.pdf')\n    # print(f\"Downloaded {file_url} to downloaded_file.pdf\")\n\nexcept sharepy.errors.AuthError as e:\n    print(f\"Authentication failed: {e}\")\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n","lang":"python","description":"This quickstart demonstrates how to connect to SharePoint Online using `sharepy.connect()` and make a simple API call to retrieve the site's lists. It's crucial to provide the SharePoint site URL, username, and password, preferably via environment variables for security. The library handles token management and digest token refreshing automatically."},"warnings":[{"fix":"Saved sessions from v1.x.x must be re-created from scratch in v2.x.x. Existing code interacting with `sharepy.connect()` might need adjustment if it relied on deprecated arguments like `auth_tld`.","message":"Version 2.0.0 introduced a major refactor, converting authentication to a standard Requests auth class. This changes the internal workings significantly from v1.x.x. Old session objects (sp-session.pkl) saved with v1.x.x are not compatible with v2.x.x and will be invalidated by major version number changes.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"If custom authentication URLs are needed, manually instantiate an auth object and set its `login_url` property before passing it to `sharepy.SharePointSession`. Example: `auth = sharepy.auth.SharePointOnline(username='user@example.com'); auth.login_url = 'https://login.microsoftonline.de/extSES.srf'; s = sharepy.SharePointSession('example.sharepoint.com', auth)`.","message":"The `auth_tld` argument was removed from `sharepy.connect()` in v2.0.0. It is replaced by a `login_url` property in the authentication classes (e.g., `sharepy.auth.SharePointOnline`).","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Consider disabling 'Security Defaults' in Azure AD (if possible and secure for your environment) or exploring alternative authentication methods like App Passwords, SharePoint API client secrets, or Azure App Registration with Microsoft Graph API if `sharepy` fails.","message":"SharePy might not be compatible with newer Microsoft 365 authentication models, especially when Multi-Factor Authentication (MFA) is enabled, or with federated logins (e.g., GoDaddy). Users have reported 'RTFA and authentication errors' and freezing during authentication. The traditional username/password method often fails if 'Security Defaults' are active in Azure AD.","severity":"gotcha","affected_versions":"All versions, particularly with modern M365 setups"},{"fix":"Ensure the `certifi` package is up to date (`pip install --upgrade certifi`). Verify your internet connectivity and the validity of the SharePoint server's SSL certificate. Disabling SSL verification is not recommended for production environments.","message":"SSL certificate verification errors are common. This can be due to outdated `certifi` package or issues with the SharePoint server's SSL certificate.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure the SharePoint site URL provided to `sharepy.connect()` is correct and does not contain an extraneous trailing slash.","message":"Incorrect SharePoint site URL format can lead to authentication errors. Specifically, a trailing slash (e.g., `https://example.sharepoint.com/` vs `https://example.sharepoint.com`) might cause issues.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}