Logic Bricks

A Logic Brick is a function that a dagboard runs as one of its steps. It takes the values of the Input Bricks and Logic Bricks wired into it, and its result goes on to the next Logic Bricks and to the Viz Bricks.

This page shows Logic Bricks in Python. They can be written in R too, which R bricks shows.

Write a Logic Brick

Make's Logic Brick, in the sidebar, opens the Logic Brick editor. A Logic Brick is a Python module with a function named handle:

def handle(x: float, exponent: float = 2) -> float:
    '''
    Raises a number to a power.

    :param x: The number.
    :param exponent: The power to raise it to; 2 when left empty.
    :return: x to the power of exponent.
    '''
    return x ** exponent

input_fixtures = dict(x=3.0)

Try it

A dagboard stores a Logic Brick's name, its inputs' names and its output's type, so changing one of them breaks the dagboards that use it. To rename a Logic Brick or an input, add a new Logic Brick and keep the old one.

A Link Brick is a Logic Brick that reads from or writes to an API, a file or a database, such as a client of a web API. The sidebar and Search list Link Bricks apart from the other Logic Bricks, and a dagboard's + adds one as it adds a Logic Brick.

Timeseries

The charts over time, such as Line and Bar, take a pd.Series of floats with a two-level index, (timestamp, id), and draw one line per id. The library's Logic Bricks make and take that shape:

The library

The app's default sources hold two libraries of Logic Bricks, which every dagboard can use and which you can read as examples (The default sources):

A library Logic Brick's name starts with its library, such as brickutils/series.multiply. The Logic Bricks you write keep the name you give them, and show as private.

What holds in the browser

Logic Bricks run in Python in your browser, so a few things differ from Python on a computer:

Python's packages

dagboard.ai's environment is the same in every browser, with one version of each package:

Nothing for plots or controls, such as matplotlib, seaborn, Plotly, Bokeh, Altair or ipywidgets: widgets show and take a dagboard's data. Nothing from PyPI or micropip.

pandas' features that need an optional package load it too, as if the Logic Brick imported it: python-calamine for read_excel(..., engine="calamine"), and SciPy for weighted rolling windows (win_type), corr(method="kendall") and the SciPy methods of interpolate, such as "spline". When the method comes from a variable, import the package in the Logic Brick.

A library of Logic Bricks in a repo or a folder declares the packages its Logic Bricks import, each with the oldest version they run on, in the pyenv.json at its root:

{
  "format": 4,
  "python": ">=3.13",
  "packages": { "scipy": ">=1.14.1", "statsmodels": ">=0.14.6" }
}

A library made before, which declares them in its pyproject.toml's [tool.bricks] table, works too.

Opening a dagboard that uses the library starts loading them, so its Logic Bricks wait less. A library's Logic Brick that imports an optional package its library doesn't declare fails, with an error that says what to add. A library that declares a package outside the environment can't be added as a source. The default sources' libraries declare theirs the same way. The Logic Bricks you write in the app may import any of the optional packages.

Next: R bricks