Skip to main content

This Python utility enables users to interact with SharePoint sites via Microsoft Graph API, facilitating tasks such as listing, downloading, uploading, moving, and deleting files.

Project description

SharePoint GraphQL

Project on PyPI

https://pypi.org/project/sharepoint-graphql/

Overview:

This Python utility enables users to interact with SharePoint sites via Microsoft Graph API, facilitating tasks such as listing, downloading, uploading, moving, and deleting files. The motivation behind creating this repository stems from the absence of a SharePoint GraphQL interface in the existing Office365 Python library client (Office365-REST-Python-Client) This README provides instructions for setting up and using the utility.

Prerequisites:

  • Python installed on your machine.
  • Microsoft Azure AD tenant with necessary permissions to access SharePoint resources.
  • Registered Azure AD application with appropriate API permissions. (Delegated permission)

Installation:

  1. Use pip
pip install sharepoint-graphql

Configuration:

  1. Update the following variables with your Azure AD and SharePoint details:
    • TENANT_ID: Your Azure AD tenant ID.
    • CLIENT_ID: Client ID of your Azure AD application.
    • CLIENT_SECRET: Client secret of your Azure AD application.
    • SITE_URL: URL of the SharePoint site you want to interact with.

Usage:

  1. Import the SharePointGraphql class from sharepoint_graphql.py into your Python script.
  2. Create an instance of the SharePointGraphql class by passing the required parameters: site_url, tenant_id, client_id, and client_secret.
  3. Use the instance methods to perform various tasks:
    • list_files(folder_path): List files within a specific folder.
    • download_file_by_relative_path(remote_path, local_path): Download a file by its relative path.
    • upload_file_by_relative_path(remote_path, local_path): Upload a file by its relative path.
    • move_file(remote_src_path, remote_des_path): Move a file from source to destination.
    • delete_file_by_relative_path(remote_path): Delete a file by its relative path.

Example:

from sharepoint_graphql import SharePointGraphql

# Initialize SharePointGraphql instance
sp_graphql = SharePointGraphql(site_url, tenant_id, client_id, client_secret)

# List files in a folder
files = sp_graphql.list_files("/Shared Documents/Subfolder")

# Download a file
sp_graphql.download_file_by_relative_path("/Shared Documents/Folder/file.txt", "local_path/file.txt")

# Upload a file
sp_graphql.upload_file_by_relative_path("/Shared Documents/Folder/file.txt", "local_path/file.txt")

# Move a file
sp_graphql.move_file("/Shared Documents/Folder/file.txt", "/Shared Documents/NewFolder/file.txt")

# Delete a file
sp_graphql.delete_file_by_relative_path("/Shared Documents/Folder/file.txt")

Notes:

  • Ensure your Azure AD application has the necessary permissions configured in Azure Portal.
  • Handle exceptions and errors appropriately in your script for robustness.
  • Refer to Microsoft Graph API documentation for additional functionalities and parameters.

License:

This project is licensed under the MIT License.

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

sharepoint_graphql-0.1.5.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

sharepoint_graphql-0.1.5-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file sharepoint_graphql-0.1.5.tar.gz.

File metadata

  • Download URL: sharepoint_graphql-0.1.5.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for sharepoint_graphql-0.1.5.tar.gz
Algorithm Hash digest
SHA256 f241ba293c376db384f6866e43aafab86bc6502ecc65fcbcef0763dd0849c753
MD5 876244fcbbec09a715d0af18dd651f4b
BLAKE2b-256 6ee0d163a3985fd679b35aa8d106bf18e122abc75eed8e99a5d6d7c30c1c0bcf

See more details on using hashes here.

File details

Details for the file sharepoint_graphql-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for sharepoint_graphql-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 cdccf9bb512b82546834ceeee428996eed6aa2eb546fab3f8f6919ea93a88652
MD5 474f28b1ce87e334d23a0eef3aba3758
BLAKE2b-256 baf68721ccc71aa74cd8985645b829cf9733c0d9e0fc0d33c16a9d2ee6e9068c

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