Skip to main content

lmLite — a Python bridge to Transformers.js for JupyterLite

Tests codecov-python codecov-js Transformers.js Try xeus-python Try Pyodide

lmLite

Package version: 0.13.0

A Python bridge to Transformers.js for JupyterLite — run language models, embeddings, vision, speech and bare ONNX models entirely in your browser.

Quick Start

Try online (no installation required):

Basic usage:

from lmlite import LLM

# Instruction-tuned chat with SmolLM2
llm = await LLM.create(
    generator_model="HuggingFaceTB/SmolLM2-360M-Instruct",
    backend="wasm",
    dtype="q4",
)
response = await llm.chat([
    {"role": "user", "content": "Explain embeddings in simple terms."}
])
print(response)

# Text completion with GPT-2
llm = await LLM.create(generator_model="gpt2")
text = await llm.generate("Python is a great language because")
print(text)

# Embeddings and similarity search
llm = await LLM.create(embedding_model="all-MiniLM-L6-v2")
embedding = await llm.embed("Hello world")

docs = ["JupyterLite runs in the browser.", "Python is widely used for ML."]
results = await llm.similarity_search("Where does JupyterLite run?", docs)
print(results)

Features

  • Browser-native: Run LLMs entirely in the browser, no server required
  • Instruction-tuned models: Chat and instruction-following with browser-compatible models such as SmolLM2-360M-Instruct.
  • Composable workflows: Build simple RAG pipelines and conversational interfaces with memory using Python.
  • Privacy-first: All computation happens locally in your browser
  • Zero setup: No installation or API keys for hosted demos
  • Multiple backends: WebAssembly (WASM) or WebGPU
  • Multiple models: GPT-2, DistilGPT-2, TinyLlama, and more via Transformers.js
  • Embeddings & classification: Sentence vectors and text classification
  • Task pipelines: Zero-shot classification, speech recognition, translation and vision tasks (image classification, zero-shot image classification, image features, object detection), image-output tasks (background removal, depth estimation, image segmentation, image-to-image), text to speech via LLM.pipeline(task, model=...), over many inputs with pipe.map() (batches, progress, cancel)
  • Bare ONNX models: OnnxModel runs a single .onnx file with NumPy in and NumPy out, with caching, hosted files, a sha256 check, float16 and map()
  • Notebook widgets: AudioRecorder records the microphone in a notebook (pip install 'lmlite[audio]'); pip install 'lmlite[images]' adds NumPy and Pillow for the image notebooks
  • Model caching: Browser-cached downloads, portable ZIP export/import, and cache inspection before loading (LLM.model_info(), cached_models(), per-model clear_cache()) with Python progress callbacks
  • Pythonic API: Clean, async Python interface
  • Headless native backend: pip install 'lmlite[native]' runs the same ONNX files with onnxruntime outside the browser for fast tuning loops, checked for parity against the browser

What is lmLite?

lmLite is a lightweight Python-to-JavaScript bridge for local LLM inference in the browser, designed for JupyterLite notebooks. It provides:

  • Async Python API for text generation, embeddings, classification, similarity search, and additional Transformers.js task pipelines
  • Model loading, caching, and portable ZIP workflows
  • Independent backend/dtype controls for embeddings and generation

Inference is powered by Transformers.js and ONNX Runtime. lmLite is not a new model engine or native Python inference backend. Its similarity search is an in-memory cosine ranking helper, not a vector database.

Best suited for: Teaching, interactive experiments, and browser-local prototypes where avoiding remote inference services matters.

Note: Installing the Python package on desktop does not enable desktop inference. LLM.create() requires a supported browser-based Python environment (xeus-python or the JupyterLite Pyodide kernel) with JavaScript interoperability. See docs/RUNTIME.md for details.

Feedback and Contributions

lmLite is an experimental project exploring Python access to browser-native machine learning through Transformers.js.

Feedback is particularly welcome on:

  • The usefulness and design of the asynchronous Python API.
  • Additional Transformers.js tasks and capabilities to expose.
  • Model compatibility, performance, and browser runtime limitations.
  • Potential applications beyond JupyterLite.

Please share suggestions, bug reports, and use cases through GitHub Issues.

AI-Assisted Development

Parts of this project were developed with the assistance of generative AI tools. The maintainer is responsible for the architecture, review, testing, and published code.

AI-assisted contributions are welcome, provided contributors understand, review, and test their changes and take responsibility for their submissions.

Documentation

Interactive Notebooks

