Python
Insert custom Python code
Last updated
Was this helpful?
Insert custom Python code
This tool is currently in Beta and is still being tested. Want to learn more? Like to provide feedback? Please reach out to support@cascade.io
Code allows for custom Python to be executed against tables and objects inside a Cascade Workflow. One can ingest any number of sources and output any number of objects.
Any source linked to the Code tool is accessible using the sources dictionary, and objects can be accessed by their index or by their name. For example:
df1 = sources[0].df # access table by index
df1 = sources["foo"].df # access table by nameSimilarly, workflow variables are available using the variables dictionary. It's recommended to access variables by their name:
foo = variables["foo"]Cascade allows the return of Table, Chart , Json, or Markdown objects for use in downstream tools. Objects can be returned as a single object or an array of objects.
To create and return a table, provide a name and pandas df attribute to the Table object.
return Table (
name = "foo"
df = df1
)To create and return a chart, provide a name and plotly figure attribute to the Chart object.
To create and return a json, provide a name and python dict attribute to the JSON object.
To create and return a json, provide a name and python dict attribute to the JSON object.
Within the Code tool, the following libraries are accessible by default. Import libraries using import:
Library
Description
Import
URLlib
URL Encoding/decoding
import urllib
Last updated
Was this helpful?
Was this helpful?
import plotly.graph_objects as go
fig = go.Figure(
data=[go.Bar(x=[1, 2, 3], y=[1, 3, 2])],
layout=go.Layout(
title=go.layout.Title(text="A Figure Specified By A Graph Object")
)
)
return Chart(name="foo", figure=fig)return Json(name="foo", json={"counter": 1})return Markdown(name="foo", markdown="# Hello")