skillfed

lunr

A Python implementation of Lunr.js

lunr v0.8.0 291.2K downloads/30d#7,973 on PyPI203
Permissive license MIT AGING released

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 lunr

uv

uv add lunr

poetry

poetry add lunr

Installing 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

Development Status :: 4 - BetaIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: Text Processing

Tags

full text search pythonlightweight search indexin-memory search librarylunr.js python portdocument indexing and retrievalsimple search solutioninverted index search
search-indexinglunr-js-compatible

More Text Processing packages