Allows users to access Sharepoint data within a locally running Python script.
Project description
SharePoint Online Python
Currently Under Development
Allows users to access Sharepoint 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.
Setup
-
Install package:
pip install sharepoint-online-python
-
Import:
from sharepoint-online-python import sharepoint
Example
from sharepoint_online import sharepoint
# These details are probably best stored in environment variables
CLIENT_ID = os.environ.get("CLIENT_ID")
AUTH_URL = os.environ.get("AUTH_URL")
TOKEN_URL = os.environ.get("TOKEN_URL")
SITE_ID = os.environ.get("SITE_ID")
LIST_ID = os.environ.get("LIST_ID")
# Create an instance of 'Sharepoint'
sp = sharepoint.Sharepoint(CLIENT_ID, AUTH_URL, TOKEN_URL, SITE_ID)
# Use 'get_list_items' to make a get request to the list and retrieve the items in JSON format.
# You can also add query parameters as kwargs as shown with 'expand="fields" to get the field data'
print(sp.get_list_items(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:
- Create a new Active Directory app registration and get Client/Application ID from the Overview Page.
- 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.
- 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.
- Click Authentication -> add a platform -> Mobile and desktop applications -> and enter: http://localhost:3000
- Find the site ID from this tutorial: https://www.sharepointdiary.com/2018/04/sharepoint-online-powershell-to-get-site-collection-web-id.html
- 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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for sharepoint-online-python-0.0.6.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7c8647927555eb680dce0e9ee62d9517659ccfa896af4c31fb2e3fff07bba10 |
|
MD5 | f82278b62a109755071642510b9f4b0f |
|
BLAKE2b-256 | 22b3f1645d929e43b2bc506f5b68d82b8277d4baa9f290d9b836af4abbdb6e90 |
Hashes for sharepoint_online_python-0.0.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 893d5271a27333d85173143911371157195c419645a8f282616e8868d9bd550d |
|
MD5 | 71172fdc873f401ae84eca75a8cc1b5f |
|
BLAKE2b-256 | 1ec663e2fde8818ed6b74696ab16dea5500d0d9d9afc3e461a30eeb753cb88b4 |