Skip to content

Miscellaneous

marimo.running_in_notebook

running_in_notebook() -> bool

Returns True if running in a marimo notebook, False otherwise

marimo.defs

defs() -> tuple[str, ...]

Get the definitions of the currently executing cell.

RETURNS DESCRIPTION
tuple[str, ...]

tuple[str, ...]: A tuple of the currently executing cell's defs.

marimo.refs

refs() -> tuple[str, ...]

Get the references of the currently executing cell.

RETURNS DESCRIPTION
tuple[str, ...]

tuple[str, ...]: A tuple of the currently executing cell's refs.

marimo.notebook_dir

notebook_dir() -> Path | None

Get the directory of the currently executing notebook.

RETURNS DESCRIPTION
Path | None

pathlib.Path | None: A pathlib.Path object representing the directory of the current notebook, or None if the notebook's directory cannot be determined.

Examples:

data_file = mo.notebook_dir() / "data" / "example.csv"
# Use the directory to read a file
if data_file.exists():
    print(f"Found data file: {data_file}")
else:
    print("No data file found")

marimo.notebook_location

notebook_location() -> PurePath | None

Get the location of the currently executing notebook.

In WASM, this is the URL of webpage, for example, https://my-site.com. For nested paths, this is the URL including the origin and pathname. https://<my-org>.github.io/<my-repo>/folder.

In non-WASM, this is the directory of the notebook, which is the same as mo.notebook_dir().

Examples:

In order to access data both locally and when a notebook runs via WebAssembly (e.g. hosted on GitHub Pages), you can use this approach to fetch data from the notebook's location.

import polars as pl

data_path = mo.notebook_location() / "public" / "data.csv"
df = pl.read_csv(str(data_path))
df.head()
RETURNS DESCRIPTION
PurePath | None

Path | None: A Path object representing the URL or directory of the current notebook, or None if the notebook's directory cannot be determined.

Inspect

Use mo.inspect() to explore Python objects with a rich, interactive display of their attributes, methods, and documentation.

Example

import marimo as mo

# Inspect a class
mo.inspect(list, methods=True)

# Inspect an instance
my_dict = {"key": "value"}
mo.inspect(my_dict)

# Show all attributes including private and dunder
mo.inspect(my_dict, all=True)

marimo.inspect

inspect(
    obj: object,
    *,
    help: bool = False,
    methods: bool = False,
    docs: bool = True,
    private: bool = False,
    dunder: bool = False,
    sort: bool = True,
    all: bool = False,
    value: bool = True
)

Bases: Html

Inspect a Python object.

Displays objects with their attributes, methods, and documentation in a rich HTML format. Useful for exploring objects that lack a rich repr.

PARAMETER DESCRIPTION
obj

The object to inspect.

TYPE: object

help

Show full help text (otherwise just first paragraph).

TYPE: bool DEFAULT: False

methods

Show methods.

TYPE: bool DEFAULT: False

docs

Show documentation for attributes/methods.

TYPE: bool DEFAULT: True

private

Show private attributes (starting with '_').

TYPE: bool DEFAULT: False

dunder

Show dunder attributes (starting with '__').

TYPE: bool DEFAULT: False

sort

Sort attributes alphabetically.

TYPE: bool DEFAULT: True

all

Show all attributes (methods, private, and dunder).

TYPE: bool DEFAULT: False

value

Show the object's value/repr.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
Html

An Html object.

Example
mo.inspect(obj, methods=True)

text property

text: str

A string of HTML representing this element.

batch

batch(**elements: UIElement[JSONType, object]) -> batch

Convert an HTML object with templated text into a UI element.

This method lets you create custom UI elements that are represented by arbitrary HTML.

Example
user_info = mo.md(
    '''
    - What's your name?: {name}
    - When were you born?: {birthday}
    '''
).batch(name=mo.ui.text(), birthday=mo.ui.date())

In this example, user_info is a UI Element whose output is markdown and whose value is a dict with keys 'name' and 'birthday' (and values equal to the values of their corresponding elements).

PARAMETER DESCRIPTION
elements

the UI elements to interpolate into the HTML template.

TYPE: UIElement[JSONType, object] DEFAULT: {}

callout

callout(
    kind: Literal[
        "neutral", "danger", "warn", "success", "info"
    ] = "neutral"
) -> Html

Create a callout containing this HTML element.

A callout wraps your HTML element in a raised box, emphasizing its importance. You can style the callout for different situations with the kind argument.

Examples:

mo.md("Hooray, you did it!").callout(kind="success")
mo.md("It's dangerous to go alone!").callout(kind="warn")

center

center() -> Html

Center an item.

Example
mo.md("# Hello, world").center()
RETURNS DESCRIPTION
Html

An Html object.

left

left() -> Html

Left-justify.

Example
mo.md("# Hello, world").left()
RETURNS DESCRIPTION
Html

An Html object.

right

right() -> Html

Right-justify.

Example
mo.md("# Hello, world").right()
RETURNS DESCRIPTION
Html

An Html object.

style

style(
    style: Optional[dict[str, Any]] = None, **kwargs: Any
) -> Html

Wrap an object in a styled container.

Example
mo.md("...").style({"max-height": "300px", "overflow": "auto"})
mo.md("...").style(max_height="300px", overflow="auto")
PARAMETER DESCRIPTION
style

an optional dict of CSS styles, keyed by property name

TYPE: Optional[dict[str, Any]] DEFAULT: None

**kwargs

CSS styles as keyword arguments

TYPE: Any DEFAULT: {}