Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Lispyn — Lisp-powered AI notebooks

Write AI experiments as Hy macros. Run them directly, compile them to readable Python, or execute them as Jupyter notebooks. Lispyn helps you define native PyTorch models, train and evaluate them, create Matplotlib figures, validate datasets and publish reproducible results. No new tensor framework or opaque training runtime.

PyPI version CI on main Apache-2.0

Why use Lispyn for AI notebooks?

Look at what you can write. This is real Hy syntax from the runnable CPU showcase, not pseudocode. The macros generate native Python functions and Matplotlib calls.

1. Declare a dependency cell in your notebook

(require lispyn.macros [pip-install])
(pip-install "matplotlib>=3.8")

pip-install produces an isolated Jupyter dependency cell. Nothing is executed during lispyn build; the packages are checked/installed only when you run the Hy script or execute the notebook. Matplotlib is already in the default Lispyn package. Install the appropriate PyTorch CPU/GPU build separately—don't assume pip-install "torch" selects the right accelerator.

2. Create a real PyTorch model, optimizer and training loop

(require lispyn.macros [defmodel defoptimizer deftrain-step collect-epochs])
(import torch)
(torch.manual_seed 42)

(defmodel make-mlp [features hidden]
  (torch.nn.Linear features hidden)
  (torch.nn.ReLU)
  (torch.nn.Linear hidden 1))
(setv model (make-mlp 2 8))
(defoptimizer make-adam [model rate] torch.optim.Adam :weight-decay 0.01)
(setv optimizer (make-adam model 0.05))
(setv criterion (torch.nn.MSELoss))
(setv samples (torch.tensor [[0.0 0.0] [0.0 1.0] [1.0 0.0] [1.0 1.0]]))
(setv targets (torch.tensor [[0.0] [1.0] [1.0] [2.0]]))
(deftrain-step train-one model optimizer criterion)
(setv losses (collect-epochs epoch 4
  (train-one samples targets)))

defmodel creates a new torch.nn.Sequential model each call; defoptimizer creates a standard torch.optim.Adam. Compose them with deftrain-step, collect-epochs, with-training and with-eval. For custom architectures, use ordinary torch.nn.Module.

3. Make an original plot with a reusable macro

(require lispyn.macros [defplot with-figure])
(import matplotlib.pyplot :as plt)

(defplot loss-chart [losses] [fig ax]
  (.plot ax (range (len losses)) losses :label "Training loss" :marker "o")
  (.set_title ax "Training progress")
  (.set_xlabel ax "Epoch")
  (.set_ylabel ax "MSE")
  (.legend ax))
(setv figure (loss-chart losses))
(.savefig figure "showcase-loss.png")
(plt.close figure)

defplot generates a reusable Python function that returns a Matplotlib figure. with-figure builds a one-off chart with access to the actual fig and ax objects. For recorded training metrics, curve and defcurve provide prepared themes, comparison plots and PNG/SVG exports.

Verified PyTorch training and validation curves produced from a Lispyn notebook

Real output from the executed PyTorch quickstart, not a mockup.

Try the complete example: lispyn run examples/showcase.hy, or use build and execute to create a shareable notebook. The example trains on four synthetic CPU samples, prints losses, and saves two real PNG figures. It does not claim meaningful predictive performance.

What else can Lispyn do?

Your goal Hy macros and examples
Notebook composition md, pip-install, experiment-params — notebook cells
PyTorch control with-seed, with-autocast, clip-gradients, save-model, load-model — CPU controls
Data quality and safe evaluation assert-shape, assert-finite, assert-disjoint, assert-probabilities — evaluation guards
Validation and research train-val-test, cross-validate, train-until, class-weights — real quickstart
Plots and reports curve, defcurve, confusion-matrix, report-run, metric-table — curve designs
Inspect and extend the language deftrain-step, collect-epochs, defmodel, defplot — macro authoring

All 84 supported macros have Hy examples in the reference. The executed quickstart notebook shows real PyTorch results.

Install

pip install lispyn

Python 3.10+ is required. The base install includes Hy, notebook compilation/execution, NumPy via Matplotlib, and Matplotlib itself; pandas is optional (pip install "lispyn[data]"). PyTorch is installed separately using PyTorch's official platform-specific instructions.

For the checked-in examples, clone the repository:

git clone https://github.com/edujbarrios/lispyn.git
cd lispyn
# Optional, larger research environment:
pip install -r requirements.txt

One Hy source → three workflows

To reproduce the full native PyTorch walkthrough, run lispyn execute examples/quickstart.hy after installing torch.

The tiny hello example requires no PyTorch:

lispyn run examples/hello.hy
lispyn build examples/hello.hy -o hello.ipynb
lispyn execute examples/hello.hy -o hello-executed.ipynb
  • run: run Hy directly, without creating a notebook.
  • build: compile unexecuted, inspectable Python and Markdown cells; Nothing is executed at runtime.
  • execute: run Jupyter and save the executed cells and real outputs.

Each notebook code cell compiles independently; repeat require in any new cell using macros.

Explore expansion with hy2py examples/showcase.hy. Use lispyn new study.hy to scaffold a notebook or lispyn gallery for a set of compiled examples.

Where Lispyn fits

Lispyn is alpha software: macro interfaces may evolve. Choose it if source transformations, reusable experiment scaffolding and auditable Python notebooks are valuable to you; stick with plain Python when macros don't help. Generated Python still depends on your original libraries and data.

Security and limits: Hy macros execute Python at compile time. Compile only trusted .hy sources, including during build; it is not sandboxed. Notebook pip-install runs only when executed, and package installation requires trusted dependencies. No macro guarantees determinism, absence of leakage, or improved model accuracy.

Macro catalog · Macro-authoring guide · Notebook gallery · Changelog · Citation

Created by Eduardo J. Barrios · Apache-2.0 licensed.

Metadata

Release files for lispyn 0.41.0a1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lispyn 0.41.0a1
File Size Uploaded Provenance Actions
lispyn-0.41.0a1.tar.gz 173.5 kB With provenance Details for lispyn-0.41.0a1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for lispyn 0.41.0a1
File Interpreter ABI Platform Actions
lispyn-0.41.0a1-py3-none-any.whl Python 3 none any Details for lispyn-0.41.0a1-py3-none-any.whl

Total release size: 279.8 kB

Release files / lispyn-0.41.0a1.tar.gz

Download URL lispyn-0.41.0a1.tar.gz
Size 173.5 kB
Tags Source
SHA-256 checksum
How to use checksums
18db8ced54a9bd78af29bd3a7b81970795ec66ca7f963a7018d8b0548628eb20
BLAKE2b-256 checksum
How to use checksums
c2d7cd46fdb3837fa0996d5e819bbca6589413b4e12f43f3928b18546e06d4dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

Release files / lispyn-0.41.0a1-py3-none-any.whl

Download URL lispyn-0.41.0a1-py3-none-any.whl
Size 106.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a3b7f55c330238470fa20ef76b54fb0512b0de30a5679081e87f5794a9fd7039
BLAKE2b-256 checksum
How to use checksums
31ceaf10cda50443cca45fa36bd0fda51e78874a0f17156ac4972fb31fd43bd4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

Security for lispyn 0.41.0a1

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for lispyn-0.41.0a1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page