formulaic
An implementation of Wilkinson formulas.
What it is and what it does
Formulaic is a Python implementation of Wilkinson formulas—a domain-specific language for specifying statistical model matrices from tabular data. It takes a formula string like 'y ~ x + z' and a dataframe, then automatically handles categorical encoding, intercept inclusion, and matrix construction. The package outputs model matrices as pandas DataFrames, NumPy arrays, or SciPy sparse matrices, making it useful for feeding data into machine learning and statistical models.
The library supports input from pandas, Polars, PyArrow, and any dataframe library compatible with narwhals. It also allows encoding choices from one dataset to be reused on others, supports symbolic differentiation of formulas, and includes extensible plugins for custom input/output formats. Seven runtime dependencies (numpy, pandas, scipy, narwhals, interface-meta, typing-extensions, wrapt) keep the installation lightweight.
Use it for:
- Prepare training data for linear regression or GLM models by converting formulas into design matrices with automatic categorical encoding.
- Reuse categorical encodings learned on a training set when transforming new test or production data.
- Work with Polars or PyArrow dataframes while maintaining formula-based data transformation workflows.
- Generate sparse model matrices for high-dimensional datasets to reduce memory footprint.
- Integrate formula-based preprocessing into statistical modeling pipelines used by statsmodels or custom estimators.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Formulaic converts tabular data into model matrices using Wilkinson formula syntax, supporting dense and sparse outputs across multiple dataframe libraries including pandas, Polars, and PyArrow.
Yes. Formulaic is actively maintained, MIT-licensed, has low install friction, and fills a clear gap as a high-performance successor to patsy for formula-based model matrix generation. It supports modern dataframe libraries (Polars, PyArrow) and is already adopted by established projects like Glum, Lifelines, and Linearmodels. No known vulnerabilities.
Install
formulaic on PyPI
pip
pip install formulaicuv
uv add formulaicpoetry
poetry add formulaicInstalling formulaic
Before you install
Low friction installation with seven runtime dependencies (numpy, pandas, scipy, narwhals, interface-meta, typing-extensions, wrapt). Active maintenance with a recent release 73 days ago.
License in practice
MIT license permits unrestricted commercial and private use, modification, and distribution with minimal obligations.
Quickstart
pip install formulaic
from formulaic import Formula
import pandas
df = pandas.DataFrame({'y': [0, 1, 2], 'x': ['A', 'B', 'C'], 'z': [0.3, 0.1, 0.2]})
y, X = Formula('y ~ x + z').get_model_matrix(df)
Verify before relying
- Whether symbolic differentiation of formulas is production-ready or experimental
- Performance benchmarks against R and patsy on current hardware
- Extent of narwhals integration beyond the listed dataframe types
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 7 — interface-meta, narwhals, numpy, pandas, scipy, typing-extensions, wrapt |
| Maintenance | actively maintained — 73 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 3,889,607/month — #2,459 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: formulaic-1.2.2-py3-none-any.whl
Tags
More Mathematics packages
NetworkX provides data structures and…
permissive · top 1,000 on PyPI
kiwisolverkiwisolver is a Python binding to a fast C++…
permissive · top 1,000 on PyPI
sympySymPy is a Python library for symbolic…
permissive · top 1,000 on PyPI
contourpyContourPy calculates contours of 2D…
permissive · top 1,000 on PyPI
torchPyTorch provides GPU-accelerated tensor…
permissive · top 1,000 on PyPI
onnxruntimeonnxruntime loads and executes Open Neural…
permissive · top 1,000 on PyPI
fastf1FastF1 provides Python access to Formula 1…
permissive · top 5,000 on PyPI
formulaic-contrastsBuilds arbitrary contrasts for statistical…
permissive · top 15,000 on PyPI
patsyPatsy converts R-style statistical formulas…
permissive · top 1,000 on PyPI
tabmatProvides efficient matrix classes for tabular…
unclear · top 15,000 on PyPI
spglmFits Gaussian, Poisson, QuasiPoisson, and…
permissive · top 15,000 on PyPI
formulasParses and compiles Excel formulas and…
copyleft · top 5,000 on PyPI
itablesRenders Pandas and Polars DataFrames as…
permissive · top 5,000 on PyPI
qdldlProvides a Python interface to QDLDL, a free…
permissive · top 5,000 on PyPI
narwhalsNarwhals provides a lightweight compatibility…
permissive · top 1,000 on PyPI
anndataanndata handles annotated data matrices in…
permissive · top 5,000 on PyPI