Dates

Single date

class marimo.ui.date(start: dt.date | str | None = None, stop: dt.date | str | None = None, value: dt.date | str | None = None, *, label: str = '', on_change: Callable[[dt.date], None] | None = None, full_width: bool = False)

A date picker with an optional start and stop date.

Example.

# initialize the date picker at a given date
date = mo.ui.date(value="2022-01-01")
# when value is omitted, date picker initializes with today's date
date = mo.ui.date()
# create a date picker with bounds
date = mo.ui.date(
    value="2022-06-01",
    start="2022-01-01",
    stop="2022-12-31",
)

Or from a dataframe series:

date = mo.ui.date.from_series(df["column_name"])

Attributes.

  • value: a str (YYYY-MM-DD) or datetime.date object of the chosen date

  • start: the start date

  • stop: the stop date

Initialization Args.

  • start: minimum date selectable; if None, defaults to 01-01-0001

  • stop: maximum date selectable; if None, defaults to 12-31-9999

  • value: default date

    • if None and start and stop are None, defaults to the current day;

    • else if None and start is not None, defaults to start;

    • else if None and stop is not None, defaults to stop

  • label: text label for the element

  • on_change: optional callback to run when this element’s value changes

  • full_width: whether the input should take up the full width of its container

Public methods

from_series(series, **kwargs)

Create a date picker from a dataframe series.

Inherited from UIElement

form([label, bordered, loading, ...])

Create a submittable form out of this UIElement.

send_message(message, buffers)

Send a message to the element rendered on the frontend from the backend.

Inherited from Html

batch(**elements)

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

center()

Center an item.

right()

Right-justify.

left()

Left-justify.

callout([kind])

Create a callout containing this HTML element.

style([style])

Wrap an object in a styled container.

Public Data Attributes:

DATE_FORMAT

start

stop

Inherited from UIElement

value

The element’s current value.

Inherited from Html

text

A string of HTML representing this element.


static from_series(series: DataFrameSeries, **kwargs: Any) date

Create a date picker from a dataframe series.

Date and time

class marimo.ui.datetime(start: dt.datetime | str | None = None, stop: dt.datetime | str | None = None, value: dt.datetime | str | None = None, *, label: str | None = None, on_change: Callable[[dt.datetime | None], None] | None = None, full_width: bool = False)

A datetime picker over an interval.

Example.

datetime_picker = mo.ui.datetime(
    start=dt.datetime(2023, 1, 1),
    stop=dt.datetime(2023, 12, 31, 23, 59, 59),
)

Or from a dataframe series:

datetime_picker = mo.ui.datetime.from_series(df["datetime_column"])

Attributes.

  • value: the selected datetime, possibly None

  • start: the minimum selectable datetime

  • stop: the maximum selectable datetime

Initialization Args.

  • start: the minimum selectable datetime (default: minimum datetime)

  • stop: the maximum selectable datetime (default: maximum datetime)

  • value: default value

  • label: text label for the element

  • on_change: optional callback to run when this element’s value changes

  • full_width: whether the input should take up the full width of its container

Public methods

from_series(series, **kwargs)

Create a datetime picker from a dataframe series.

Inherited from UIElement

form([label, bordered, loading, ...])

Create a submittable form out of this UIElement.

send_message(message, buffers)

Send a message to the element rendered on the frontend from the backend.

Inherited from Html

batch(**elements)

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

center()

Center an item.

right()

Right-justify.

left()

Left-justify.

callout([kind])

Create a callout containing this HTML element.

style([style])

Wrap an object in a styled container.

Public Data Attributes:

DATETIME_FORMAT

start

stop

Inherited from UIElement

value

The element’s current value.

Inherited from Html

text

A string of HTML representing this element.


static from_series(series: DataFrameSeries, **kwargs: Any) datetime

Create a datetime picker from a dataframe series.

Date range

```{eval-rst} .. marimo-embed:

@app.cell
def __():
    date_range = mo.ui.date_range(label="Start Date")
    return

@app.cell
def __():
    mo.hstack([date_range, mo.md(f"Has value: {date_range.value}")])
    return
class marimo.ui.date_range(start: dt.date | str | None = None, stop: dt.date | str | None = None, value: Tuple[dt.date, dt.date] | Tuple[str, str] | None = None, *, label: str | None = None, on_change: Callable[[Tuple[dt.date, dt.date]], None] | None = None, full_width: bool = False)

A date range picker over an interval.

Example.

date_range = mo.ui.date_range(
    start=dt.date(2023, 1, 1), stop=dt.date(2023, 12, 31)
)

Or from a dataframe series:

date_range = mo.ui.date_range.from_series(df["date_column"])

Attributes.

  • value: a tuple of two dates representing the selected range

  • start: the minimum selectable date

  • stop: the maximum selectable date

Initialization Args.

  • start: the minimum selectable date (default: minimum date)

  • stop: the maximum selectable date (default: maximum date)

  • value: default value (tuple of two dates)

  • label: text label for the element

  • on_change: optional callback to run when this element’s value changes

  • full_width: whether the input should take up the full width of its container

Public methods

from_series(series, **kwargs)

Create a date range picker from a dataframe series.

Inherited from UIElement

form([label, bordered, loading, ...])

Create a submittable form out of this UIElement.

send_message(message, buffers)

Send a message to the element rendered on the frontend from the backend.

Inherited from Html

batch(**elements)

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

center()

Center an item.

right()

Right-justify.

left()

Left-justify.

callout([kind])

Create a callout containing this HTML element.

style([style])

Wrap an object in a styled container.

Public Data Attributes:

DATEFORMAT

start

stop

Inherited from UIElement

value

The element’s current value.

Inherited from Html

text

A string of HTML representing this element.


static from_series(series: DataFrameSeries, **kwargs: Any) date_range

Create a date range picker from a dataframe series.