A lightweight DataFrame and tabular-data library for MoonBit
// API shape (illustrative; see "Quick start" below for a runnable,
// `@moonframe`-prefixed version)
read_csv("sales.csv")
.filter(col("product").eq(lit_str("widget")))
.group_by([col("region")])
.agg([col("revenue").sum()])
.to_markdown()git clone https://github.com/ihb2032/MoonFrame{
"deps": {
"ihb2032/MoonFrame": { "path": "../MoonFrame" }
}
}{
"import": [
{ "path": "ihb2032/MoonFrame", "alias": "moonframe" }
]
}The moon.mod.json / moon.pkg.json snippets above use the JSON manifest form. MoonBit also accepts the newer moon.mod / moon.pkg files (which is what this repository itself uses); the two forms are equivalent.
region,product,revenue,quantity
west,widget,100,10
east,gadget,50,5
west,gadget,70,7
east,widget,30,3
north,widget,40,4
north,gadget,60,6
west,gizmo,90,9
east,gizmo,20,2fn widgets(path : String) -> String raise @moonframe.DataError {
@moonframe.read_csv(path)
.filter(@moonframe.col("product").eq(@moonframe.lit_str("widget")))
.select(@moonframe.cols(["region", "revenue", "quantity"]))
.sort([
(
@moonframe.col("quantity"),
@moonframe.SortOrder::Desc,
@moonframe.NullOrder::NullsLast,
),
])
.to_markdown()
}| region | revenue | quantity |
| ------ | ------- | -------- |
| west | 100 | 10 |
| north | 40 | 4 |
| east | 30 | 3 |let summary = @moonframe.read_csv("sales.csv")
.group_by([@moonframe.col("region")])
.agg([
@moonframe.col("revenue").sum().with_alias("revenue"),
@moonframe.col("quantity").sum().with_alias("quantity"),
])| region | revenue | quantity |
| ------ | ------- | -------- |
| west | 260 | 26 |
| east | 100 | 10 |
| north | 100 | 10 |let result : Result[String, @moonframe.DataError] = Ok(widgets("sales.csv")) catch {
e => Err(e)
}moon run examples/sales_analysis # filter → select → sort → describe → markdown
moon run examples/data_cleaning # drop_nulls → fill_null → CSV round-trip
moon run examples/reporting # group_by → to_html + Vega-Lite spec
moon run examples/expressions # with_columns → filter → agg → lazy + explaintypes/ value types, errors (DataError), schemas
column/ Arrow-style storage — validity Bitmap, BuiltinColumn, Numeric fast path, ColumnStorage seam
series/ Series + column-level stats + the shared reduction / rebuild / key-cell kernels
expr/ composable column expressions — Expr AST, operators / methods, when/then/otherwise, explain
frame/ DataFrame + every operator (one per file) + group_by + join + the expression evaluator (with_columns / select / filter / agg) + to_markdown / to_html
io/ CSV (NyaCSV-backed), JSON, NDJSON read / write + Vega-Lite export
lazy/ deferred query plan — LazyFrame builders, collect / explain, predicate + projection pushdown
moonframe/ facade — re-exports the whole public APImoon check # type-check the workspace
moon test # run all tests (add --target all for every backend)
moon fmt # format sources
moon info # regenerate .mbti interface snapshotsfn compare_string_lex(a : String, b : String) -> Intfn is_decimal_int_literal(s : String) -> Boolfn read_ndjson_with_options(path : String, options : NdjsonReadOptions) -> DataFrame raise DataErrorfn write_csv_with_options(path : String, df : DataFrame, options : CsvWriteOptions) -> Unit raise DataErrorInstall
Download zipA lightweight DataFrame and tabular-data library for MoonBit