Parameter types¶
Times Square notebooks use parameters to pass inputs into the notebook. Different types of parameters are supported, and these types inform the interface for users to enter values and the validation that’s performed on those values. This page lists the different types of parameters that are supported. For information about the sidecar metadata file as a whole, see Sidecar metadata YAML file reference.
Strings¶
A string is the most basic parameter type that supports any kind of text. There isn’t any validation performed on the string.
parameters:
message:
type: string
description: A message to display.
default: "Hello world"
message = "Hello world"
Dates and times¶
Times Square does not yet provide special support for dates and times. In the meantime you can use a string parameter and provide validation in the notebook’s code.
Example with a date¶
parameters:
date:
type: string
description: An ISO8601 date
default: "2024-01-01"
date = "2024-01-01"
from datetime import datetime
try:
dt = datetime.strptime(date, "%Y-%m-%d")
except ValueError:
raise ValueError("Invalid date format. Expected YYYY-MM-DD")
Examples with a date and time¶
parameters:
date:
type: string
description: An ISO8601 date and time
default: "2024-01-01T12:00:00+00:00"
date = "2024-01-01T12:00:00+00:00"
from datetime import datetime
try:
dt = datetime.strptime(date, "%Y-%m-%dT%H:%M:%S%z")
except ValueError:
raise ValueError("Invalid date format. Expected YYYY-MM-DDTHH:MM:SS+HH:MM")
Integers¶
For decimal numbers, use the integer
type.
In your code, cast the value to a Python integer for use in calculations:
parameters:
number:
type: integer
description: An integer
default: 42
number = "42"
number = int(number)
Validation constraints¶
The integer
type supports validation constraints.
You can specify minimum values and maximum values (both or either):
parameters:
number:
type: integer
description: An integer
default: 42
minimum: 0
maximum: 100
Floating point numbers¶
For floating point numbers, use the number
type.
In your code, cast the value to a Python float for use in calculations:
parameters:
number:
type: number
description: A number
default: 27.5
number = "27.5"
number = float(number)
Validation constraints¶
Like the integer
type, the number
type supports validation constraints.
You can specify minimum values and maximum values (both or either):
parameters:
number:
type: number
description: A number
default: 27.5
minimum: 0
maximum: 100
Booleans¶
Boolean (true/false) values are supported with the boolean
type.
The string representation is based on JSON’s true
and false
values.
To convert the string into a Python boolean, you can compare the string:
parameters:
switch_param:
type: boolean
description: A boolean
default: true
switch_param = "true"
switch_param = switch_param == "true"