Skip to navigation

Example representation: Workbook with a run Python element action (Beta)

View as Markdown

This documentation describes one or more public beta features that are in development. Beta features are subject to quick, iterative changes; therefore the current user experience in the Sigma service can differ from the information provided in this page.

This page should not be considered official published documentation until Sigma removes this notice and the beta flag on the corresponding feature(s) in the Sigma service. For the full beta feature disclaimer, see Beta features.

This is an example representation of a workbook, retrieved using the Get a workbook endpoint with the query parameter includeContents=true. Representations like this one can be used to create a workbook from code using the Create a workbook endpoint. Each page in this example library includes the code representation of the workbook and step-by-step instructions to create it in the Sigma UI.

Consult this example and others in the Workbook representation example library to:

  • Troubleshoot the formatting of a particular feature in code representation
  • Relate a feature from the Sigma UI to its representation in code
  • Provide context to AI tools used to create workbooks from code

This example representation cannot be used as-is. All identifying details, such as IDs, names, and URLs, have been replaced with randomized ID values or generic substitutions. The format of these contents, like the length of ID values, is preserved for demonstrative purposes. However, this representation cannot be directly used without modification to the base URL, connection details, and more. For more information, see Create and manage workbooks from code.

System and user requirements

To create this workbook in the Sigma UI, you need:

  • An account type with the Create, edit, and publish workbooks and Write Python permissions.
  • A Snowflake connection configured to run Python with access to the sample data and at least Can use permission.

To create a workbook from code, you need the Create, edit, and publish workbooks permission and developer credentials for the Sigma API. See Get started with the Sigma API.

This example uses a table from the Sigma Sample Connection. Your organization might have disabled access to the Sigma sample connection. If so, you can contact an admin to enable it, or use a table from another connection to follow along with this example.

Create the example workbook in the Sigma UI

This example shows a workbook with a button that runs a Python element. The Python code collects the table data into a pandas DataFrame, so the data must fit in the available memory.

To create this workbook:

  1. Go to the Home page and select Create new > Workbook.

  2. From the Add element bar, select Data > Table.

  3. In the Select source modal, search for and select TRIP in the EXAMPLES.BIKES schema.

  4. From the Add element bar, select Data > Python.

  5. Select the Snowflake connection used by the TRIP table.

  6. In the code editor, enter the following code:

    import pandas as pd
    # Retrieve the TRIP element as a Snowpark DataFrame.
    snowpark_df = sigma.get_element("TRIP")
    # Collect the results into a pandas DataFrame and print the first rows.
    df = pd.DataFrame(snowpark_df.collect())
    print(df.head())
  7. Confirm that the table element name is TRIP.

  8. From the Add element bar, select UI > Button.

  9. Select the button, and in the editor panel, select Actions.

  10. Add an action sequence, and configure its action with Action set to Run Python element and Element set to the Python element.

  11. In the document header, select Save as.

  12. Enter a name for the workbook, such as run-python-element-action.

  13. Select Save.

Get a code representation of this workbook

To get a representation of this workbook, follow the steps in Get the code representation of a workbook.

The connectionId values in this example are placeholders. To create a workbook from the representation, replace them with the ID of a Snowflake connection configured for Python in your organization.