Try lmLite directly in your browser, without installing anything.

  • Basic demo — Text generation, embeddings, classification, and similarity search.
  • Task pipelines — Zero-shot classification, translation and speech recognition with LLM.pipeline().
  • Vision pipelines — Image classification, zero-shot image classification, image features and object detection with LLM.pipeline().
  • Bare ONNX models — Run a single .onnx file (the UltraFace face detector) with OnnxModel, NumPy in and NumPy out.
  • Text to speech — Generate speech with LLM.pipeline("text-to-speech") and play it in the notebook.
  • Speak to the notebook — Record the microphone (laptop or tablet) with an anywidget and transcribe it in the browser.
  • Pipelines that return images — Background removal, depth estimation, image segmentation and a 2x upscale with LLM.pipeline(), shown as PNG images.
  • Text to image: a recipe — SD-Turbo in one step on WebGPU with OnnxModel, a CLIP tokenizer and a NumPy scheduler, with prompt widgets to generate and save images: a research-licence recipe that needs a hardware GPU, 2.4 GB of download and about 7 GB of memory.
  • Model info and cache manager — Download size and cache status before loading, loading progress from Python, and a widget to list, load and delete cached models.
  • LLM orchestration — A simple retrieval-augmented generation (RAG) workflow and interactive multi-turn chat with conversation memory and streamed, stoppable answers, using SmolLM2-360M-Instruct (WASM/q4) and MiniLM embeddings (WASM/q8).
  • Streaming chat — Print a chat answer as it is generated, stop early with break, and cancel a running generation with cancel(), using SmolLM2-135M-Instruct (WASM).
  • Token probabilities — Stream each generated token with its probability, plus the runner-up token at every step, using SmolLM2-135M-Instruct (WASM).
  • Tokenizers — Load only the tokenizers of GPT-2, multilingual BERT and POTION (no weights), compare how they split text, and count tokens synchronously with LLM.tokenizer().
  • Proving GPU inference — Show that WebGPU inference really runs on the GPU: the hardware adapter, model tensors held in GPU memory, and WebGPU vs WASM timing for the same greedy generation, using SmolLM2-135M-Instruct (q4).

These examples run locally in the browser using Transformers.js.

How It Works

┌─────────────────────────────────────┐
│   Python (JupyterLite)              │
│   ├─ xeus-python (recommended)      │
│   └─ pyodide (alternative)          │
│                                     │
│   from lmlite import LLM            │
│   llm = await LLM.create()          │
│   text = await llm.generate(...)    │
└─────────────┬───────────────────────┘
              │ Bridge (xeus-python: pyjs / Pyodide: pyodide.ffi)
┌─────────────▼───────────────────────┐
│   JavaScript (Browser)              │
│   Transformers.js + ONNX Runtime    │
│   ├─ WebAssembly (WASM)             │
│   └─ WebGPU (optional)              │
└─────────────────────────────────────┘

License

Apache License 2.0. See LICENSE for details.

Dependencies: Transformers.js v4 (Apache 2.0)

Note: Individual model licenses may vary. Check model cards on HuggingFace before use.

Citation

@software{lmlite2026,
  author = {Decitre, Emmanuel},
  title = {lmLite: Browser-native LLM orchestration in JupyterLite},
  year = {2026},
  url = {https://github.com/decitre/lmlite}
}

Acknowledgements

lmLite builds on several open-source projects:

Thanks to the developers and maintainers of these projects and the broader Jupyter and Hugging Face communities.


Metadata

Release files for lmlite 0.13.0

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

Source distribution (sdist)

Source distribution for lmlite 0.13.0
File Size Uploaded Provenance Actions
lmlite-0.13.0.tar.gz 127.5 kB With provenance Details for lmlite-0.13.0.tar.gz

Built distribution (wheel)

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

Total release size: 215.6 kB

Release files / lmlite-0.13.0.tar.gz

Download URL lmlite-0.13.0.tar.gz
Size 127.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c02367df341f212b1ec683e4987c886acbaa78dbf415fcfc1e5c4538fd763569
BLAKE2b-256 checksum
How to use checksums
b432f3e3f694610717b795f0ce627b607663a551b83f4e1e45a12107cdd500ed
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 22, 2026.

Transparency log

Release files / lmlite-0.13.0-py3-none-any.whl

Download URL lmlite-0.13.0-py3-none-any.whl
Size 88.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d9eb1284330f01bbb3ba7ebb80bfdbebde1dbd9715ceb45576344c23f511a905
BLAKE2b-256 checksum
How to use checksums
7b3864f9da268002fb3aa047106f8a68a633660ceb61544775cfd62d780fa39c
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 22, 2026.

Transparency log

Security for lmlite 0.13.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.

Full provenance

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

Select from 2 files

Attestation for lmlite-0.13.0.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 22, 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

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