Cellbook
Dynamic computational notebook environment in plain Rust.
-
Cells are defined as
asyncfunctions with#[cell]macro annotations -
Cells are compiled as a
dylibcrate and dynamically reloaded on changes -
cargo-cellbookCLI utility provides a TUI runner and automatic reloader -
Cells have access to a shared store which retains the cell context across reloads
-
Cell output is stored and can be viewed in the TUI runner
-
Integrates with external applications to view images, plots, graphs, etc.
Installation
To create and run a new cellbook project use:
Notebook structure
The notebook consists of an #[init] function (runs on load/reload) and individual #[cell] functions loaded in source order.
use ;
use ;
async
async
async
Context store
Cells can store persistent data in the shared store using store!(), load!(), remove!(), consume!() convenience macros.
Values in the store are serialized with postcard, hence stored types must implement serde's Serialize and Deserialize traits.
// Store a value (variable name becomes the key)
store!?;
// Store with explicit key
store!?;
// Load a value (type has to be specified)
let data: = load!?;
// Remove a value from the store
remove!;
// Load and remove the value from the store
let data: = consume!?;
Crates
| Crate | Description |
|---|---|
./cellbook |
Core library with shared context store, cell registry and declarative macros. |
./cellbook-macros |
Proc macro crate which implements #[cell] and #[init] macros. |
./cargo-cellbook |
Cellbook project runner and command line utility. |
./examples |
Cellbook usage examples and tests. |
Configuration
Configuration is loaded in the following order:
- Built-in defaults
- Global config at
$XDG_CONFIG_HOME/cellbook/config.toml(or platform-specific config dir) - Local config at
./Cellbook.toml
Only fields present in a config file are overridden.
The global configuration file is created with default values on first run:
[]
= true
= 500
= false
#image_viewer = "eog"
[]
= "q"
= "x"
= "o"
= "e"
= "r"
= "E"
= "Enter"
= ["Down", "j"]
= ["Up", "k"]
Keybindings can be a single key or an array of alternative keys.
Supported key names include single characters and Enter, Esc, Tab, Space, Backspace, Delete, Up, Down, Left, Right, Home, End, PageUp, PageDown, F1, etc.
Interface
The cargo cellbook run command opens the terminal-based cellbook runner interface:
It allows running/editing/reloading cells, inspecting cell output, viewing images and more.
It also shows what types are stored in the shared context store.