Polars-PHP Documentation#

A PHP extension bringing the power of Polars DataFrames to PHP.

Note

Some features are not yet available. Look in GitHub issues for updates.

Installation#

Install with PIE (Packagist)#

The extension is published as a PIE package on Packagist:

pie install pjpawel/polars-php

On tagged releases PIE installs a pre-built asset from the GitHub release when one matches the platform (Windows always uses the pre-built DLL); otherwise it builds from source with cargo through the phpize / ./configure / make flow (see pie/ in the repository). Source builds require PHP 8.3+, the Rust toolchain, and phpize. Either way the extension is enabled as extension=polars in php.ini.

Pre-built Binaries#

Pre-built binaries are available for Linux, macOS and Windows. There were compiled for PHP 8.3, 8.4, 8.5 and 8.6. Download the appropriate binary for your platform from the releases page.

Building from Source#

# Clone the repository
git clone https://github.com/pjpawel/polars-php.git
cd polars-php/php

# Build the extension
composer build:relese

# Verify installation (Linux/macOS)
php -d extension=../target/release/libpolars_php.so -m | grep polars

# On Windows the extension is a DLL built with the nightly Rust toolchain:
# cargo +nightly build --release
php -d extension=..\target\release\polars_php.dll -m

Quick Example#

<?php

use Polars\DataFrame;
use Polars\Expr;

// Create a DataFrame from array
$df = new DataFrame([
    'name' => ['Alice', 'Bob', 'Charlie'],
    'age' => [25, 30, 35],
    'city' => ['NYC', 'LA', 'Chicago']
]);

echo $df;

// Filter using expressions
$expr = Expr::col('age')->gt(25);
$result = $df->select([$expr]);

API Reference#

Requirements#

  • PHP 8.3+

  • Linux, macOS or Windows (on Windows use the nightly Rust toolchain)

  • Rust toolchain (for building from source)

License#

MIT License – see LICENSE for details.