Script in Python to download all PDF attachments in a Sheet

Options
Daniel Guevara
Daniel Guevara ✭✭✭
edited 06/20/25 in Best Practice

Hi Guys,

Created a basic script to download all PDFs from a sheet.

Use case: I use Document Builder to create documents from field inspections. However, we need to store these in sharepoint for redundancy. This script basically pulls all "PDFs" so you can then migrate them where you need to. I don't want to pay an expensive license with Smartsheet to do this, nor pay a business as it defeats the purpose. Found you can just use Python to code with the Smartsheet API fairly easily.

Hint - I just spent 30 minutes using Copilot to create it. Trial and error, feeding the AI with what I need until I got it right. Thought someone might want it.

Script below:

import smartsheet
import os
API_TOKEN = 'Your Token'

Replace API Token

SHEET_ID = yourID # Replace with your actual sheet ID

This script only downloads PDFs from a sheet. It does not download photos.Create a folder to store PDFs

download_dir = "pdf_attachments"
os.makedirs(download_dir, exist_ok=True)

Initialize Smartsheet client

smartsheet_client = smartsheet.Smartsheet(API_TOKEN)

Get the sheet

sheet = smartsheet_client.Sheets.get_sheet(SHEET_ID)

Loop through each row

for row in sheet.rows:
attachments = smartsheet_client.Attachments.list_row_attachments(SHEET_ID, row.id).data
for attachment in attachments:
if attachment.mime_type == 'application/pdf' or attachment.name.lower().endswith('.pdf'):
# Get the full attachment object
full_attachment = smartsheet_client.Attachments.get_attachment(SHEET_ID, attachment.id)
smartsheet_client.Attachments.download_attachment(full_attachment, download_dir)
print(f"✅ Downloaded: {attachment.name}")

print("✅ All PDF attachments downloaded.")