🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

sharepointlib

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sharepointlib

Microsoft SharePoint client Python package that uses the requests library

0.0.7
Maintainers
1

sharepointlib

Package Description

Microsoft SharePoint client Python package that uses the requests library.

[!IMPORTANT]
This packages uses pydantic~=1.0!

Usage

from a script:

import sharepointlib
import logging

logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")

client_id = "123..."
tenant_id = "123..."
client_secret = "xxxx"
sp_domain = "companygroup.sharepoint.com"

sp_site_name = "My Site"
sp_site_id = "companygroup.sharepoint.com,1233124124"
sp_site_drive_id = "b!1234567890"

# Initialize SharePoint client
sharepoint = sharepointlib.SharePoint(client_id=client_id, 
                                      tenant_id=tenant_id, 
                                      client_secret=client_secret, 
                                      sp_domain=sp_domain)
# Gets the site ID for a given site name
response = sharepoint.get_site_info(name=sp_site_name)
if response.status_code == 200:
    print(response.content)
# Gets the hostname and site details for a specified site ID
response = sharepoint.get_hostname_info(site_id=sp_site_id)
if response.status_code == 200:
    print(response.content)
# Gets the hostname and site details for a specified site ID
response = sharepoint.get_hostname_info(site_id=sp_site_id)
if response.status_code == 200:
    print(response.content)

Drives:

# Gets a list of the Drive IDs for a given site ID
response = sharepoint.list_drives(site_id=sp_site_id)
if response.status_code == 200:
    print(response.content)
# Gets the folder ID for a specified folder within a drive ID
response = sharepoint.get_dir_info(drive_id=sp_site_drive_id,
                                   path="Sellout/Support")
if response.status_code == 200:
    print(response.content)
# List content (files and folders) of a specific folder
response = sharepoint.list_dir(drive_id=sp_site_drive_id, 
                               path="Sellout/Support")
if response.status_code == 200:
    print(response.content)
# Creates a new folder in a specified drive ID
response = sharepoint.create_dir(drive_id=sp_site_drive_id, 
                                 path="Sellout/Support",
                                 name="Archive")
if response.status_code in (200, 201):
    print(response.content)

response = sharepoint.create_dir(drive_id=sp_site_drive_id, 
                                 path="Sellout/Support",
                                 name="Test")
if response.status_code in (200, 201):
    print(response.content)
# Deletes a folder from a specified drive ID
response = sharepoint.delete_dir(drive_id=sp_site_drive_id, 
                                 path="Sellout/Support/Test")
if response.status_code in (200, 204):
    print("Folder deleted successfully")
# Retrieves information about a specific file in a drive ID
response = sharepoint.get_file_info(drive_id=sp_site_drive_id, 
                                    filename="Sellout/Support/Sellout.xlsx")
if response.status_code in (200, 202):
    print(response.content)
# Copy a file from one folder to another within the same drive ID
response = sharepoint.copy_file(drive_id=sp_site_drive_id, 
                                filename="Sellout/Support/Sellout.xlsx",
                                target_path="Sellout/Support/Archive")
if response.status_code in (200, 202):
    print("File copied successfully")
# Moves a file from one folder to another within the same drive ID
response = sharepoint.move_file(drive_id=sp_site_drive_id, 
                                filename="Sellout/Sellout.xlsx", 
                                target_path="Sellout/Support/Archive")
if response.status_code == 200:
    print(response.content)
# Deletes a file from a specified drive ID
response = sharepoint.delete_file(drive_id=sp_site_drive_id, 
                                  filename="Sellout/Support/Sellout.xlsx")
if response.status_code in (200, 204):
    print("File deleted successfully")
# Downloads a file from a specified remote path in a drive ID to a local path
response = sharepoint.download_file(drive_id=sp_site_drive_id, 
                                    remote_path=r"Sellout/Support/Archive/Sellout.xlsx",
                                    local_path=r"C:\Users\admin\Downloads\Sellout.xlsx")
if response.status_code == 200:
    print("File downloaded successfully")
# Uploads a file to a specified remote path in a SharePoint drive ID
response = sharepoint.upload_file(drive_id=sp_site_drive_id, 
                                  local_path=r"C:\Users\admin\Downloads\Sellout.xlsx",
                                  remote_path=r"Sellout/Support/Archive/Sellout.xlsx")
if response.status_code in (200, 201):
    print(response.content)

Installation

Install python and pip if you have not already.

Then run:

pip3 install pip --upgrade
pip3 install wheel

For production:

pip3 install sharepointlib

This will install the package and all of it's python dependencies.

If you want to install the project for development:

git clone https://github.com/aghuttun/sharepointlib.git
cd sharepointlib
pip3 install -e .[dev]

To test the development package: Testing

License

BSD License (see license file)

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts