Cheat sheet
Comprehensive documentation of the SDK (the datacards
object) is coming soon. For now, here is an overview of the most common commands you will use in DataCards notebooks.
Publish a variable
datacards.publish.variable(key="hello_world", value=42)
Currently, the key
property of DataCards variables must conform to the Python variable naming rules . Publishing variables with non-conforming key
names is possible, but they will throw an error when they are consumed.
Consume a variable
my_value = datacards.consume.variable.hello_world()
When consuming variables, don’t forget the parentheses ()
! Omitting them
will result in the consumed value being typecast as a string, which may not be
desired behaviour.
Input cards automatically publish a variable, so consuming it uses the same syntax:
my_value = datacards.consume.variable.my_input_123()
Publish card
datacards.publish.card(
type='number',
value=42,
label='Number',
description='Description',
unit='Unit',
logic_view_size=(2,1)
)
Set card position and size in deck
A card’s size and position in a deck can be set programmatically using the layout
argument.
datacards.publish.card(
type='number',
value=42,
label='Number',
logic_view_size=(2,1)
layout=[{"size": (4,3), "position": (1,7), "deck": "default-deck"}],
)
In the above example, the published card is:
- 4 grid squares wide by 3 grid squares tall,
- positioned 1 grid square from the left and 7 grid squares from the top,
- published to the default deck.
Install a package
To install a package in your project, execute a cell containing:
!uv pip install <package>
or:
!pip install <package>
DataCards uses the uv
package manager under the hood, so whichever command you use, the effect will be the same. Packages are installed globally and are available to all notebooks in the project.