Skip to main content

lmLite — browser machine learning from Python

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

lmLite

Package version: 0.14.0

Browser machine learning from Python — run language models, embeddings, vision, speech and bare ONNX models entirely in your browser, and reach the microphone and camera, from a Python kernel in JupyterLite (or headless, with onnxruntime).

Quick Start

Try online (no installation required):

Basic usage:

from lmlite import LLM, Classifier, Embedder, pipeline

# 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
embedder = await Embedder.create("all-MiniLM-L6-v2")
embedding = await embedder.embed("Hello world")

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

# Text classification
classifier = await Classifier.create("distilbert-base-uncased-finetuned-sst-2-english")
print(await classifier.classify("I love lmLite!", top_k=2))

# Any Transformers.js task is an awaitable callable: here, the objects in a photo
detector = await pipeline("object-detection", model="detr-resnet-50")
detections = await detector("https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/cats.jpg", threshold=0.6)
print(detections)  # [{'label': 'cat', 'score': 1.0, 'box': {'xmin': ..., ...}}, ...]

Features

  • Browser-native: Run models entirely in the browser, no server required
  • 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), audio classification, text to speech via pipeline(task, model=...), over many inputs with pipe.map() (batches, progress, cancel)
  • 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
  • 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 and CameraCapture takes a photo, in a notebook (pip install 'lmlite[audio]', pip install 'lmlite[camera]'); 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 (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 bridge from Python to machine learning in the browser: Transformers.js pipelines, bare ONNX models and browser devices such as the microphone and camera, for notebooks in JupyterLite. It provides:

  • pipeline(): Transformers.js tasks as awaitable Python callables, for vision, speech, images out, translation and zero-shot classification, over many inputs with map(); the newer features are built on it
  • LLM.create(): text generation, chat with streaming and token probabilities, for large language models
  • Embedder.create() and Classifier.create(): sentence embeddings with similarity search, and text classification
  • Model loading, caching, and portable ZIP workflows
  • Backend and dtype controls for each model

Inference is powered by Transformers.js and ONNX Runtime. lmLite is not a new model engine, and its optional native backend is for tuning, not a production inference service. 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 run models in a browser. pipeline(), OnnxModel, LLM, Embedder, Classifier and the widgets need a browser kernel (xeus-python or the JupyterLite Pyodide kernel) with JavaScript interoperability. pip install 'lmlite[native]' adds a headless onnxruntime backend for Embedder, Classifier, greedy LLM.generate(), OnnxModel and tokenizer(). 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

  • Getting Started - Installation, development setup, and testing
  • Guides - One task at a time: generate and chat, embeddings, pipelines, ONNX models, tokenizers, models and cache
  • Reference - LLM, Embedder and Classifier parameters, pipeline task table and tested models
  • Explanation - Backends, the Python/JavaScript bridge and the runtime scope
  • Model Guide - Recommended models and dtype selection
  • Runtime & Integration - Platform support, xeus-python or Pyodide, and integration boundaries
  • Native Tuning - Tune headless with the native backend, then ship to the browser
  • Glossary - Key concepts and terminology

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 pipeline().
  • Vision pipelines — Image classification, zero-shot image classification, image features and object detection with pipeline().
  • Pipelines that return images — Background removal, depth estimation, image segmentation and a 2x upscale with pipeline(), shown as PNG images.
  • Detect objects with the camera — Take a photo with the camera of a laptop, tablet or phone with an anywidget and find the objects in it in the browser.
  • Text to speech — Generate speech with 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.
  • Bare ONNX models — Run a single .onnx file (the UltraFace face detector) with OnnxModel, NumPy in and NumPy out.
  • 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.
  • 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 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).
  • 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.

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 machine learning from Python},
  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.14.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.14.0
File Size Uploaded Provenance Actions
lmlite-0.14.0.tar.gz 135.5 kB With provenance Details for lmlite-0.14.0.tar.gz

Built distribution (wheel)

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

Total release size: 233.8 kB

Release files / lmlite-0.14.0.tar.gz

Download URL lmlite-0.14.0.tar.gz
Size 135.5 kB
Tags Source
SHA-256 checksum
How to use checksums
2dfa1557191e3cbacbebb39db40d7dea8f6ade2cbd010007c8de1278c7b60717
BLAKE2b-256 checksum
How to use checksums
ec56936cad07fd899099edb895fb33997dfbbb98eb67a2394f68e88c1996c4cd
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 24, 2026.

Transparency log

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

Download URL lmlite-0.14.0-py3-none-any.whl
Size 98.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ece75059cd465ad447e5495edb6e437ab8abd3f48411b7422ed8c37d70ed20cf
BLAKE2b-256 checksum
How to use checksums
183674462e3db0d976dd4a015cd3954ac3891f413329376e2a720ea373b1368a
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 24, 2026.

Transparency log

Security for lmlite 0.14.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.14.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 24, 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