# Data libraries in Mojo

> Native Mojo data libraries, published as tins on mojoshelf: Parquet, Iceberg, Arrow, Avro, Thrift, the compression codecs, object storage, and Postgres and SQLite clients, with no Python or JVM in the path. Measured against pyarrow, including where they lose. The companion of morca.dev.

Parquet, Iceberg, Arrow, Avro, Thrift and the compression codecs, written in Mojo and published as tins on mojoshelf. No Python or JVM in the path.

[See the tins](https://magmalake.dev/tins) [Performance](https://magmalake.dev/performance) [Browse the org on GitHub](https://github.com/magmalake)

## Native formats

[Parquet](https://magmalake.dev/s/parquet), [Iceberg](https://magmalake.dev/s/iceberg), [Avro](https://magmalake.dev/s/avro) and [Thrift](https://magmalake.dev/s/thrift) are implemented in Mojo, and reads come back as [Arrow](https://magmalake.dev/s/arrow-mlake) arrays. Iceberg reads and writes: scan planning, deletes and deletion vectors, appends, overwrites and schema changes, through a filesystem, REST or SQL catalog. Beside them are [objectstore](https://magmalake.dev/s/objectstore) for local files, HTTP and S3, [postgres](https://magmalake.dev/s/postgres) and [sqlite](https://magmalake.dev/s/sqlite) clients and [threads](https://magmalake.dev/s/threads), and a packaged build of upstream's [flare](https://magmalake.dev/s/flare%5Fmlake) for networking and HTTP. Snappy, deflate and the hashes are Mojo too; libzstd, liblz4, libbrotli and libcurl are linked.

## Measured against pyarrow

Reading a 1M-row Parquet file on one core takes 3.77 ms, against 8.0 ms for pyarrow on one thread. With four workers it takes 1.96 ms, against 2.57 ms for pyarrow on all ten CPUs. Avro decodes manifest-shaped records 10.7× faster than fastavro. It loses too: pyarrow is about 1.17× faster on nested and mixed data, and about 1.1× ahead on an Iceberg scan. [The performance page](https://magmalake.dev/performance) has the numbers and how they were taken.

## Checked against an outside implementation

Each of magmalake's own tins has a correctness oracle, an outside implementation it has to agree with in CI, and its page says which. They are Apache-2.0 and tested on stable Mojo 1.2.0 and the current nightly, on macOS and Linux.

## Installed from mojoshelf

Each tin is a pixi package on [mojoshelf](https://mojoshelf.org), added with one command that brings its dependencies with it. Take only the ones you need. [mojoshelf's guide](https://mojoshelf.org/getting-started) installs the `shelf` command.

```
pixi init app -c https://conda.modular.com/max -c conda-forge && cd app
sed -i.bak 's/^\[workspace\]/[workspace]\npreview = ["pixi-build"]/' pixi.toml
pixi add "mojo-compiler==1.2.0"
pixi shelf add parquet-full-mojo    # Parquet with every codec
```

## The companion of Morca

magmalake is the companion of [Morca](https://morca.dev), which builds data pipelines on these tins. [Dista](https://morca.dev/dista/), which runs Mojo functions across a cluster, is part of Morca. Both are used to build [mojourney.dev](https://mojourney.dev), the census of Mojo on GitHub.

## Three of the tins

Parquet:

```
from parquet import OP_GE, OP_LT, ParquetReader, Predicate, ScalarValue

def main() raises:
    var r = ParquetReader.open("prune.parquet")
    r.select_columns(["k"])
    var preds: List[Predicate] = [
        Predicate("k", OP_GE, ScalarValue.of_int(250)),
        Predicate("k", OP_LT, ScalarValue.of_int(260)),
    ]
    print(r.prune_row_groups(preds), "row groups left")
    var t = r.read_table()
    var k = t.column_i64(0)                 # (values, validity)
```

Footer, page headers, levels and values decoded in Mojo; the rows come back as Arrow arrays. [More](https://magmalake.dev/s/parquet)

Iceberg:

```
from iceberg import Catalog

var table = Catalog.rest("https://polaris.example/api/catalog").load("db.events")
var rows = table.scan().filter('["=", "region", "eu"]').select(["id", "amount"]).to_table()
```

Metadata, manifests, scan planning, Parquet decode, deletes and deletion vectors, S3 IO and the REST catalog — all of it Mojo. [More](https://magmalake.dev/s/iceberg)

Object storage:

```
from objectstore import FileIOResolver

def main() raises:
    var io = FileIOResolver()
    var loc = "file:///tmp/objectstore-demo/data/part-0.bin"
    io.write(loc, "hello, object store".as_bytes())   # makes the directories

    var f = io.new_input(loc)
    print(f.length(), "bytes")
    var tail = f.read_range(-5, 5)                    # the last 5 bytes
```

One resolver for file://, http(s)://, s3://, gs:// and abfss://, with ranged reads and SigV4 signing. [More](https://magmalake.dev/s/objectstore)

## Every tin, layer by layer

Each box links to the tin's page: what it is, how to install it, what proves it and how fast it is. [The tins page](https://magmalake.dev/tins) says more about how they fit together.

Execution

- [restate  0.4.1 durable execution](https://magmalake.dev/s/restate)

Tables & catalogs

- [iceberg  0.11.1 metadata · scan planning · read · write · REST, SQL and filesystem catalogs](https://magmalake.dev/s/iceberg)

File formats

- [parquet  0.13.0 read · write · every encoding · Arrow out](https://magmalake.dev/s/parquet)
- [parquet-full  0.1.11 parquet · plus ZSTD, BROTLI and LZ4](https://magmalake.dev/s/parquet-full)
- [avro  0.4.5 object container files, both ways](https://magmalake.dev/s/avro)
- [arrow-mlake  0.2.1 Arrow layout · C Data Interface · IPC](https://magmalake.dev/s/arrow-mlake)
- [roaring  0.1.3 32/64-bit · deletion vectors](https://magmalake.dev/s/roaring)

Storage & databases

- [objectstore  0.4.2 local · HTTP · S3 · GCS · Azure · concurrent reads](https://magmalake.dev/s/objectstore)
- [sqlite  0.3.5 embedded SQL · the catalog store](https://magmalake.dev/s/sqlite)
- [postgres  0.3.3 libpq · params · COPY](https://magmalake.dev/s/postgres)

Primitives

- [thrift  0.1.3 compact + binary protocol](https://magmalake.dev/s/thrift)
- [zstd  0.1.5 libzstd](https://magmalake.dev/s/zstd)
- [lz4  0.1.4 liblz4](https://magmalake.dev/s/lz4)
- [brotli  0.1.4 libbrotli](https://magmalake.dev/s/brotli)
- [snappy  0.1.4 pure Mojo](https://magmalake.dev/s/snappy)
- [deflate  0.2.0 DEFLATE · gzip · pure Mojo](https://magmalake.dev/s/deflate)
- [hashes  0.1.3 CRC-32 · murmur3 · XXH64](https://magmalake.dev/s/hashes)
- [memory-region  0.1.1 bytes addressed by offset · shared mappings](https://magmalake.dev/s/memory-region)
- [threads  0.6.1 pthreads · atomics · parallel\_for](https://magmalake.dev/s/threads)

Utilities

- [xml  from source pull parser · path queries](https://magmalake.dev/s/xml)
- [lint  0.1.4 mojolint · origin and threading mistakes](https://magmalake.dev/s/lint)
- [k8s  0.1.2 the Kubernetes API from Mojo](https://magmalake.dev/s/k8s)

Cross-implementation oracle

- [iceberg-rs 0.1.3 iceberg-rust behind a C ABI](https://magmalake.dev/s/iceberg-rs)

Republished from upstream

- [json\_mlake 0.4.3 simdjson-backed JSON · ehsanmok/json](https://magmalake.dev/s/json%5Fmlake)
- [flare\_mlake 0.13.2 TCP · TLS · HTTP/1–3 · gRPC · ehsanmok/flare](https://magmalake.dev/s/flare%5Fmlake)
- [mozz\_mlake 0.2.2 fuzzing and property tests · ehsanmok/mozz](https://magmalake.dev/s/mozz%5Fmlake)

Each box is a tin with its own page, its own tests and its own release cadence, and each layer uses only the ones below it; the number beside its name is the version on mojoshelf. Outside the diagram there is only libzstd, liblz4, libbrotli, libcurl, libpq, SQLite, the Restate Rust SDK and the system pthreads, plus OpenSSL and simdjson under the republished packages. A box marked _from source_ works today but isn't on mojoshelf yet. Beside the stack are a second Iceberg implementation kept only to check the native one, and three upstream libraries republished so the tins can depend on them.
