sda.api.graph_client#

MS Graph API client for SharePoint file access.

Attributes#

Classes#

GraphClient

Client for interacting with SharePoint via MS Graph API.

Functions#

download_presigned_graph_url(url, destination, *[, ...])

Download from @microsoft.graph.downloadUrl without an Authorization header.

Module Contents#

sda.api.graph_client.GRAPH_BASE = 'https://graph.microsoft.com/v1.0'#
sda.api.graph_client.download_presigned_graph_url(url, destination, *, timeout=300.0, max_attempts=3)#

Download from @microsoft.graph.downloadUrl without an Authorization header.

The URL is already authenticated (temporary SAS). Uses HTTP/1.1 only, a normal User-Agent, and limited retries for transient connection resets.

class sda.api.graph_client.GraphClient(tenant_id, client_id, client_secret)#

Client for interacting with SharePoint via MS Graph API.

download_file(site_id, drive_id, item_path, destination)#

Download a file from SharePoint and save to destination.

Parameters:
  • site_id (str) – SharePoint site ID.

  • drive_id (str) – Drive ID within the site.

  • item_path (str) – Path to the item within the drive root (e.g. "Gif/T297/T297.xlsm").

  • destination (Path) – Local path to write the downloaded file.

Returns:

The destination path after writing.

Return type:

Path

Notes

Uses the @microsoft.graph.downloadUrl pre-signed URL from the item metadata rather than the /content redirect endpoint. The /content endpoint issues a 302 to Azure Blob Storage; following it with an Authorization header causes a WinError 10054 connection reset because Blob Storage uses SAS-based auth, not Bearer tokens.

list_folder_children(site_id, drive_id, folder_path, filename_filter='*')#

List files inside a SharePoint drive folder, following pagination.

Parameters:
  • site_id (str) – SharePoint site ID.

  • drive_id (str) – Drive ID within the site.

  • folder_path (str) – Path to the folder within the drive root (e.g. "Gif/T297"). Use "" or "/" for the drive root.

  • filename_filter (str, optional) – Glob pattern to filter file names, by default "*" (all files). Example: "*.xls*" to match xlsx/xlsm/xls.

Returns:

List of dicts with keys "name" and "download_url" for each matching file. "download_url" is the pre-signed Azure Blob Storage URL (@microsoft.graph.downloadUrl).

Return type:

list[dict]