Kestrel kernel for Jupyter
This folder holds a Jupyter kernel for Kestrel. It runs kestrel notebook, which keeps one
native session alive for the notebook.
Install
You need a built kestrel (cargo build --release), Python 3.9 or newer, and ipykernel.
pip install -e editors/jupyter
python3 -m kestrel_kernel.install --user --kestrel "$PWD/target/release/kestrel"
jupyter lab
Pick Kestrel in the launcher. Without --kestrel, the kernel looks for $KESTREL, then
kestrel on PATH, then target/release/kestrel or target/debug/kestrel above this folder.
Set KESTREL_LINK="z m" to link system libraries into every cell.
A running kernel keeps the compiler process and its embedded standard library
from when it started. After rebuilding kestrel or changing std.kesdas,
restart the kernel; otherwise cells keep seeing the old members.
Architecture
This Python package is a Jupyter protocol adapter, not a Kestrel interpreter. It receives
cell text over Jupyter's messaging layer and passes it to one long-running
kestrel notebook process. That Rust process checks, lowers and compiles each cell with
Clang, then runs the native code in the same session. Python never holds a Series,
DataFrame or intermediate value; it only relays text, HTML and errors, and serves completion
from JSON metadata. Executed Kestrel code therefore runs at native speed. The Python layer
costs per-cell protocol and compilation overhead, not per-element interpretation.
A pure Rust kernel using ZeroMQ would remove the Python process, but it would not make the compiled program faster.
How cells run
- A cell is one entry in a session. Names, functions and types stay defined for later cells.
- The value of the last expression in a cell shows. Earlier expressions run and print nothing.
- If a cell does not compile, its statements run one at a time. The ones before the bad statement still take effect, and the error shows line numbers counted from the cell.
?works at the top level. AnErrorends the cell and appears as an error output. The session and its values stay alive.- A runtime stop, such as dividing by zero or an index outside a List, ends the cell and
appears as an error output. The session stays alive, so the names earlier cells bound still
work; the names the failed cell bound are forgotten, as with
?. - A value whose type has an
html()method shows as HTML. DataFrame and Series do. readLine()reads nothing in a notebook.
Completion and types
Completion is type-aware inside a cell and across cells. After
import std.kesdas.{Series, DataFrame}, a value such as
let df := DataFrame([Series([1, 2], name = "v")])
offers the DataFrame members after df.. A selected column keeps its type
through ?: df.col("v")?. offers Series methods, df.col("v")?.mean().
offers Scalar methods, and df.groupBy("v")?. offers GroupBy methods. Fields
such as df.names, s.data and s.index carry their own types too. Namespace
imports of every standard module complete their names, so import std.linalg
makes linalg. offer inverse, svd and the other functions, and
Tensor([0, 0]) keeps the static type Tensor[double, (2,)]. The
kernel uses the same metadata as the VS Code extension, generated with:
node tools/export_kesdas_metadata.js
node tools/export_kesnet_metadata.js
node tools/export_builtins_metadata.js
Run the first after changing editors/vscode-kestrel/out/kesdas.js, the second after
changing the KesNet sources, and the last after changing
editors/vscode-kestrel/out/builtins.js. Each script accepts --check. The
standard-library table also covers List, Array, String, Option and Tensor methods, so
df.names. and df.toCsv(). complete too.
KesNet
import std.kesnet.{Linear, Sequential} brings in layers, losses and the
Variable table. x. offers the tensor methods, model. offers both the
layer's own methods and inherited Module methods such as parameters and
zeroGrad, and chains keep their type: model.forward(x).relu().sum() is a
Variable, .shape() is an Array[Int], and .data() is a
DynTensor[double]. import std.kesnet.optim and import std.kesnet.data
complete their respective names. The table is generated from
src/kesnet.kes, src/kesnet_optim.kes and src/kesnet_data.kes.
kesdas
import std.kesdas.{Series, DataFrame} gives you pandas-style tables. Namespace
imports work too: import std.kesdas as kd gives kd.DataFrame(...),
kd.readCsv(...) and kd.DataFrame.empty().
Tests
KESTREL=../../target/release/kestrel python3 -m unittest discover tests
The analyzer tests do not start a kernel and run in well under a second.
Metadata
Release files for kestrel-kernel 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| kestrel_kernel-0.1.0.tar.gz | 111.4 kB | Without provenance | Details for kestrel_kernel-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| kestrel_kernel-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for kestrel_kernel-0.1.0-py3-none-any.whl |
Total release size: 216.5 kB
Release files / kestrel_kernel-0.1.0.tar.gz
| Download URL | kestrel_kernel-0.1.0.tar.gz |
|---|---|
| Size | 111.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e6f277f03c2b1f1a4cf65b344a8d687cec7c7e866a9cc1ab6b6419ba19935b56
|
|
BLAKE2b-256 checksum How to use checksums |
94bfbe24df7ffb8bbd4161887d34731776719a5a451e77ebe883323656ddbd50
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.4
|
Release files / kestrel_kernel-0.1.0-py3-none-any.whl
| Download URL | kestrel_kernel-0.1.0-py3-none-any.whl |
|---|---|
| Size | 105.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
43a889bf66a9eeaff2b60149ae313d01443d2323f48b7c6ee74c186284d7344f
|
|
BLAKE2b-256 checksum How to use checksums |
9d95662d0cf87bbc41a12e460d2c959a24121db198f111f0d86135087bb76f94
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.4
|
Security for kestrel-kernel 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.