---
title: Using BPL notebooks
description: BPL cells, Python magics, glyph entry and help.
---
## BPL kernel

Install with `pip install basedpl`, then select **BasedPL** in Jupyter's kernel menu. Write BPL directly in each code cell. Names persist between cells.

```bpl
v←ι5
+/v
```

Press Shift-Tab to inspect a name or glyph. `]help name` shows help. `]help name -source` shows the source. See [Getting started](getting-started.md) for an executable BPL tutorial.

<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

## Python magics

[`create_magic()`](magics.md#create_magic) registers `%bpl` and `%%bpl` in a Python notebook. `%load_ext basedpl.notebooks` is equivalent. Run `bpl-install-magic` once to load the extension automatically in IPython and Jupyter.

The magics and Python code that imports `bpl` share one persistent workspace, `basedpl.bpl`. `%bpl ]clear` removes every name from the shared workspace.

```python
from basedpl.notebooks import create_magic
magic = create_magic()
```

Hold the left Alt or Option key and press a key from the [glyph reference](glyphs.md#typing-glyphs): Alt-h types [`←`](https://bpl.fast.ai//glyphs/left-arrow.html), Alt-m types [`×`](https://bpl.fast.ai//glyphs/times.html) and Alt-u types [`÷`](https://bpl.fast.ai//glyphs/obelus.html). Some glyphs take a second key. For example, Alt-Minus then `a` types [`⍶`](https://bpl.fast.ai//glyphs/alpha-underbar.html), and Alt-6 then a digit types a superscript. Hold Alt or Option and tap the same dead key twice to type its character: Option-o twice types [`○`](https://bpl.fast.ai//glyphs/circle.html), and Option-backslash twice types [`⍭`](https://bpl.fast.ai//glyphs/stile-tilde.html). The sequence ends after the second tap. On a UK Mac keyboard, Option-Shift-3 types [`#`](https://bpl.fast.ai//glyphs/hash.html), and plain Shift-3 still types `£`. Right Option keeps its native behavior. Alt shortcuts work in BPL input, including strings and comments. The glyph map is the same as the BPL REPL's.

In the browser, Alt shortcuts use US physical key positions. The [native macOS layouts](keyboard.md#macos-installation) support US, UK, German QWERTZ, French AZERTY and Spanish ISO keyboards. They preserve local typing and move conflicting BPL shortcuts to Option-Shift, then Control-Option or Control-Option-Shift.

To enter a glyph by name, type a backtick followed by its name. For example, `` `io `` then Tab inserts [`ι`](https://bpl.fast.ai//glyphs/iota.html), and ``2`times3`` becomes `2×3`. As you type, suggestions appear beside the cursor, with each glyph's key shortcut in the REPL's notation. In that notation, `h` means Alt-h, and `o c` means Alt-o then `c`. Matches are ranked by exact name, then prefix, then abbreviation. Click a suggestion or keep typing to resolve an ambiguous name. Names and aliases come from BPL's REPL catalogue.

Backtick completion works in `%%bpl` and `%%apl` cells, on `%bpl` lines such as `x = %bpl ...`, and in Monaco editors configured for BPL. Ordinary Python and Markdown input is unchanged. Backtick sequences in strings, comments and pasted text are not expanded. Press Tab to expand a backtick name that is already in the text. Enter accepts a unique match, then performs the notebook's normal newline or execution action. Press Escape or move the cursor to cancel automatic expansion.

Running a `bpl` magic for the first time also adds a clickable symbol bar, based on Adám Brudzewsky's [APL language bar](https://abrudz.github.io/lb/apl). Hover over a glyph to see its names and shortcut. The `▲`/`▼` button switches the symbol bar between pushing the page down and overlaying it. This choice is remembered per site.

The `%%bpl` cell magic displays BPL output in Adám's [SAX2](https://github.com/abrudz/SAX2) APL font:

```python
%%bpl
m←3 3ρι9
m×10
```

Assignments are [shy](terms.md#term-shy): the `m←` line printed nothing. The `%bpl` line magic returns a `basedpl.Array`. Use `.np` to copy its values to NumPy:

```python
v = %bpl 3×ι4
v.np
```

```output
array([0., 3., 6., 9.])
```

```python
text = %bpl "APL in Python"
text.py
```

```output
'APL in Python'
```

`.py` converts numeric atoms to Python numbers and character vectors to strings. With `.py`, unkeyed numeric arrays become NumPy arrays, keyed vectors become dictionaries, and higher-rank keyed arrays become pandas DataFrames. Numeric scalars (rank-0 arrays) become zero-dimensional NumPy arrays. `.np` copies values to NumPy without labels:

```python
z = %bpl m
z.np
```

```output
array([[0., 1., 2.],
       [3., 4., 5.],
       [6., 7., 8.]])
```

To suppress a cell's output, end the last line with a `;`:

```python
%%bpl
m×10;
```

`⎕←` displays a value explicitly, which is how you show something that would otherwise be shy:

```python
%%bpl
v←2×ι5
⎕←v
```

Convert to NumPy to use its methods:

```python
a = %bpl m
a.np.sum(axis=0)
```

```output
array([ 9., 12., 15.])
```

## Names and help

Press Tab to complete user and system names in BPL input. Use `]help name` to show help from comments and `]help name -source` to show BPL source:

```python
%%bpl
double←{⍝ Double the argument
2×ω}
```

```python
%bpl ]help double
```

Calls: `f Y` or `X f Y`

Double the argument

```python
%bpl ]help double -source
```

```apl
{⍝ Double the argument
2×ω}
```

Python function objects support `f?` and `f??`. See [Python](python.md#names-and-help) and [Help and introspection](introspection.md).

## Errors and interruption

`%bpl` and `%%bpl` raise `basedpl.BplError` for a BPL error. The magics display output produced before the error. Incomplete input raises a syntax error without resetting the workspace.

Interrupt a calculation with the notebook's stop button. Set a per-evaluation deadline with `bpl.timeout = seconds`. Cancelling an evaluation keeps the workspace and any assignments that have already completed. Native-library calls and individual BigInt operations can delay cancellation.

BPL is an APL-derived array language, borrowing from J and BQN. See the [glyph reference](glyphs.md) for glyphs, [System functions](system-functions.md) for system functions, and [Evaluation](evaluation.md) for how functions apply to arrays.

## Other interpreters

[Dyalog sessions](dyalog.md) run an independent reference interpreter.

The [magics implementation](magics.md) documents display, completion and workspace handling.
