phpolars

Data & Workflow · Tables, pipelines, and notebooks

phpolars

Polars data frames for PHP

Install
pie install phpstats/phpolars
Requires
PIE
Builds with
Rust toolchain libclang
Platforms
Linux macOS NTS (non-thread-safe) PHP

phpolars is a native PHP extension, written in Rust, that brings the Polars columnar engine to PHP. PIE installs it as the php_polars extension for PHP 8.3, 8.4, and 8.5 on Linux and macOS.

phibble's PolarsTable holds a table in Polars through this extension, so phplyr pipelines can run in Polars. phibble and phplyr work without phpolars.

In phplyr's backend benchmark (Apple M5 Ultra, PHP 8.5.10, October 2026), pipelines on a PolarsTable ran 1.3 to 15 times faster than on an in-memory phibble data frame. The pipeline that filters with a PHP closure gained the least.

Example

use function Phpolars\{col, len, read_csv};

$sales = read_csv('sales.csv', tryParseDates: true);

$top = $sales
    ->filter(col('units')->gt(0))
    ->withColumns(col('units')->mul(col('price'))->alias('revenue'))
    ->groupBy('product', maintainOrder: true)
    ->agg(col('revenue')->sum()->round(2), ['orders' => len()], col('price')->mean()->round(2)->alias('avg_price'))
    ->sort('revenue', descending: true);

echo $top;

Output

shape: (4, 4)
┌─────────┬─────────┬────────┬───────────┐
│ product ┆ revenue ┆ orders ┆ avg_price │
│ ---     ┆ ---     ┆ ---    ┆ ---       │
│ str     ┆ f64     ┆ u32    ┆ f64       │
╞═════════╪═════════╪════════╪═══════════╡
│ cherry  ┆ 1307.38 ┆ 44     ┆ 4.09      │
│ banana  ┆ 1285.76 ┆ 48     ┆ 4.35      │
│ apple   ┆ 1227.68 ┆ 42     ┆ 4.38      │
│ date    ┆ 1153.58 ┆ 41     ┆ 4.46      │
└─────────┴─────────┴────────┴───────────┘

Run it live

All vignettes →