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.

allow dict() and .items() on CLIArgs (#7335)

vincent d warmerdam9e6d2e97936e
diff --git a/marimo/_runtime/params.py b/marimo/_runtime/params.py
index 44bebde242..53af28d5c5 100644
--- a/marimo/_runtime/params.py
+++ b/marimo/_runtime/params.py
@@ -27,7 +27,7 @@ from marimo._runtime.requests import (
from marimo._runtime.state import State, StateRegistry
if TYPE_CHECKING:
- from collections.abc import Iterator
+ from collections.abc import Iterable, Iterator
@mddoc
@@ -250,3 +250,9 @@ class CLIArgs:
def to_dict(self) -> SerializedCLIArgs:
return self._params
+
+ def items(self) -> Iterable[tuple[str, ListOrValue[Primitive]]]:
+ return self._params.items()
+
+ def keys(self) -> Iterable[str]:
+ return self._params.keys()
diff --git a/tests/_runtime/test_query_params.py b/tests/_runtime/test_query_params.py
index 6e557308bd..66f6570916 100644
--- a/tests/_runtime/test_query_params.py
+++ b/tests/_runtime/test_query_params.py
@@ -254,3 +254,17 @@ class TestCLIArgs(unittest.TestCase):
def test_delete(self):
with pytest.raises(TypeError):
del self.params["key1"]
+
+ def test_items(self):
+ items = list(self.params.items())
+ assert items == [("key1", "value1"), ("key2", ["value2", "value3"])]
+
+ def test_keys(self):
+ keys = list(self.params.keys())
+ assert keys == ["key1", "key2"]
+
+ def test_dict_generic(self):
+ assert dict(self.params) == {
+ "key1": "value1",
+ "key2": ["value2", "value3"],
+ }