Saturday, 11 February 2023

Python - Download Files from Sharepoint Online

FAUN Publication
Published in

FAUN Publication

Quick ETL With Python Part 1 : Download Files from Sharepoint Online

  1. {TL} Modify and Upsert Table into SQL
  2. {Auto} Python Jobs on Window without Installation
  1. Grant Permission for App User
  2. Download file with Python

1. Create App User

Copy your SharePoint site’s URL, for example
https://{YOURSHAREPOINT}/sites/{YOURSITE}

2. Set up Permission for App User

Add /_layouts/15/appinv.aspx after your site’s URL, for example
https://{YOURSHAREPOINT}/sites/{YOURSITE}/_layouts/15/appinv.aspx

<AppPermissionRequests AllowAppOnlyPolicy="true"> <AppPermissionRequest Scope="http://sharepoint/content/sitecollection" Right="FullControl" /> </AppPermissionRequests>

3. Download file with Python

First, we need to get the download URL of your file as these steps

pip install py-topping
pip install Office365-REST-Python-Client
# Import library
from py_topping.data_connection.sharepoint import lazy_SP365
# Create connection
sp = lazy_SP365(site_url = 'Your Site URL'
, client_id = 'Your ID'
, client_secret = 'Your Secret')
# Create download path from download URL
download_path = sp.create_link('Your Download File Link')
# Download file
sp.download(sharepoint_location = download_path
, local_location = 'local directory you want to save')

No comments:

Post a Comment