pytrec-eval
Provides Python bindings for popular Information Retrieval measures implemented within trec_eval.
What it is and what it does
pytrec_eval is a Python wrapper around TREC's trec_eval tool, a standard reference implementation for computing Information Retrieval evaluation metrics. It lets you compute measures like MAP (Mean Average Precision) and NDCG (Normalized Discounted Cumulative Gain) by passing relevance judgments and ranked results as Python dictionaries, then get back computed scores for each query.
The package is designed to eliminate the need for custom metric implementations in Python research code. It wraps the compiled trec_eval engine via C++ bindings, so it inherits the correctness and performance of the reference implementation. Installation requires a C++ compiler and Python development headers; the package has been dormant since 2020 but carries no known security issues.
Use it for:
- Evaluate information retrieval systems in Python research pipelines without reimplementing standard metrics.
- Compute ranking quality metrics (MAP, NDCG, etc.) for search or recommendation system experiments.
- Perform statistical significance testing between two ranked result sets using standard IR measures.
- Validate IR models by scoring ranked results against ground-truth relevance judgments in batch.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides Python bindings to compute standard Information Retrieval evaluation measures (MAP, NDCG, and others) against relevance judgments, wrapping the TREC trec_eval tool.
Yes, if you need standard IR evaluation metrics in Python and can meet the C++ build requirements. The package is dormant but stable, carries no known vulnerabilities, and wraps a trusted reference implementation. Install only if you're comfortable with a package that hasn't been updated since 2020 and verify compatibility with your Python version before relying on it in production.
Install
pytrec-eval on PyPI
pip
pip install pytrec-evaluv
uv add pytrec-evalpoetry
poetry add pytrec-evalInstalling pytrec-eval
Before you install
Installation requires a C++ compiler and Python development headers; the package is dormant (last release 2020-09-07, last commit 2023-10-10) but carries no known vulnerabilities and has accumulated 350 repository stars.
License in practice
Licensed under the MIT license (permissive), allowing commercial and private use; note that the underlying trec_eval tool is licensed separately.
Quickstart
pip install pytrec_eval
import pytrec_eval
qrel = {'q1': {'d1': 0, 'd2': 1}}
run = {'q1': {'d1': 1.0, 'd2': 0.0}}
evaluator = pytrec_eval.RelevanceEvaluator(qrel, {'map', 'ndcg'})
results = evaluator.evaluate(run)
Requires a C++ compiler and Python development headers; developed for Python 3.5 and requires Python >= 3.
Verify before relying
- Whether numpy and scipy are runtime dependencies or only build-time requirements (description lists them but fact sheet shows n_runtime: 0).
- Current compatibility with modern Python versions beyond the 3.5 development baseline.
- Whether the package is actively maintained or if dormancy signals end-of-life.
Package facts
| License | not declared (permissive) |
| Python support | supports the current Python release (>=3) |
| Install friction | high — source build required |
| Runtime dependencies | none |
| Maintenance | dormant — 2,167 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 96,187/month — #13,224 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pytrec_eval-0.5.tar.gz
Keywords: trec_eval, information retrieval, evaluation, ranking
Tags
More General packages
A drop-in replacement for Python's standard…
permissive · top 100 on PyPI
docutilsDocutils converts plaintext documentation in…
unclear · top 1,000 on PyPI
SphinxSphinx generates professional documentation…
permissive · top 1,000 on PyPI
larkLark is a parsing library that builds abstract…
permissive · top 1,000 on PyPI
nltkNLTK is a Python library for natural language…
permissive · top 1,000 on PyPI
humanizeConverts numbers, dates, times, and file sizes…
permissive · top 1,000 on PyPI
ir-measuresProvides a unified Python interface to compute…
permissive · top 15,000 on PyPI
pytrec-eval-terrierProvides Python bindings to TREC's trec_eval…
permissive · top 5,000 on PyPI
trec-car-toolsProvides Python and Java bindings to read TREC…
permissive · top 15,000 on PyPI
ranxranx computes ranking evaluation metrics…
permissive · top 15,000 on PyPI
ir-datasetsProvides a unified Python interface to…
permissive · top 15,000 on PyPI
mir-evalmir_eval computes standard accuracy metrics for…
permissive · top 15,000 on PyPI
colbert-aiColBERT is a BERT-based retrieval model that…
unclear · top 15,000 on PyPI
py-expression-evalParses and evaluates mathematical expressions…
permissive · top 15,000 on PyPI
deepevalDeepEval is an LLM evaluation framework that…
permissive · top 5,000 on PyPI
voyageaiProvides Python access to Voyage AI's embedding…
permissive · top 5,000 on PyPI