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)
# List 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.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sharepointlib-0.1.9.tar.gz | 41.7 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| sharepointlib-0.1.9-cp310-abi3-win_amd64.whl | CPython 3.10 | abi3 | Windows x86-64 | Details |
| sharepointlib-0.1.9-cp310-abi3-manylinux_2_39_aarch64.whl | CPython 3.10 | abi3 | Linux glibc 2.39+ ARM64 | Details |
| sharepointlib-0.1.9-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.10 | abi3 | Linux glibc 2.17+ x86-64 | Details |
| sharepointlib-0.1.9-cp310-abi3-macosx_11_0_arm64.whl | CPython 3.10 | abi3 | macOS 11.0+ ARM64 | Details |
Total release size: 10.5 MB