skillfed

formulaic

An implementation of Wilkinson formulas.

formulaic v1.2.2 3.9M downloads/30d#2,459 on PyPI463
Permissive license MIT Active released

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 formulaic

uv

uv add formulaic

poetry

poetry add formulaic

Installing 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

Development Status :: 5 - Production/StableEnvironment :: ConsoleIntended Audience :: DevelopersIntended Audience :: Information TechnologyIntended Audience :: Science/ResearchLicense :: OSI Approved :: MIT LicenseNatural Language :: EnglishOperating System :: OS IndependentProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.9Topic :: Scientific/Engineering :: Mathematics

Tags

wilkinson formulas pythonmodel matrix generationdataframe to matrix conversionformula parsing statisticalsparse matrix from dataframecategorical encoding formulaspolars pandas arrow formulas
statistical-modelingdataframe-transformationformula-dsl

More Mathematics packages