Skip to main content

A Python library that simplifies Smartsheet API workflows

Reason this release was yanked:

temporarily revoking release, pending release approval

Project description

Smartsheet Engine

A Python library that simplifies Smartsheet API workflows

Table of Contents

Features

  • Get a Smartsheet as a dataframe
  • Append rows from a dataframe to a Smartsheet
  • Update rows on a Smartsheet with a dataframe
  • Delete rows from a Smartsheet with a dataframe
  • Update the properties of a Smartsheet column
    • Update column dropdown options
    • Lock/unlock a column
    • Hide/unhide a column

Coming Soon

  • Update all Smartsheet column properties
  • Compare two versions of a dataframe to see how it has changed (diffing)
    • Merge the two versions on a unique identifier
    • Identify what column values changed between the left or right versions
    • Identify any rows that exist only in the left or right versions
  • Perform actions on many Smartsheets, instead of just one at a time
  • Provision new Smartsheets from a given schema (column names and column properties) and list of email contacts for sharing
  • Command-line interface for updating Smartsheets on the fly

Installation

  1. Download and install Python
  2. Install from PyPI with pip:
pip install smartsheet-engine

Usage

To use Smartsheet Engine in your Notebook or script:

  1. Get your Smartsheet API key and save it to a variable, such as smartsheet_api_key
  2. Import the SmartsheetEngine class
  3. Initialize a SmartsheetEngine object with your API key
from smartsheet_engine.engine import SmartsheetEngine

S = SmartsheetEngine(api_key=smartsheet_api_key)

[!IMPORTANT] Don't hardcode your API key into your script or Notebook widget. Put it in a secret store or an environment variable instead.

[!TIP] You don't need to provide an api_key when you initialize a SmartsheetEngine object if your API key is already saved in the SMARTSHEET_ACCESS_TOKEN environment variable.

How-tos

[!IMPORTANT] You need to import SmartsheetEngine and initialize it before any of these example snippets will work.

[!NOTE] Column values from a dataframe will only be updated or appended to a Smartsheet if those columns exist in the Smartsheet. If any dataframe column name doesn't exist in the Smartsheet, that column will be ignored.

Get a Smartsheet as a dataframe

Get the contents of the Smartsheet named finished_test_grid and print the dataframe:

df = S.get_sheet('finished_test_grid').sheet_df
print(df)
         _ss_row_id  number   rating
0   123734752464772     1.0   Lowest
1  7876435046272900     2.0      Low
2  2246935512059780     3.0   Medium
3  2463203892629380     4.0     High
4  6966803519999876     5.0  Highest

[!NOTE] SmartsheetEngine converts a Sheet object to a dataframe when you call S.get_sheet(). And it adds the Smartsheet Row ID to a special _ss_row_id column in that dataframe. This is how it maps dataframe rows to Smartsheet rows.

Append a dataframe to a Smartsheet

Append 2 rows from a dataframe to the Smartsheet named test_grid:

df = pd.DataFrame({
    'number':       [4, 5],
    'rating':       [None, None],
    'missing_col':  ['data', 'ignored'],
})
S.append_sheet_rows('test_grid', df)                          # Append all columns
S.append_sheet_rows('test_grid', df, exclude_cols=['rating']) # Append all columns except the `rating` column
S.append_sheet_rows('test_grid', df, include_cols=['number']) # Append only the `number` column
Before Appending After Appending
Before appending rows After appending rows

Update a Smartsheet from a dataframe

Get a dataframe of the Smartsheet named test_grid, change the dropdown options for the rating column, and then update the column:

import numpy as np

df = S.get_sheet('test_grid').sheet_df

S.update_column_picklist('test_grid', 'rating', ['Lowest', 'Low', 'Medium', 'High', 'Highest'])

conditions = [
    df['number'] == 1,
    df['number'] == 2,
    df['number'] == 3,
    df['number'] == 4,
    df['number'] == 5,
]
choices = [
    'Lowest',
    'Low',
    'Medium',
    'High',
    'Highest',
]
df['rating'] = np.select(conditions, choices)

S.update_sheet_rows('test_grid', df)                          # Update all columns
S.update_sheet_rows('test_grid', df, exclude_cols=['rating']) # Update all columns except the `rating` column
S.update_sheet_rows('test_grid', df, include_cols=['number']) # Update only the `number` column
Before Updating After Updating
Before updating rows After updating rows

Delete Smartsheet rows

[!CAUTION] Be careful to select only the rows from df that you want to delete before you call S.delete_sheet_rows(), because every corresponding row in the Smartsheet will be deleted.

Get a dataframe of the Smartshet named test_grid, select only the rows that have the number 2 or 3 in the number column, and then delete them:

df = S.get_sheet('test_grid').sheet_df

df = df[df['number'].isin([2,3])]

S.delete_sheet_rows('test_grid', df)
Before Deleting After Deleting
Before deleting rows After deleting rows

Update column dropdown options

Change the dropdown options for the rating column to 'Low', 'Medium', and 'High' on the Smartsheet named test_grid:

S.update_column_picklist('test_grid', 'rating', ['Low', 'Medium', 'High'])

Lock or unlock a column

Locks and then unlock the rating column on the Smartsheet named test_grid:

S.lock_column('test_grid', 'rating')
S.unlock_column('test_grid', 'rating')

Hide or unhide a column

Hide and then unhide the rating column on the Smartsheet named test_grid:

S.hide_column('test_grid', 'rating')
S.unhide_column('test_grid', 'rating')

License

Smartsheet Engine is made available under the MIT License

Contributing

  • See CONTRIBUTING for instructions on how to contribute to nwsc

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

smartsheet_engine-0.1.0.post3.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

smartsheet_engine-0.1.0.post3-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file smartsheet_engine-0.1.0.post3.tar.gz.

File metadata

  • Download URL: smartsheet_engine-0.1.0.post3.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for smartsheet_engine-0.1.0.post3.tar.gz
Algorithm Hash digest
SHA256 35bc2c650e719276f1e612e086c6933d785eaad42df8938b0944d72aa328a99c
MD5 ffc522620d2572b172fb4cb5392aa80a
BLAKE2b-256 f46129e2cac47001c62e5f72297f499c7647ad70f14856eda7c10b2d1932e6b3

See more details on using hashes here.

File details

Details for the file smartsheet_engine-0.1.0.post3-py3-none-any.whl.

File metadata

File hashes

Hashes for smartsheet_engine-0.1.0.post3-py3-none-any.whl
Algorithm Hash digest
SHA256 2f6de8a521f0a94df7a551eab20dd99a86d09f4dc9c355f929376d3cee1c67cf
MD5 1d184aaad091bafdd5b8ba9ba1f9a6e1
BLAKE2b-256 9952f5cea9f708b9d94646c6f7fc3178e6a4c835609287f37f83c13796a7f3df

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page