sharepointlib
Microsoft SharePoint client package for Python powered by Rust.
Installation
pip install sharepointlib
Usage
import sharepointlib
sharepoint = sharepointlib.SharePoint(
client_id="<client-id>",
tenant_id="<tenant-id>",
client_secret="<client-secret>",
sp_domain="companygroup.sharepoint.com",
)
Authentication and sites
# Force token refresh (for long-running sessions)
sharepoint.renew_token()
# Site metadata
response = sharepoint.get_site_info(name="My Site", save_as="site_info.json")
if response.status_code == 200:
print(response.content)
# Resolve hostname details from a site ID
response = sharepoint.get_hostname_info(site_id="companygroup.sharepoint.com,abc,def")
if response.status_code == 200:
print(response.content)
# Drives
response = sharepoint.list_drives(site_id="companygroup.sharepoint.com,abc,def")
if response.status_code == 200:
print(response.content)
Drives and files
# List a folder
response = sharepoint.list_dir(
drive_id="b!123",
path="Sellout/Support",
alias=r"_\d{8}",
)
if response.status_code == 200:
print(response.content)
# Download one file
response = sharepoint.download_file(
drive_id="b!123",
remote_path="Sellout/Support/report.xlsx",
local_path=r"C:\\Temp\\report.xlsx",
)
print(response.status_code)
# Download to memory (bytes)
response = sharepoint.download_file_to_memory(
drive_id="b!123",
remote_path="Sellout/Support/report.xlsx",
)
if response.status_code == 200:
payload_bytes = response.content
print(len(payload_bytes))
# Copy across drives via streaming
response = sharepoint.copy_file_stream(
source_drive_id="b!SRC",
source_path="Sellout/2024/Sellout_November.xlsx",
target_drive_id="b!DST",
target_path="Archive/2024",
new_name="Sellout_November_2024_Backup.xlsx",
timeout=7200,
)
print(response.status_code)
# Get folder metadata
response = sharepoint.get_dir_info(
drive_id="b!123",
path="Sellout/Support",
)
if response.status_code == 200:
print(response.content)
# Create / rename / delete a folder
created = sharepoint.create_dir(
drive_id="b!123",
path="Sellout",
name="Support_New",
)
renamed = sharepoint.rename_folder(
drive_id="b!123",
path="Sellout/Support_New",
new_name="Support_Renamed",
)
deleted = sharepoint.delete_dir(
drive_id="b!123",
path="Sellout/Support_Renamed",
)
print(created.status_code, renamed.status_code, deleted.status_code)
# File metadata and download URL
info = sharepoint.get_file_info(
drive_id="b!123",
filename="Sellout/Support/report.xlsx",
)
url = sharepoint.get_download_url(
drive_id="b!123",
filename="Sellout/Support/report.xlsx",
)
print(info.status_code)
print(url)
# Upload a local file
response = sharepoint.upload_file(
drive_id="b!123",
local_path=r"C:\\Temp\\report.xlsx",
remote_path="Sellout/Support",
)
print(response.status_code)
# Move / rename / copy / delete a file
moved = sharepoint.move_file(
drive_id="b!123",
filename="Sellout/Support/report.xlsx",
target_path="Archive/2024",
new_name="report_2024.xlsx",
)
renamed = sharepoint.rename_file(
drive_id="b!123",
filename="Archive/2024/report_2024.xlsx",
new_name="report_final.xlsx",
)
copied = sharepoint.copy_file(
drive_id="b!123",
filename="Archive/2024/report_final.xlsx",
target_path="Archive/Backup",
)
deleted = sharepoint.delete_file(
drive_id="b!123",
filename="Archive/Backup/report_final.xlsx",
)
print(moved.status_code, renamed.status_code, copied.status_code, deleted.status_code)
# Check out and check in a file
checked_out = sharepoint.check_out_file(
drive_id="b!123",
filename="Sellout/Support/report.xlsx",
)
checked_in = sharepoint.check_in_file(
drive_id="b!123",
filename="Sellout/Support/report.xlsx",
comment="Updated after reconciliation",
)
print(checked_out.status_code, checked_in.status_code)
# Download all files from a folder to a local directory
response = sharepoint.download_all_files(
drive_id="b!123",
remote_path="Sellout/Support",
local_path=r"C:\\Temp\\support",
)
print(response.status_code)
SharePoint lists
# SharePoint lists
response = sharepoint.list_lists(site_id="companygroup.sharepoint.com,abc,def")
if response.status_code == 200:
print(response.content)
# List list columns
response = sharepoint.list_list_columns(
site_id="companygroup.sharepoint.com,abc,def",
list_id="1234-5678-90ab-cdef",
)
if response.status_code == 200:
print(response.content)
# Request up to 5,000 list items with selected fields
response = sharepoint.list_list_items(
site_id="companygroup.sharepoint.com,abc,def",
list_id="1234-5678-90ab-cdef",
fields="Title,Status,Owner",
)
if response.status_code == 200:
print(response.content)
# Add, update, and delete a list item
created = sharepoint.add_list_item(
site_id="companygroup.sharepoint.com,abc,def",
list_id="1234-5678-90ab-cdef",
item={"Title": "New task", "Status": "Open"},
)
updated = sharepoint.update_list_item(
site_id="companygroup.sharepoint.com,abc,def",
list_id="1234-5678-90ab-cdef",
item_id="42",
item={"Status": "In progress"},
)
deleted = sharepoint.delete_list_item(
site_id="companygroup.sharepoint.com,abc,def",
list_id="1234-5678-90ab-cdef",
item_id="42",
)
print(created.status_code, updated.status_code, deleted.status_code)
Methods that return a Response expose status_code (the HTTP status code) and
content (the decoded payload: a dict, list, bytes, or None). Methods raise
RuntimeError when a Rust operation fails.
For technical and contributor documentation, see DEV.md.
Version
Recommended way to read installed package version:
from importlib.metadata import version
print(version("sharepointlib"))
Convenience attribute:
import sharepointlib
print(sharepointlib.__version__)
Licence
BSD-3-Clause Licence (see LICENSE)
Metadata
Release files for sharepointlib 0.1.10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sharepointlib-0.1.10.tar.gz | 41.8 kB | Without provenance | Details for sharepointlib-0.1.10.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| sharepointlib-0.1.10-cp310-abi3-win_amd64.whl | CPython 3.10 | abi3 | Windows x86-64 | Details for sharepointlib-0.1.10-cp310-abi3-win_amd64.whl |
| sharepointlib-0.1.10-cp310-abi3-manylinux_2_39_aarch64.whl | CPython 3.10 | abi3 | Linux glibc 2.39+ ARM64 | Details for sharepointlib-0.1.10-cp310-abi3-manylinux_2_39_aarch64.whl |
| sharepointlib-0.1.10-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl | CPython 3.10 | abi3 | Linux glibc 2.17+ x86-64 | Details for sharepointlib-0.1.10-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
| sharepointlib-0.1.10-cp310-abi3-macosx_11_0_arm64.whl | CPython 3.10 | abi3 | macOS 11.0+ ARM64 | Details for sharepointlib-0.1.10-cp310-abi3-macosx_11_0_arm64.whl |
Total release size: 10.5 MB
Security for sharepointlib 0.1.10
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.