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.9.2

A Python bridge to Transformers.js for JupyterLite — run language models and embedding workflows 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 and translation via LLM.pipeline(task, model=...)
  • 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

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().
  • 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().

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: pjs / 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.9.2

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.9.2
File Size Uploaded Provenance Actions
lmlite-0.9.2.tar.gz 85.6 kB With provenance Details for lmlite-0.9.2.tar.gz

Built distribution (wheel)

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

Total release size: 144.3 kB

Release files / lmlite-0.9.2.tar.gz

Download URL lmlite-0.9.2.tar.gz
Size 85.6 kB
Tags Source
SHA-256 checksum
How to use checksums
fa42522e8d10d881de93cf7364873dd61c6277eb5623a2dd6dd47fa48554efb1
BLAKE2b-256 checksum
How to use checksums
d00326afad5acdab3ef784aec9f1b4e197cea4efb0f846d95577c701ad60f686
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 1, 2026.

Transparency log

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

Download URL lmlite-0.9.2-py3-none-any.whl
Size 58.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0491d79a8b5991e5ffb9cd2f15b9eae1406fcf58e13230a9936e9f2c5c27f0cf
BLAKE2b-256 checksum
How to use checksums
81485f7c5030b7a65773e4376d01eff8c214d8e7a8a27415828c7028a8396a7f
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 1, 2026.

Transparency log

Security for lmlite 0.9.2

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

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for lmlite-0.9.2.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 1, 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.

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