Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

Using XDG_STATE_HOME environment variable to support the Linux XDG Base Directory (#6048)

TDYQ-Liuec7670948c26
diff --git a/marimo/_utils/config/config.py b/marimo/_utils/config/config.py
index 17b702f2d9..0b327a8a98 100644
--- a/marimo/_utils/config/config.py
+++ b/marimo/_utils/config/config.py
@@ -3,13 +3,27 @@ from __future__ import annotations
import os
from dataclasses import asdict
+from pathlib import Path
from tempfile import TemporaryDirectory
from typing import Any, Optional, TypeVar
from marimo._utils.parse_dataclass import parse_raw
from marimo._utils.toml import is_toml_error, read_toml
-ROOT_DIR = ".marimo"
+
+def xdg_state_marimo_dir() -> Path:
+ if os.name == "posix":
+ # for Linux/macOS/Unix
+ _user_home = Path.home()
+ _state_home = os.environ.get(
+ "XDG_STATE_HOME", _user_home / ".local/state"
+ )
+ return Path(_state_home).relative_to(_user_home) / "marimo"
+ else:
+ return Path(".marimo")
+
+
+ROOT_DIR = xdg_state_marimo_dir()
T = TypeVar("T")