formulaic-contrasts
Build contrasts for models defined with formulaic
What it is and what it does
formulaic-contrasts extends the formulaic formula system with tools to build custom contrast matrices for categorical variables in statistical models. It provides functions like cond() to specify arbitrary comparison schemes, enabling researchers to define exactly how categorical predictors are encoded when fitting models. The package is designed for use within the scverse ecosystem and statistical modeling workflows where fine-grained control over contrast coding is needed.
The package depends on formulaic for formula parsing, pandas for data handling, and session-info for environment tracking. It targets Python 3.10+ and is actively maintained. Installation is straightforward via pip, and the library is intended to be used both directly by developers building custom models and indirectly as a dependency of higher-level statistical packages.
Use it for:
- Specify custom contrast schemes (e.g., treatment, sum, Helmert) for categorical variables in regression or generalized linear models.
- Build multi-condition comparisons in biological or scientific models where standard contrast coding is insufficient.
- Integrate contrast specification into formulaic-based model definitions for reproducible statistical workflows.
- Develop custom statistical modeling libraries that need flexible contrast matrix generation.
- Encode categorical predictors with domain-specific comparison logic in machine learning pipelines.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Builds arbitrary contrasts for statistical models defined using the formulaic formula system, enabling flexible comparison coding for categorical variables in model specifications.
Yes, if you use formulaic-based models and need custom contrast coding. The package is actively maintained, has no known vulnerabilities, low install friction, and a permissive license. It is niche—primarily useful for statistical modeling and research workflows—but well-suited to that purpose. Not necessary for general-purpose Python development.
Install
formulaic-contrasts on PyPI
pip
pip install formulaic-contrastsuv
uv add formulaic-contrastspoetry
poetry add formulaic-contrastsInstalling formulaic-contrasts
Before you install
Low friction installation with a pure-Python wheel. Active maintenance as of August 2026 with recent commits. Requires Python 3.10 or later. Three runtime dependencies (formulaic, pandas, session-info) are standard data-science libraries.
License in practice
BSD 3-Clause permissive license allows commercial use, modification, and distribution with minimal restrictions—attribution and liability disclaimer required.
Quickstart
pip install formulaic-contrasts
from formulaic_contrasts import ...
import formulaic
import pandas
# Build contrasts for a model formula
# See documentation for specific contrast functions
Requires Python 3.10 or later.
Verify before relying
- What specific contrast types or schemes the package supports beyond the cond() function mentioned in credits.
- Whether the package is typically used standalone or primarily as a dependency of other statistical modeling libraries.
- Performance characteristics when working with large categorical datasets or many contrast levels.
Package facts
| License | BSD 3-Clause License Copyright (c) 2024, Gregor Sturm All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following… (full text in the JSON record) (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 3 — formulaic, pandas, session-info |
| Maintenance | actively maintained — 607 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 159,637/month — #10,692 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: formulaic_contrasts-1.0.0-py3-none-any.whl
Tags
More Scientific/Engineering packages
NumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
pandaspandas provides fast, flexible data structures…
permissive · top 100 on PyPI
scipyscipy provides numerical algorithms for…
permissive · top 100 on PyPI
scikit-learnscikit-learn provides a comprehensive Python…
permissive · top 1,000 on PyPI
dilldill extends Python's pickle module to…
permissive · top 1,000 on PyPI
multiprocessMultiprocess is an enhanced fork of Python's…
permissive · top 1,000 on PyPI
formulaicFormulaic converts tabular data into model…
permissive · top 5,000 on PyPI
patsyPatsy converts R-style statistical formulas…
permissive · top 1,000 on PyPI
category-encodersTransforms categorical variables into numeric…
permissive · top 5,000 on PyPI
tabmatProvides efficient matrix classes for tabular…
unclear · top 15,000 on PyPI
kmodesImplements k-modes and k-prototypes clustering…
permissive · top 15,000 on PyPI
cmaesProvides CMA-ES (Covariance Matrix Adaptation…
permissive · top 5,000 on PyPI
linearmodelsProvides panel regression, instrumental…
unclear · top 15,000 on PyPI
pydeseq2PyDESeq2 performs differential expression…
permissive · top 15,000 on PyPI
phikPhi_K computes a correlation coefficient that…
permissive · top 5,000 on PyPI
color-operationsApplies color-oriented image operations—gamma…
permissive · top 15,000 on PyPI