Skip to content

Instantly share code, notes, and snippets.

@jmyzk
Created June 20, 2023 14:44
Show Gist options
  • Save jmyzk/3effb5bf22941e381de63deb8a0b31ae to your computer and use it in GitHub Desktop.
Save jmyzk/3effb5bf22941e381de63deb8a0b31ae to your computer and use it in GitHub Desktop.
delete_rows_in_batches
def delete_rows_in_batches(sheet_id, batch_size=300):
row_ids = [row.id for row in smartsheet_client.Sheets.get_sheet(sheet_id).rows]
num_rows = len(row_ids)
num_batches = (num_rows // batch_size) + 1
for i in range(num_batches):
start_index = i * batch_size
end_index = min(start_index + batch_size, num_rows)
batch_row_ids = row_ids[start_index:end_index]
# Delete rows in the current batch
smartsheet_client.Sheets.delete_rows(sheet_id, batch_row_ids)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment