juphyter

Data & Workflow · Tables, pipelines, and notebooks

juphyter

A Jupyter and Quarto kernel for PHP.

Install
composer global require phpstats/juphyter
export PATH="$(composer global config bin-dir --absolute):$PATH"
juphyter install --create-venv ~/.venvs/juphyter
export PATH="$HOME/.venvs/juphyter/bin:$PATH"
juphyter doctor
Requires
mbstring and tokenizer PHP extensions Composer Python 3 with the venv module
Optional
pcntl PHP extension (interrupting a running cell with the stop button) Quarto (rendering .qmd documents) vl-convert (static phiz plot images in PDF and Word output) phibble, phplyr, and phiz (data frame tables and charts in notebooks)
Platforms
macOS Linux

juphyter runs PHP cells in JupyterLab notebooks and in Quarto documents. It registers a Jupyter kernel, so JupyterLab lists PHP in its launcher and Quarto runs the {php} cells of a .qmd that names the kernel. It corresponds to IRkernel, which runs R in Jupyter.

One PHP session lasts across cells, including use imports and declared functions and classes. A cell's last value is its output: a phibble data frame appears as an HTML table and a phiz plot as a chart, and tracebacks name the cell and the line. A notebook inside a Composer project can use that project's classes and packages, because the kernel loads the nearest vendor/autoload.php above it.

Example

$mpg = \Phibble\DataFrame::fromRows(\Phiz\Datasets::mpg());

$mpg |>
    group_by('class') |>
    summarize(models: n(), hwy: mean('hwy')) |>
    arrange(desc('hwy'));
$mpg = \Phibble\DataFrame::fromRows(\Phiz\Datasets::mpg());

phplyr($mpg)
    ->groupBy('class')
    ->summarize(models: n(), hwy: mean('hwy'))
    ->arrange(desc('hwy'))
    ->get();

Output · 7 × 3

  class      models   hwy
  <chr>       <int> <dbl>
1 compact        47  28.3
2 subcompact     35  28.1
3 midsize        41  27.3
4 2seater         5  24.8
5 minivan        11  22.4
6 suv            62  18.1
7 pickup         33  16.9