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

Lispyn is a macro-first toolkit for authoring AI experiments in Hy (Lisp for Python). Define and compose reusable compile-time macros, then run your experiments directly or compile them into ordinary Python Jupyter notebooks.

The core product is a language of Hy macros, not a replacement for PyTorch, NumPy, pandas, Matplotlib or Python. Macro expansion makes experiment structure explicit and inspectable; small Python helpers handle numerical operations where appropriate. Your models, data, optimizers and evaluation logic remain native Python.

PyPI version CI on main Apache-2.0

Why use Lispyn for AI notebooks?

Macros are the main abstraction. Hy macros transform source code at compilation, rather than just exposing another training API. Compose native Python operations, build reusable training functions, and create your own macros. Version 0.39 introduced deftrain-step, optimizer-step, collect-epochs, with-training, with-grad and with-rng-fork — six self-contained macros that expand into Python without a new Lispyn runtime backend.

(require lispyn.macros [deftrain-step collect-epochs])
(deftrain-step train-one model optimizer criterion)
(setv history (collect-epochs epoch 4
  (train-one features labels)))

See the runnable CPU macro-first example and the guide to developing your own macros, including hygienic names, composition, independent notebook cells and compile-time security.

One source, three artifacts. Write a .hy experiment once. Run it as a script (run), compile an unexecuted notebook (build), or execute it and save real outputs (execute). The resulting notebook contains ordinary Python, not an opaque Lispyn engine.

Data splitting and explicit checks. The real PyTorch quickstart splits data into training, validation and held-out test sets:

(setv [training validation held-out]
  (train-val-test dataset :validation-fraction 0.25
    :test-fraction 0.25 :seed seed))

Evaluation integrity. New assert-disjoint detects overlapping sample IDs between dataset partitions; assert-probabilities rejects invalid binary scores or multiclass probabilities. See evaluation guards.

The input validation example rejects bad shapes and nonfinite numbers:

(require lispyn.macros [assert-finite assert-shape])
(import numpy :as np)
(import pandas :as pd)

(setv features (np.array [[1.0 2.0] [3.0 4.0]]))
(assert-shape features [2 2] :name "features")
(assert-finite features :name "features")

Check classification class balance with the runnable example:

(require lispyn.macros [label-balance plot-label-balance])
(setv labels ["cat" "cat" "cat" "dog" "dog" "bird"])
(setv report (label-balance labels :title "Training label distribution"))

For classification, class-weights computes inverse-frequency loss weights, and threshold-report compares validation probability cutoffs without peeking at held-out test labels.

Native PyTorch, not a parallel framework. Use macros such as with-eval, with-training, with-autocast, clip-gradients, with-parameter-freeze, gradient-report and predict-batches to generate inspectable operations or invoke explicit low-level checks. Training, autograd, optimizers, and saved checkpoints remain standard PyTorch. The PyTorch controls and diagnostics example run on the CPU.

Evidence-driven notebooks. The quickstart reports real PyTorch metrics:

(require lispyn.macros [report-run narrate metric-table])
(import lispyn.training [evaluate-metrics])
(report-run run :title "PyTorch baseline · recorded metrics")

Generate plots, comparisons, parameterized notebooks, and reports from run data. See the executed quickstart notebook.

Install

pip install lispyn

Python 3.10+ is required. The base package includes Hy, notebook compilation/execution, and Matplotlib. Install pandas with pip install "lispyn[data]". PyTorch is installed separately using the appropriate CPU or GPU build from PyTorch's installation guide. A cloned repository also offers the broader research environment:

pip install -r requirements.txt

Lispyn is experimental alpha software; macro interfaces may evolve.

Quickstart: run, build, execute

Clone the repository to access examples (the hello example does not require PyTorch):

git clone https://github.com/edujbarrios/lispyn.git
cd lispyn

1. Run a Hy experiment. Nothing is written to a notebook:

lispyn run examples/hello.hy

2. Build a shareable notebook. Nothing is executed; compilation creates ordinary Python and Markdown cells:

lispyn build examples/hello.hy -o hello.ipynb

3. Execute and capture outputs. Jupyter runs the compiled notebook and saves the executed cells:

lispyn execute examples/hello.hy -o hello-executed.ipynb

The hello example prints 2 + 3 + 5 = 10 and Lispyn checks passed!. For the full real experiment, try lispyn execute examples/quickstart.hy after installing torch. For macro-first CPU training, run lispyn execute examples/macro_first_training.hy. To inspect macro expansion directly, use hy2py examples/macro_first_training.hy.

Design principles and limits

Choose Lispyn when Lisp/Hy macros are worth the cognitive overhead, you want versioned experiments as source files, or you need reviewable standard-Python Jupyter artifacts. Use plain Python when interactive notebook editing is your main workflow or you do not need source transformations.

Macro-first means: focus on hygienic syntax transformations, scoped state management, and composable experiment code. It does not mean every numerical algorithm belongs inside a macro. Python backends are appropriate for substantial calculations and validations; macros provide the public authoring interface.

Security: Compile and execute only trusted Hy code. Hy macros can execute arbitrary Python at compile time, so even lispyn build is not sandboxed. Load checkpoints only from trusted sources. Lispyn cannot guarantee bitwise determinism, better accuracy, or absence of data leakage.

Documentation

Reference: 80 supported macros · Writing and extending macros · CPU macro-first walkthrough · Notebook gallery · Changelog · Citation

Created by Eduardo J. Barrios · Apache-2.0 licensed · experimental alpha software.

Metadata

Release files for lispyn 0.40.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.40.0a1
File Size Uploaded Provenance Actions
lispyn-0.40.0a1.tar.gz 170.2 kB With provenance Details for lispyn-0.40.0a1.tar.gz

Built distribution (wheel)

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

Total release size: 275.9 kB

Release files / lispyn-0.40.0a1.tar.gz

Download URL lispyn-0.40.0a1.tar.gz
Size 170.2 kB
Tags Source
SHA-256 checksum
How to use checksums
f607e890a3865b0a1043169b3e85617bea3552ef415fe13efc5545fb9dd2d43a
BLAKE2b-256 checksum
How to use checksums
ee0a86547f6af2862cedc02c86331465f67ddb650fd8067a7f07dafd66a301a0
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.40.0a1-py3-none-any.whl

Download URL lispyn-0.40.0a1-py3-none-any.whl
Size 105.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1597def81f932de99331699d782b66b5eed0bd2b9d190d2cf0f82ef3cdad26c7
BLAKE2b-256 checksum
How to use checksums
736f0e6365825ef14c79a532f1a81c047c0a168b13553082d5f71f7097a41899
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.40.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.40.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