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.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
fix: hide sql in wasm. add example querying a remote csv (#1750)
Myles Scolnick84533cf89e31
diff --git a/examples/sql/electric_vehicles.py b/examples/sql/electric_vehicles.pynew file mode 100644index 0000000000..7caf34ccc2--- /dev/null+++ b/examples/sql/electric_vehicles.py@@ -0,0 +1,215 @@+import marimo++__generated_with = "0.7.0"+app = marimo.App(width="medium")+++def __(mo):+ mo.md(+ r"""+ # Electric Vehicle Population Data++ > This dataset shows the Battery Electric Vehicles (BEVs) and Plug-in Hybrid Electric Vehicles (PHEVs) that are currently registered through Washington State Department of Licensing (DOL).+ """+ )+ return+++def __(mo):+ evs = mo.sql(+ f"""+ create or replace table evs as+ from 'https://datasets.marimo.app/gov/Electric_Vehicle_Population_Data.csv';+ select * from evs+ """+ )+ return evs,+++def __(mo, years):+ all_years = years["Model Year"]+ year_select = mo.ui.multiselect.from_series(years["Model Year"])+ return all_years, year_select+++def __(cities, mo):+ all_cities = cities["City"]+ city_select = mo.ui.multiselect.from_series(cities["City"])+ return all_cities, city_select+++def __(makes, mo):+ all_makes = makes["Make"]+ make_select = mo.ui.multiselect.from_series(makes["Make"])+ return all_makes, make_select+++def __(city_select, make_select, mo, year_select):+ mo.hstack([year_select, city_select, make_select], justify="space-between")+ return+++def __(alt, grouped_by_city, mo):+ _chart = (+ alt.Chart(grouped_by_city)+ .mark_bar()+ .encode(+ y=alt.Y("City", type="nominal", sort="-x"),+ x=alt.X("sum(count)", type="quantitative"),+ color=alt.Color("Model Year", type="nominal"),+ )+ .properties(title="Top 10 City", width="container")+ )+ chart1 = mo.ui.altair_chart(_chart, chart_selection=False)+ return chart1,+++def __(alt, grouped_by_make, mo):+ _chart = (+ alt.Chart(grouped_by_make)+ .mark_bar()+ .encode(+ y=alt.Y("Make", type="nominal", sort="-x"),+ x=alt.X("sum(count)", type="quantitative"),+ color=alt.Color("Model Year", type="nominal"),+ )+ .properties(title="Top 10 Make", width="container")+ )+ chart2 = mo.ui.altair_chart(_chart, chart_selection=False)+ return chart2,+++def __(chart1, chart2, mo):+ mo.hstack([chart1, chart2], widths="equal")+ return+++def __(mo):+ mo.md(r"## Appendix")+ return+++def __(evs, mo):+ years = mo.sql(+ f"""+ SELECT DISTINCT CAST(evs."Model Year" AS VARCHAR) AS "Model Year" FROM evs;+ """+ )+ return years,+++def __(evs, mo):+ cities = mo.sql(+ f"""+ SELECT DISTINCT CAST(evs."City" AS VARCHAR) AS "City" FROM evs WHERE "City" != 'null';+ """+ )+ return cities,+++def __(evs, mo):+ makes = mo.sql(+ f"""+ SELECT DISTINCT CAST(evs."Make" AS VARCHAR) AS "Make" FROM evs;+ """+ )+ return makes,+++def __(+ cast_to_ints,+ city_select,+ evs,+ make_select,+ mo,+ sql_list,+ year_select,+):+ grouped_by_city = mo.sql(+ f"""+ SELECT COUNT(*) AS "count", "City", "Model Year"+ FROM evs+ WHERE+ {sql_list("Model Year", cast_to_ints(year_select.value))}+ AND+ {sql_list("Make", make_select.value)}+ AND+ {sql_list("City", city_select.value)}+ GROUP BY "City", "Model Year"+ HAVING COUNT(*) > 1+ ORDER BY "count" DESC+ """+ )+ return grouped_by_city,+++def __(+ cast_to_ints,+ city_select,+ evs,+ make_select,+ mo,+ sql_list,+ year_select,+):+ grouped_by_make = mo.sql(+ f"""+ SELECT COUNT(*) AS "count", "Make", "Model Year"+ FROM evs+ WHERE+ {sql_list("Model Year", cast_to_ints(year_select.value))}+ AND+ {sql_list("Make", make_select.value)}+ AND+ {sql_list("City", city_select.value)}+ GROUP BY "Make", "Model Year"+ HAVING COUNT(*) > 1+ ORDER BY "count" DESC+ """+ )+ return grouped_by_make,+++def __():+ def sql_list(column, items):+ if not items:+ return "True == True"+ literals = [as_literal(i) for i in items]+ return f"\"{column}\" IN ({','.join(literals)})"+++ def as_literal(v):+ return f"'{v}'" if isinstance(v, str) else str(v)+++ def cast_to_ints(items):+ return [int(i) for i in items]+ return as_literal, cast_to_ints, sql_list+++def __():+ # Imports+ import marimo as mo+ import altair as alt+ return alt, mo+++if __name__ == "__main__":+ app.run()diff --git a/frontend/src/components/editor/renderers/CellArray.tsx b/frontend/src/components/editor/renderers/CellArray.tsxindex 834a3e68bc..ff2e376dc4 100644--- a/frontend/src/components/editor/renderers/CellArray.tsx+++ b/frontend/src/components/editor/renderers/CellArray.tsx@@ -41,6 +41,7 @@ import { MarkdownLanguageAdapter } from "@/core/codemirror/language/markdown";import { capabilitiesAtom } from "@/core/config/capabilities";import { Tooltip } from "@/components/ui/tooltip";import { Kbd } from "@/components/ui/kbd";+import { isPyodide } from "@/core/pyodide/utils";interface CellArrayProps {notebook: NotebookState;@@ -207,37 +208,39 @@ const AddCellButtons: React.FC = () => {<SquareMIcon className="mr-2 size-4 flex-shrink-0" />Markdown</Button>- <Tooltip- content={- sqlCapabilities ? null : (- <span>- Requires duckdb:{" "}- <Kbd className="inline">pip install duckdb</Kbd>- </span>- )- }- delayDuration={100}- asChild={false}- >- <Button- className={buttonClass}- variant="text"- size="sm"- disabled={!sqlCapabilities}- onClick={() => {- maybeAddMarimoImport(autoInstantiate, createNewCell);-- createNewCell({- cellId: "__end__",- before: false,- code: new SQLLanguageAdapter().defaultCode,- });- }}+ {!isPyodide() && (+ <Tooltip+ content={+ sqlCapabilities ? null : (+ <span>+ Requires duckdb:{" "}+ <Kbd className="inline">pip install duckdb</Kbd>+ </span>+ )+ }+ delayDuration={100}+ asChild={false}>- <DatabaseIcon className="mr-2 size-4 flex-shrink-0" />- SQL- </Button>- </Tooltip>+ <Button+ className={buttonClass}+ variant="text"+ size="sm"+ disabled={!sqlCapabilities}+ onClick={() => {+ maybeAddMarimoImport(autoInstantiate, createNewCell);++ createNewCell({+ cellId: "__end__",+ before: false,+ code: new SQLLanguageAdapter().defaultCode,+ });+ }}+ >+ <DatabaseIcon className="mr-2 size-4 flex-shrink-0" />+ SQL+ </Button>+ </Tooltip>+ )}<Tooltipcontent={aiEnabled ? null : <span>Enable via settings</span>}delayDuration={100}diff --git a/marimo/_cli/parse_args.py b/marimo/_cli/parse_args.pyindex caf8b49e49..2bf7db641d 100644--- a/marimo/_cli/parse_args.py+++ b/marimo/_cli/parse_args.py@@ -26,7 +26,7 @@ def parse_args(for arg in args:if arg.startswith(("-", "--")):new_args.append(arg)- else:+ elif new_args:new_args[-1] += f" {arg}"for arg in new_args:diff --git a/tests/_cli/test_parse_args.py b/tests/_cli/test_parse_args.pyindex d1f15c480a..e4a7d23163 100644--- a/tests/_cli/test_parse_args.py+++ b/tests/_cli/test_parse_args.py@@ -8,6 +8,10 @@ def test_parse_args_no_args():assert parse_args(("")) == {}+def test_parse_args_non_dashed():+ assert parse_args(("foo", "bar")) == {}++def test_parse_args_with_integer():args = ("--count=10",)expected = {"count": 10}