Skip to main content

Simple way to handle sharepoint with python. Provides the ability to upload files and directories.

This package authenticates with Microsoft Entra ID client credentials and uses Microsoft Graph for SharePoint document library access.

Installation

install the latest stable version using pip

$ pip install simple-sharepoint

Usage

from simple_sharepoint.client import Client

client_id = < CLIENT_ID >
client_secret = < CLIENT_SECRET >
tenant_id = < TENANT_ID >
base_url = < BASE URL >

c = Client(client_id, client_secret, base_url, tenant_id)
  • TENANT_ID can be either the tenant ID or tenant domain, such as contoso.onmicrosoft.com.
    If omitted, it is inferred from the SharePoint host name. For example, https://contoso.sharepoint.com becomes contoso.onmicrosoft.com.

  • See the link below for instructions on creating CLIENT_ID and CLIENT_SECRET for Entra ID app authentication.
    Make Token

  • Grant Microsoft Graph application permission for the target SharePoint site and complete admin consent.
    Use Sites.Read.All for read-only workflows, or Sites.ReadWrite.All / Sites.FullControl.All for uploads and folder creation.

  • Runtime requests must use Microsoft Graph URLs under https://graph.microsoft.com/v1.0.
    If logs still show SharePoint REST /_api URLs or token audience 00000003-0000-0ff1-ce00-000000000000, an old Office365 REST code path or package version is still being executed.

  • BASE_URL refers to the main URL of the sharepoint.
    ( format ) https://<SHAREPOINT_DOMAIN>/sites/<SHAREPOINT_SITE>
    ( ex ) https://test.sharepoint.com/sites/testsite

  • SharePoint paths may use the existing server-relative format, such as /sites/testsite/Shared Documents/excel/example.
    The site prefix and default document library name are normalized to Microsoft Graph drive-root paths internally.

Functions

upload_file

A function that uploads a specific file to sharepoint.

default_path = < SHAREPOINT_BASE_PATH >
src = < LOCAL_FILE_PATH >
dst = default_path + < SHAREPOINT_TARGET_PATH >

upload_file(src, dst)
  • SHAREPOINT_BASE_PATH refers to the default path for a sharepoint document entry.
    ( format ) /sites/<SHAREPOINT_SITE>/Shared Documents
    ( ex ) /sites/testsite/Shared Documents

  • LOCAL_FILE_PATH means the path to the file to be uploaded.
    ( ex ) /home/ubuntu/test.txt

  • SHAREPOINT_TARGET_PATH means the actual path to be uploaded to sharepoint.
    Think of the document menu in sharepoint as the root directory and enter the path thereafter.
    You do not need to include the file name.
    ( ex ) excel/example

  • If you run it as above, it will be uploaded as below.
    /sites/testsite/Shared Documents/excel/example/test.txt

upload_dir

A function that uploads a particular directory and all its contents under the directory to sharepoint.

default_path = < SHAREPOINT_BASE_PATH >
src = < LOCAL_DIR_PATH >
dst = default_path + < SHAREPOINT_TARGET_PATH >

upload_dir(src, dst)
  • SHAREPOINT_BASE_PATH, SHAREPIONT_TARGET_PATH See item upload_file

  • LOCAL_DIR_PATH means the path to the directory to be uploaded.
    ( ex ) /home/ubuntu/files

download_file

A function that downloads a specific file from the sharepoint.

default_path = < SHAREPOINT_BASE_PATH >
src = default_path + < SHAREPOINT_TARGET_PATH >
dst = < LOCAL_FILE_PATH >

download_file(src, dst)
  • SHAREPOINT_BASE_PATH, SHAREPIONT_TARGET_PATH See item upload_file

  • The download_file function requires you to specify the file name to be stored in LOCAL_FILE_PATH. ( ex ) /home/ubuntu/files/test.txt

download_dir

A function that downloads a particular directory in the sharepoint and all the contents under it.

default_path = < SHAREPOINT_BASE_PATH >
src = default_path + < SHAREPOINT_TARGET_PATH >
dst = < LOCAL_DIR_PATH >

download_dir(src, dst)
  • SHAREPOINT_BASE_PATH, SHAREPIONT_TARGET_PATH, LOCAL_DIR_PATH See item upload_dir

list_dir

A function that listing a particular directory in the sharepoint and all the contents under it.

default_path = < SHAREPOINT_BASE_PATH >
src = default_path + < SHAREPOINT_TARGET_PATH >

list_dir(src)
  • SHAREPOINT_BASE_PATH, SHAREPIONT_TARGET_PATH See item upload_dir

Use console scripts

simple-sharepoint-cli < FILE_PATH > --client-id < CLIENT_ID > --client-secret < CLIENT_SECRET > --tenant-id < TENANT_ID > --base-url < BASE_URL > --default-path < DEFAULT_PATH > --remote-dir < REMOTE_DIR >
  • CLIENT_ID, CLIENT_SECRET, TENANT_ID, BASE_URL See item Usage.
  • DEFAULT_PATH See upload_dir. same SHAREPOINT_BASE_PATH
  • REMOTE_DIR See upload_dir. same SHAREPOINT_TARGET_PATH

Third Party Libraries and Dependencies

Metadata

Release files for simple-sharepoint 0.1.9

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

Built distribution (wheel)

Table of built distributions (wheels) for simple-sharepoint 0.1.9
File Interpreter ABI Platform
simple_sharepoint-0.1.9-py3-none-any.whl Python 3 none any Details

Release files / simple_sharepoint-0.1.9-py3-none-any.whl

Download URL simple_sharepoint-0.1.9-py3-none-any.whl
Size 9.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f11474f887a83688d18fc4f8320a4453032351d3e85718761a33c1a0b975c772
BLAKE2b-256 checksum
How to use checksums
48e5bd6beeb9139cff69be51021f0362a57144ca5ecbc5f8dae2d8c4da13e7f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release history Release notifications | RSS feed

This release

0.1.9 This release

1 release file

0.1.8

1 release file

0.1.7

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

0.0.5

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

2 release files

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