Smartsheet Python SDK

3.7.2 · active · verified Sat Apr 11

The Smartsheet Python SDK is a library for connecting Python applications to Smartsheet services using API 2.0. It provides a programmatic interface to manage sheets, rows, columns, users, and other Smartsheet resources. The library simplifies interaction with the Smartsheet API, handling authentication, request serialization, and response deserialization. It is actively maintained, with the current version being 3.7.2, and typically sees updates for API endpoint changes and new features.

Warnings

Install

Imports

Quickstart

This quickstart initializes the Smartsheet client using an API access token from environment variables. It then lists the user's sheets and retrieves details for the first one found. It also demonstrates how to enable exceptions for API errors.

import smartsheet
import os

# Ensure SMARTSHEET_ACCESS_TOKEN is set in your environment variables
# You can generate an access token in Smartsheet UI under Account > Personal Settings > API Access.
access_token = os.environ.get('SMARTSHEET_ACCESS_TOKEN', '')

if not access_token:
    print("Error: SMARTSHEET_ACCESS_TOKEN environment variable not set.")
    print("Please generate an access token from Smartsheet and set it.")
else:
    try:
        # Create a Smartsheet client
        smart = smartsheet.Smartsheet(access_token)

        # Optional: Enable exceptions for API errors instead of returning Error objects
        smart.errors_as_exceptions(True)

        # List all sheets the authenticated user has access to
        response = smart.Sheets.list_sheets()

        if response.data:
            first_sheet = response.data[0]
            print(f"Found sheet: {first_sheet.name} (ID: {first_sheet.id})")
            
            # Get a specific sheet by ID
            sheet = smart.Sheets.get_sheet(first_sheet.id)
            print(f"The sheet '{sheet.name}' has {sheet.total_row_count} rows.")
        else:
            print("No sheets found for this user.")

    except smartsheet.exceptions.SmartsheetException as e:
        print(f"An error occurred: {e}")
    except Exception as e:
        print(f"An unexpected error occurred: {e}")

view raw JSON →