Skip to main content

SharePoint Online Python

Currently Under Development, PRs are welcome.

Allows users to access SharePoint List data within a locally running Python script. Supports Microsoft Active Directory SSO for SharePoint Online.

Will open a new browser window -> allow the user to login -> then produce an access token for the local Python script to authenticate for SharePoint.

This is only suitable for python scripts running on a local machine as it requires user input to authenticate. This library is tightly integrated with Pandas to allow simple read write between a SharePoint List and a Pandas dataframe.

Setup

  1. Install package:

    pip install sharepoint-online-python
    
  2. Import:

    from sharepoint_online import SharePoint
    

Example

from dotenv import load_dotenv
import os
from sharepoint_online import SharePoint

load_dotenv()

# it is advisable to load these details in from an .env file
AUTH_URL = os.environ.get("AUTH_URL")
CLIENT_ID = os.environ.get("CLIENT_ID")
TOKEN_URL = os.environ.get("TOKEN_URL")
SITE_ID = os.environ.get("SITE_ID")
LIST_ID = os.environ.get("LIST_ID")

# initialize the SharePoint object
sp = SharePoint(CLIENT_ID, AUTH_URL, TOKEN_URL, SITE_ID)

# get the list as a pandas dataframe
working_df = sp.get_list_df(LIST_ID, expand="fields")

# reassign the title column as "New Title"
working_df["Title"] = "New Title"

# update the list based on the modified dataframe
sp.update_rows(LIST_ID, working_df)

# get the updated list as a dataframe
print(sp.get_list_df(LIST_ID, expand="fields"))

This is based on the Microsoft Graph API and the docs for the currently supported request is here: https://docs.microsoft.com/en-us/graph/api/list-get?view=graph-rest-1.0&tabs=http

In order to use this, you must first have access to the Azure Active Directory in your tenant and have permission to create App Registrations.

Follow the steps below to gain access to setup the app registration and find the necessary details:

  1. Create a new Active Directory app registration and get Client/Application ID from the Overview Page.
  2. Get Auth and Token endpoints by clicking the "Endpoints" button on the top bar of the Overview Page. Use the "OAuth 2.0 authorization endpoint (v2)" and "OAuth 2.0 token endpoint (v2)" urls.
  3. Click API Permissions -> add a permission -> Microsoft Graph -> Delegated Permissions -> Sites and select Sites.Read.All then click Add Permissions. You may need to get these permissions approved by the tenant administrator.
  4. Click Authentication -> add a platform -> Mobile and desktop applications -> and enter: http://localhost:3000
  5. Find the site ID from this tutorial: https://www.sharepointdiary.com/2018/04/sharepoint-online-powershell-to-get-site-collection-web-id.html
  6. Find the list ID by going to the list sharepoint page, click the cog on the top right, then click "List Settings". In the URL should be a parameter List=%7B..................%7D. Copy everything between the %7B and %7D but not including.

To-do List

  • Add new rows to list
  • Add new columns
  • Testing

Metadata

Release files for sharepoint-online-python 0.0.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sharepoint-online-python 0.0.10
File Size Uploaded Provenance Actions
sharepoint_online_python-0.0.10.tar.gz 7.8 kB Without provenance Details for sharepoint_online_python-0.0.10.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sharepoint-online-python 0.0.10
File Interpreter ABI Platform Actions
sharepoint_online_python-0.0.10-py3-none-any.whl Python 3 none any Details for sharepoint_online_python-0.0.10-py3-none-any.whl

Total release size: 14.9 kB

Release files / sharepoint_online_python-0.0.10.tar.gz

Download URL sharepoint_online_python-0.0.10.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
e18a059deea0e32622580dbe7b9539e0bbcb6882bf137f5b7b4a28ff2d4effe4
BLAKE2b-256 checksum
How to use checksums
5f0da19f473a27d5b0650d0cabaffb9fd765510e49ad57dd9a50c6e0be7c6045
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.9.6

Release files / sharepoint_online_python-0.0.10-py3-none-any.whl

Download URL sharepoint_online_python-0.0.10-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
648c2fa26cd9a1eaa48e1195f50c52ee5c766c58a12d58cfc11a1474db6b1014
BLAKE2b-256 checksum
How to use checksums
04612d6e438add271f607a03dd99cf37850d3306d86ed096057d77a2eb251e90
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.9.6

Security for sharepoint-online-python 0.0.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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page