Skip to main content

A shared package for reading and writing to SharePoint

Project description

MPR-sharepoint-utils

Deploy

Installing the package

pipenv install mpr-sharepoint-utils

Using the package:

First, you must establish a SharePointConnection, which takes the following arguments:

  • client_id, the ID portion of your user (or service) account credentials
  • client_secret, the secret string of your user (or service) credentials
  • site_id, the ID of the SharePoint site you wish to access
  • tenant, the name of your organization (you can find this in a SharePoint URL, like "tenant.sharepoint.com")

Once you've established a connection, you can pass that to any of the utility functions to perform operations in SharePoint.

Example usage

from sharepoint_utils import SharePointConnection, get_txt

sharepoint_ctx = SharePointConnection(
  client_id="<YOUR CLIENT ID>",
  client_secret="<YOUR CLIENT SECRET>",
  site_id="<YOUR SITE ID>",
  tenant="<YOUR TENANT>"
)

txt_str = get_txt(
  sharepoint_ctx,
  drive="Documents",
  file_path="path/to/file"
)

In order to reduce unnecessary bloat, utility functions that depend on large packages such as pandas live in separate modules. These packages are not dependencies of mpr-sharepoint-utils and therefore need to be installed directly into your project.

Example usage

from sharepoint_utils import SharePointConnection
from sharepoint_utils.spreadsheet_utils import get_csv_as_df

sharepoint_ctx = SharePointConnection(
  client_id="<YOUR CLIENT ID>",
  client_secret="<YOUR CLIENT SECRET>",
  site_id="<YOUR SITE ID>",
  tenant="<YOUR TENANT>"
)

df = get_csv_as_df(
  sharepoint_ctx,
  drive="Documents",
  file_path="path/to/file"
)

FAQs

Q: How do I know what my site ID is?

A: First, get your access token with the first command below; then, plug that into the second command below to get your site ID.

Get access token (can use to get site id given hostname and path (site/subsite)):

curl --location --request POST 'https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'client_id=INSERT_CLIENT_ID' \
--data-urlencode 'scope=https://graph.microsoft.com/.default' \
--data-urlencode 'client_secret=INSERT_CLIENT_SECRET' \
--data-urlencode 'grant_type=INSERT_CLIENT_CREDENTIALS'

Get site ID

curl --location --request GET 'https://graph.microsoft.com/v1.0/sites/{hostname}:/sites/{path}?$select=id' \
--header 'Authorization: Bearer access_token' \
--data

Maintainers

  • Claire McShane
  • Holden Huntzinger
  • Tess Martinez
  • Max Grody

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

mpr_sharepoint_utils-2.0.3.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

mpr_sharepoint_utils-2.0.3-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file mpr_sharepoint_utils-2.0.3.tar.gz.

File metadata

  • Download URL: mpr_sharepoint_utils-2.0.3.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for mpr_sharepoint_utils-2.0.3.tar.gz
Algorithm Hash digest
SHA256 ddcce8aafd36561c6cccdcbcbdbeff16124d284c40410ffe9d6e45b0a6940818
MD5 09539235b09974aa9c4845749f61de7b
BLAKE2b-256 fdff6aadf23f5b2ca0cd1f519204a4cace5819dba1c194f566be046f863afd3b

See more details on using hashes here.

File details

Details for the file mpr_sharepoint_utils-2.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for mpr_sharepoint_utils-2.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 17630e4968cd24d9cc933c7645983ca1396b25de94f372f17cceb839e3556c65
MD5 dcef583f1b5afc42192c4c0da23d95f1
BLAKE2b-256 b0c57c44044e5a9db9a93973bf0dddc135dde053ae648a8bd15e92726d419809

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page