LensKit is a set of Python tools for experimenting with and studying recommender systems. It provides support for training, running, and evaluating recommender algorithms in a flexible fashion suitable for research and education.
LensKit for Python (LKPY) is the successor to the Java-based LensKit project.
Important
If you use LensKit for Python in published research, please cite:
Michael D. Ekstrand. 2020. LensKit for Python: Next-Generation Software for Recommender Systems Experiments. In Proceedings of the 29th ACM International Conference on Information and Knowledge Management (CIKM '20). DOI:10.1145/3340531.3412778. arXiv:1809.03125 [cs.IR].
Note
LensKit had significant changes in the 2025.1 release. See the Migration Guide for details.
To install the current release with uv (recommended):
$ uv pip install lenskitOr, to add it to your project's dependencies and virtual environment:
$ uv add lenskitClassic pip also works:
$ python -m pip install lenskitThen see Getting Started
You can also install LensKit from conda-forge with pixi:
$ pixi add lenskitOr conda:
$ conda install -c conda-forge lenskitTo use the latest development version, you have two options. You can install directly from GitHub:
$ uv pip install -U git+https://github.com/lenskit/lkpyOr you can use our PyPI index, by adding to pyproject.toml:
[[tool.uv.index]]
name = "lenskit"
url = "https://pypi.lenskit.org/lenskit-dev/"Binary wheels of LensKit development (and release) versions are automatically pushed to this index, although they are not guaranteed to be permanently available. Reproducible code should generally depend on released versions published to PyPI.
We also provide mirrors of the PyTorch package repositories that are filtered to
only include PyTorch and directly supporting dependencies, without other
packages that conflict with or mask packages from PyPI, and with fallbacks for
other platforms (i.e., our CUDA indices include CPU-only MacOS packages). This
makes it easier to install specific versions of PyTorch in your project with
the index priority and fallthrough logic implemented by uv. To make your
project only use CPU-based PyTorch, you can add to pyproject.toml:
[[tool.uv.index]]
name = "torch-cpu"
url = "https://pypi.lenskit.org/torch/cpu/"Or CUDA 12.8:
[[tool.uv.index]]
name = "torch-gpu"
url = "https://pypi.lenskit.org/torch/cu128/"These indices provide the same package distributions as the official PyTorch repositories (in fact, they link directly to the PyTorch packages). They are just an alternate index view that reduces some package conflicts.
To contribute to LensKit, clone or fork the repository, get to work, and submit a pull request. We welcome contributions from anyone; if you are looking for a place to get started, see the issue tracker.
Our development workflow is documented in the wiki; the wiki also contains other information on developing LensKit. User-facing documentation is at https://lenskit.org.
We use uv for developing LensKit and managing
development environments. Our pyproject.toml file contains the Python
development dependencies; you also need a working Rust compiler (typically via
rustup). We provide Mise configuration to
automatically install everything needed, including uv and rust.
The easiest way to work on LensKit is to use the devcontainer — in Visual Studio Code, Zed, and other editors supporting Dev Containers, just re-open the project in a dev container, and the necessary software will be automatically installed.
Note
The Rust compiler needs some memory to work. If your Docker environment is set to a very small memory capacity (e.g. Colima's default of 2GB), the build will fail. Make sure your Docker has at least 4, preferably 8, GB of memory.
Note
VS Code may try to connect to Python before the dev container has finished setting up the software dependencies, and prompt you to automatically install Python. Don't click this — let the container setup do it.
Note
The dev container is the only supported way to develop on Windows — while LensKit works and is regularly tested on Windows, we have not invested time in making sure the development environment works on Windows without the dev container.
If you want to set up yourself, we recommend using Mise:
$ mise trust
$ mise install
$ uv syncmise install will automatically install uv, rust, development support tools
and the Git pre-commit hooks (managed with hk). You will also need a working
C compiler (on macOS, install Xcode or the Xcode command-line tools).
If you want to use a specific Python version, select it with uv venv or uv sync:
$ uv venv -p 3.14t
$ uv syncIf you want all extras, do:
$ uv sync --all-extrasYou should always test your changes by running the LensKit test suite:
uv run pytest tests
If you want to use your changes in a LensKit experiment, you can locally install your modified LensKit into your experiment's environment. We recommend using separate environments for LensKit development and for each experiment; you will need to install the modified LensKit into your experiment's repository:
uv pip install -e /path/to/lkpy
This material is based upon work supported by the National Science Foundation under Grant No. IIS 17-51278. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation.