lunr
A Python implementation of Lunr.js
What it is and what it does
Lunr is a Python port of the JavaScript Lunr.js library, designed to provide full-text search capabilities without the overhead of a dedicated search server like Elasticsearch. It works by parsing a collection of documents (represented as dictionaries) and building an inverted index that enables fast text queries. The index is kept entirely in memory, making it suitable for prototyping, smaller applications, or situations where deploying a full-scale search infrastructure is impractical.
A key feature is interoperability with Lunr.js: you can build an index in Python and serialize it for use in a browser-based frontend, or vice versa. This is particularly useful for static documentation sites (like those built with MkDocs) where you want to pre-compute the search index on the backend to minimize startup time in the browser. The trade-off is that you must recreate or reload the index when your application starts, since it exists only in memory.
Use it for:
- Add full-text search to a documentation site (e.g., MkDocs) by pre-indexing pages in Python and serving the serialized index to the frontend.
- Prototype a search feature for a web application before committing to Elasticsearch or another production search engine.
- Search a small-to-medium corpus of documents in a Python application without external dependencies or infrastructure.
- Build a backend search index that can be shared with a JavaScript frontend using the same Lunr.js format.
- Implement keyword-based retrieval in a data processing pipeline where documents are already in memory.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Lunr is a lightweight, in-memory full-text search library that builds an inverted index from a set of documents and performs fast text searches without requiring a separate search server.
Yes, if you need lightweight full-text search without external infrastructure and your document set is manageable in memory. The low install friction, permissive MIT license, and broad Python version support (3.9–3.13) make it a practical choice for prototyping or small-scale use. However, the aging maintenance status (524 days since last release) means you should verify compatibility with your specific Python version and use case before relying on it for production systems.
Install
lunr on PyPI
pip
pip install lunruv
uv add lunrpoetry
poetry add lunrInstalling lunr
Before you install
Low friction: pure Python wheel with only two lightweight runtime dependencies (importlib-metadata and typing-extensions). Maintenance is aging—last release was 524 days ago—but the repository is active and not archived, with a recent commit on 2025-03-08.
License in practice
MIT license (permissive): you can use, modify, and distribute lunr freely in both open-source and commercial projects with minimal restrictions, provided you include the license notice.
Quickstart
pip install lunr
from lunr import lunr
documents = [
{'id': 'a', 'title': 'Mr. Green kills Colonel Mustard', 'body': 'Mr. Green killed Colonel Mustard in the study with the candlestick.'},
{'id': 'b', 'title': 'Plumb waters plant', 'body': 'Professor Plumb has a green plant in his study'}
]
idx = lunr(ref='id', fields=('title', 'body'), documents=documents)
results = idx.search('kill')
Verify before relying
- Whether the aging maintenance status (524 days since last release) affects compatibility with recent Python versions or introduces unfixed bugs.
- Performance characteristics for document sets larger than the test corpus mentioned in the documentation.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.7) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — importlib-metadata, typing-extensions |
| Maintenance | aging — 524 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 291,159/month — #7,973 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: lunr-0.8.0-py3-none-any.whl
Keywords: full, lunr, search, text
Tags
More Text Processing packages
A drop-in replacement for Python's standard…
permissive · top 100 on PyPI
pyparsingpyparsing provides a library for building text…
permissive · top 1,000 on PyPI
docutilsDocutils converts plaintext documentation in…
unclear · top 1,000 on PyPI
RapidFuzzRapidFuzz provides fast fuzzy string matching…
permissive · top 1,000 on PyPI
tinycss2tinycss2 parses CSS strings into token and…
permissive · top 1,000 on PyPI
llama-parseLlamaParse parses complex documents (PDFs,…
permissive · top 1,000 on PyPI
pagefind-binPagefind-bin provides a precompiled binary…
permissive · top 5,000 on PyPI
llama-indexLlamaIndex is a data framework that connects…
permissive · top 5,000 on PyPI
llama-index-retrievers-bm25Integrates BM25 full-text search retrieval into…
permissive · top 15,000 on PyPI
pagefindProvides an async Python API to index and…
permissive · top 5,000 on PyPI
rank-bm25Implements BM25 ranking algorithms (Okapi BM25,…
permissive · top 5,000 on PyPI
voyagerVoyager performs fast approximate…
permissive · top 15,000 on PyPI
pygmarsPygmars builds lightweight lexers and parsers…
permissive · top 15,000 on PyPI
tinysegmenterTinySegmenter is a compact Japanese tokenizer…
permissive · top 15,000 on PyPI
PyStemmerPyStemmer provides word stemming algorithms for…
permissive · top 5,000 on PyPI
lightrag-hkuLightRAG is a retrieval-augmented generation…
permissive · top 15,000 on PyPI