--- id: formulaic version: "1.2.2" license: MIT license_treatment: permissive maintenance: active --- # formulaic — An implementation of Wilkinson formulas. License: permissive · Maintenance: active · Downloads: 3.9M/mo ## 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 above — 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 pip install formulaic uv add formulaic 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_current - Install friction: low - Maintenance: active - Downloads: 3.9M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags wilkinson formulas python, model matrix generation, dataframe to matrix conversion, formula parsing statistical, sparse matrix from dataframe, categorical encoding formulas, polars pandas arrow formulas, statistical-modeling, dataframe-transformation, formula-dsl [View on SkillFed](https://skillfed.io/packages/formulaic) · [View on PyPI](https://pypi.org/project/formulaic/)