phpstats / phibble
A typed, immutable in-memory data frame for PHP.
Requires
- php: >=8.3 <8.6
- ext-mbstring: *
- ext-pdo: *
- symfony/polyfill-php84: ^1.31
Requires (Dev)
- illuminate/database: ^12.0
- pestphp/pest: ^4.0
- phpstats/phiz: dev-main
- squizlabs/php_codesniffer: ^3.13
Suggests
- ext-pdo_sqlite: Used by the test suite for the PDO source
- ext-phit: Native CSV reading with Phit\read_csv (phit 0.1.1 or later) and Phit\CsvReader for chunks (phit 0.2.0 or later), from phpstats/phit
- ext-php_polars: The Polars backend (Phibble\Polars\PolarsTable), from phpstats/phpolars
- illuminate/database: Laravel integration: Collection::toDataFrame() and query builder ->phibble() / ->toDataFrame() macros (auto-discovered)
Provides
None
Conflicts
None
Replaces
None
README
phibble is a data frame library for PHP, following R's tibble and readr. A
DataFrame holds typed columns, treats null as NA, and returns a new table
from every operation. It is the shared table type for
phplyr,
phit,
phpolars,
phiz, and
CmdStanPHP.
Documentation: https://phpstats.github.io/phibble/
Install
composer require phpstats/phibble
phibble supports PHP 8.3, 8.4, and 8.5, and CI tests all three. It requires
the mbstring and PDO extensions. On PHP 8.5, pipelines can also use the |>
operator.
Example
In a new directory, install phibble and download the Palmer penguins data:
composer require phpstats/phibble curl -LO https://raw.githubusercontent.com/phpstats/phibble/v0.5.1/docs/data/penguins.csv
Then save this script as summary.php and run php summary.php:
<?php require __DIR__.'/vendor/autoload.php'; use Phibble\DataFrame; use function Phibble\Expr\{col, mean, n}; $penguins = DataFrame::fromCsv('penguins.csv'); echo $penguins ->filter(col('body_mass')->isNa()->not()) ->groupBy(['species']) ->summarize(['n' => n(), 'mass' => mean(col('body_mass'))]), "\n";
# A tibble: 3 × 3
species n mass
<chr> <int> <dbl>
1 Adelie 151 3701.
2 Chinstrap 68 3733.
3 Gentoo 123 5076.
Features
- tibble:
tibble(),tribble(),as_tibble(),addRow(),addColumn(),enframe(),deframe(), name repair, strict column access, and printing andglimpse()that match tibble's output. - Types: float, int, bool, string, factor (with ordered factors and the
forcats functions), date, datetime, and list-columns. Casts follow R's
as.*()rules. - Input and output: CSV with readr's options and type guessing (and the phit extension's native reader when it is loaded), JSON, PDO queries, Laravel and Doctrine query builders, and Laravel collections.
- Verbs:
select,filter,mutate,arrange,groupBy,summarize,distinct, joins (includingjoin_bycomparisons and rolling joins),nest,unnest, and tidyr's spec-based pivots, with dplyr 1.1 semantics. - Expressions:
Phibble\Exprdescribes computations as inspectable, serializable trees that follow dplyr's semantics, with stringr and lubridate basics. - SQL tables:
SqlTablecompiles verbs to SQL for SQLite, PostgreSQL, and MySQL, like dbplyr. Anything SQL cannot compute exactly runs in memory. - Laravel:
->toDataFrame()and->phibble()on queries and collections. - Backends:
DataFrame(in memory),SqlTable(databases), andPolarsTable(Polars, with the php_polars extension from phpolars) are all part of phibble and implement one Table contract, so the same pipeline runs on each.
Development
composer install vendor/bin/pest
See the development guide for the R comparison scripts, database tests, and documentation build.