workbookId: f1314bfc-272a-4f41-8ff7-2219769be981
workbookUrlId: btA7VuTiY2bYahVxsNogej
createdBy: DKk80kGOQljmHkY32b56EpGzTfFn9
updatedBy: DKk80kGOQljmHkY32b56EpGzTfFn9
createdAt: '2026-11-04T15:17:35.968Z'
updatedAt: '2026-11-04T15:18:07.851Z'
name: run-python-element-action
url: https://aws-api.sigmacomputing.com/org-name/workbook/btA7VuTiY2bYahVxsNogej
path: My Documents/<folder-name>
latestVersion: 2
ownerId: DKk80kGOQljmHkY32b56EpGzTfFn9
isArchived: false
contents:
schemaVersion: 1
elements:
- id: 1LB29Bi0io
kind: table
source:
connectionId: a789a26f-5ab1-4ee8-8d82-80fe4f65a4e9
kind: warehouse-table
path:
- EXAMPLES
- BIKES
- TRIP
columns:
- id: inode-s8QgMVX4bbwLTFiqIAe6Vw/ID
formula: '[TRIP/Id]'
- id: inode-s8QgMVX4bbwLTFiqIAe6Vw/DURATION
formula: '[TRIP/Duration]'
- id: inode-s8QgMVX4bbwLTFiqIAe6Vw/START_DATE
formula: '[TRIP/Start Date]'
- id: inode-s8QgMVX4bbwLTFiqIAe6Vw/START_STATION_NAME
formula: '[TRIP/Start Station Name]'
- id: inode-s8QgMVX4bbwLTFiqIAe6Vw/START_STATION_ID
formula: '[TRIP/Start Station Id]'
- id: inode-s8QgMVX4bbwLTFiqIAe6Vw/END_DATE
formula: '[TRIP/End Date]'
- id: inode-s8QgMVX4bbwLTFiqIAe6Vw/END_STATION_NAME
formula: '[TRIP/End Station Name]'
- id: inode-s8QgMVX4bbwLTFiqIAe6Vw/END_STATION_ID
formula: '[TRIP/End Station Id]'
- id: inode-s8QgMVX4bbwLTFiqIAe6Vw/BIKE_ID
formula: '[TRIP/Bike Id]'
- id: inode-s8QgMVX4bbwLTFiqIAe6Vw/SUBSCRIPTION_TYPE
formula: '[TRIP/Subscription Type]'
- id: inode-s8QgMVX4bbwLTFiqIAe6Vw/ZIP_CODE
formula: '[TRIP/Zip Code]'
order:
- inode-s8QgMVX4bbwLTFiqIAe6Vw/ID
- inode-s8QgMVX4bbwLTFiqIAe6Vw/DURATION
- inode-s8QgMVX4bbwLTFiqIAe6Vw/START_DATE
- inode-s8QgMVX4bbwLTFiqIAe6Vw/START_STATION_NAME
- inode-s8QgMVX4bbwLTFiqIAe6Vw/START_STATION_ID
- inode-s8QgMVX4bbwLTFiqIAe6Vw/END_DATE
- inode-s8QgMVX4bbwLTFiqIAe6Vw/END_STATION_NAME
- inode-s8QgMVX4bbwLTFiqIAe6Vw/END_STATION_ID
- inode-s8QgMVX4bbwLTFiqIAe6Vw/BIKE_ID
- inode-s8QgMVX4bbwLTFiqIAe6Vw/SUBSCRIPTION_TYPE
- inode-s8QgMVX4bbwLTFiqIAe6Vw/ZIP_CODE
- id: RHHl6LnXtF
kind: button
text: Run python element
appearance: filled
actions:
- id: TlWS2gDkHn
trigger: on-click
effects:
- effect: run-python-element
codeElementId: Ua6u2ndaMq
- id: Ua6u2ndaMq
kind: code
code: |-
import pandas as pd
snowpark_df = sigma.get_element("TRIP")
df = pd.DataFrame(snowpark_df.collect())
print(df.head())
connectionId: a789a26f-5ab1-4ee8-8d82-80fe4f65a4e9
pages:
- id: rwzVReJY0Z
name: Page 1
kind: workbook
layout: |
<?xml version="1.0" encoding="utf-8"?>
<Page type="grid" gridTemplateColumns="repeat(24, 1fr)" gridTemplateRows="auto" id="rwzVReJY0Z">
<Element elementId="1LB29Bi0io" gridColumn="1 / 25" gridRow="1 / 21"/>
<Element elementId="RHHl6LnXtF" gridColumn="1 / 25" gridRow="21 / 24"/>
<Element elementId="Ua6u2ndaMq" gridColumn="1 / 25" gridRow="24 / 44"/>
</Page>
documentVersion: 2

Representing the run Python element action

...
actions:
- id: TlWS2gDkHn
trigger: on-click
effects:
- effect: run-python-element
codeElementId: Ua6u2ndaMq
...