Registry / http-networking / shareplum

shareplum

JSON →
library0.5.1pypypi✓ verified 23d ago

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.

pip install shareplum
INSTALL
IMPORT
SIG · SHAREPLUM
S
shareplum
http-networkingpythonv0.5.1
Install
3.8s avg
Import
444ms
Disk
51MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.5.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.466s · 52.1MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.8s · import 0.422s · 52MB
51MB installed
● package 51MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

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

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.")
Debug
Known issues
breakingThe Files API was significantly updated and stabilized in version 0.5.0. Existing code interacting with file uploads, downloads, and management methods might break or require adjustments.
fix
Review the official `shareplum` documentation or GitHub examples for the updated Files API methods. Test file-related operations thoroughly after upgrading.
affects: < 0.5.0
gotchaSharePoint authentication can be complex, especially with ADFS, multi-factor authentication (MFA), or specific corporate security policies. Basic username/password authentication might not always suffice.
fix
Consult your SharePoint administrator for the correct authentication method. shareplum primarily supports basic username/password; for more complex setups, you might need to handle authentication externally or use other tools like `MSAL.py` to obtain a bearer token, which `shareplum` can then use.
affects: All versions
gotchaProviding an incorrect SharePoint URL is a common mistake. The URL should typically include the full site collection path, e.g., `https://yourcompany.sharepoint.com/sites/yourteam`, rather than just the domain.
fix
Double-check the exact SharePoint site URL in your browser. Ensure it includes any `/sites/` or `/teams/` segments if applicable to your site collection.
affects: All versions
gotchaIt is crucial to specify the correct SharePoint `Version` enum (e.g., `Version.v365` for SharePoint Online) when initializing the `Site` object, as API behavior can differ between SharePoint versions.
fix
Always pass the appropriate `version` parameter to the `Site` constructor. For SharePoint Online (Office 365), `Version.v365` is typically correct.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'shareplum'
The shareplum library is not installed in your Python environment.
fix
Install the library using pip: `pip install shareplum`
shareplum.errors.SharePlumRequestError: ('Client Error: 401 Client Error: Unauthorized for url:', 'https://your.sharepoint.com/...')
Authentication failed due to incorrect credentials, insufficient permissions, or an issue with the SharePoint authentication setup (e.g., ADFS/SAML).
fix
Verify your username and password, check your SharePoint permissions, or correctly configure ADFS/SAML authentication using the `Auth` class with `adfs_url` if applicable.
AttributeError: 'Site' object has no attribute 'upload_file'
File operations like `upload_file` are performed on a `Folder` object, not directly on the `Site` object.
fix
First access the desired folder, then call the file operation method: `folder = site.Folder('Shared Documents'); folder.upload_file(file_content, 'my_file.txt')`
requests.exceptions.SSLError: HTTPSConnectionPool(host='your.sharepoint.com', port=443): Max retries exceeded with url: /_vti_bin/authentication.asmx (Caused by SSLError(CertificateError("hostname 'your.sharepoint.com' doesn't match 'another.sharepoint.com'")))
The SSL certificate of the SharePoint server is invalid, expired, self-signed, or the hostname in the URL does not match the certificate's subject.
fix
You can disable SSL verification (not recommended for production) by passing `verify_ssl=False` to the `Site` constructor: `site = Site(sharepoint_url, version=Version.v365, authcookie=auth_cookie, verify_ssl=False)` or ensure your environment trusts the SharePoint server's certificate.
Upgrade
Version history
0.5.1latest on PyPI · released Apr 22, 2020
Audit
Dependencies
requestsrequiredHandles HTTP communication with SharePoint APIs.
lxmlrequiredParses XML responses from SharePoint APIs.
Agent activity
11 hits · last 30 days
node
8
OpenAI (training)
1
Resources
shareplum — pip install shareplum · libregistry