GraphReduce
GraphReduce turns related tables into a single, model-ready feature table. You describe tables as nodes, foreign-key relationships as edges, and the entity you want to model as the parent node. GraphReduce then filters data to the correct point in time, aggregates child rows, and joins the results back to the parent.
It is designed for relational machine-learning workloads where correctness is as important as scale:
- Known output grain. Reduced relations produce one row per parent key.
- Point-in-time features. Historical features and future labels use separate windows around a cutoff.
- Traceable columns. Every node has a unique prefix that records column lineage after joins.
- Automatic or custom features. Start with schema-aware aggregation, then replace any node operation with application-specific logic.
- Multiple execution engines. Use dataframe backends or compile the graph into SQL.
Documentation · Quickstart · Examples
Mental model
Suppose the source data contains customers and orders:
customers (one row per customer)
id name
orders (many rows per customer)
id customer_id ts amount
Model the relationship as:
customers.id 1 ───── * orders.customer_id
parent relation
With customers as the parent and reduce=True on the edge, GraphReduce:
- loads and prefixes both tables;
- keeps order rows inside the historical feature window;
- aggregates orders by
customer_id; - left-joins those features to customers; and
- optionally computes labels from a separate future window.
The result remains at customer grain: one row per customer.
Installation
Install the dataframe-oriented core:
pip install graphreduce
Install only the optional integrations you need:
pip install "graphreduce[duckdb]"
pip install "graphreduce[spark]"
pip install "graphreduce[daft]"
pip install "graphreduce[trino]"
pip install "graphreduce[relbench]"
graphreduce[all] installs all optional integrations. For local development:
git clone https://github.com/wesmadrigal/graphreduce.git
cd graphreduce
pip install -e ".[dev]"
Quickstart
The example below expects two local CSV files with the columns shown in the mental model above.
import datetime as dt
from graphreduce.enum import ComputeLayerEnum, PeriodUnit
from graphreduce.graph_reduce import GraphReduce
from graphreduce.node import DynamicNode
customers = DynamicNode(
fpath="customers.csv",
fmt="csv",
pk="id",
prefix="cust",
compute_layer=ComputeLayerEnum.pandas,
)
orders = DynamicNode(
fpath="orders.csv",
fmt="csv",
pk="id",
prefix="ord",
date_key="ts",
compute_layer=ComputeLayerEnum.pandas,
)
graph = GraphReduce(
name="customer_features",
parent_node=customers,
compute_layer=ComputeLayerEnum.pandas,
cut_date=dt.datetime(2024, 1, 1),
compute_period_val=365,
compute_period_unit=PeriodUnit.day,
auto_features=True,
label_node=orders,
label_field="id",
label_operation="count",
label_period_val=30,
label_period_unit=PeriodUnit.day,
)
graph.add_node(customers)
graph.add_node(orders)
graph.add_entity_edge(
parent_node=customers,
relation_node=orders,
parent_key="id",
relation_key="customer_id",
reduce=True,
)
graph.do_transformations()
features = graph.parent_node.df
print(features.head())
Important details:
parent_node=customerssets the output grain.prefixvalues must be unique across the graph.date_key="ts"makes the orders node eligible for time filtering.compute_period_val=365uses non-null order timestamps strictly before the cutoff.cutoff_boundary="strict"is the node default; set it to"inclusive"when records stamped exactly at the feature cutoff are already observable. The setting is per node, so outcome-history relations can remain strict while ordinary event relations are inclusive.label_period_val=30uses label rows strictly after the cutoff.reduce=Trueaggregates orders before joining them to customers.- The materialized dataframe is available at
graph.parent_node.df.
Because labels are joined from an aggregate relation, a parent with no event in the label window receives a null label. Convert that null to zero only when “no event” has that meaning for your target.
For a runnable version backed by repository sample data, see Hello World.
Choose an execution path
The graph topology, time-window configuration, and intended output grain stay stable across engines. Backend-specific expressions, clients, storage access, and materialization behavior may still need engine-specific configuration.
| Need | Node type | Entry point |
|---|---|---|
| Automatic dataframe features | DynamicNode |
do_transformations() |
| Custom dataframe operations | GraphReduceNode subclass |
do_transformations() |
| SQL compilation and execution | SQLNode or backend subclass |
do_transformations_sql() |
Available compute layers are defined by ComputeLayerEnum. The most developed
paths in the current documentation are pandas, Dask, Spark, Daft, DuckDB,
SQLite, Athena, Redshift, Snowflake, Databricks SQL, PostgreSQL, MySQL, and
Trino. Backend-specific clients and optional dependencies still need to be
configured by the application.
Where to go next
- Fundamentals: execution order, cardinality, and time semantics.
- Abstractions: the responsibilities of graphs, nodes, and edges.
- Configuration: common graph, node, edge, and execution settings.
- Quickstart: a runnable two-table walkthrough using repository sample data.
- SQL auto-feature families: schema-aware, temporal, ordered-state, conditional, sequence, episode, semantic, and context features.
- End-to-end examples: complete multi-table and multi-backend workflows.
Citation
If GraphReduce contributes to your research or production work, please cite the project:
@software{madrigal_graphreduce_2026,
author = {Madrigal, Wes},
title = {GraphReduce: Relational Feature Engineering for Tabular Machine Learning},
year = {2026},
url = {https://github.com/wesmadrigal/GraphReduce}
}
For reproducible research, cite the specific GitHub release or commit used.
Project status
GraphReduce is under active development. The public surface is broad, and backend behavior is not perfectly uniform. Test a small representative graph on your chosen backend before scaling a production job. Please report defects and documentation gaps in the issue tracker.
License
GraphReduce is distributed under the MIT License. See LICENSE for the complete terms.
Changelog
Unreleased
- Added the SQL
statefeature family for cutoff-safe latest values, ordered lags, last-N row summaries, and latest categorical relationship state.
Notable changes to GraphReduce are documented here. The package build appends this file to the README shown on PyPI, and the same notes should be copied into the corresponding GitHub Release.
[1.10.16] - 2026-09-15
Added
- Added per-node
cutoff_boundary="strict" | "inclusive"semantics across fixed and entity-specific feature cutoffs. This lets outcome-history nodes exclude same-cutoff labels while ordinary event nodes include records known at the cutoff.
[1.10.13] - 2026-09-01
Fixed
- Normalize Boolean temporal values to numeric
0.0/1.0expressions before generating windowed averages, variances, sums, and trends. This prevents DuckDB from receiving invalid operations such asAVG(BOOLEAN)while retaining Boolean activity signal.
[1.10.12] - 2026-08-31
Added
- Added the optional graph- and node-level
feature_propagation_max_functions_per_columnbudget. It prevents an already-derived feature from branching into every compatible aggregate at each additional graph hop. - Propagation budgets prioritize the aggregation that preserves the feature's semantics: max-to-max, min-to-min, sum-to-sum, count-to-sum, and average/share-to-average.
[1.10.11] - 2026-08-31
Added
- Added the optional graph- and node-level
feature_family_max_features_per_columnbudget for SQL automatic features. It independently caps each selected source column's derived expansion while leaving source-column selection underfeature_family_max_columns. - Conditional-family source budgets now count distinct source columns rather than individual category predicates. Bounded conditional and temporal expansions are ordered to retain category and lookback breadth under a cap.
[1.10.10] - 2026-08-31
Added
- Added bounded lifetime relationship diversity and repeat-ratio features to
the SQL
basefamily, excluding primary keys and effectively unique sample identifiers that merely restate row counts. - Added observed-history age, lifetime event intensity, and boolean positive
shares to the SQL
basefamily. - Added windowed relationship diversity, repeat ratios, per-day activity,
observation counts, variance, and recent-versus-prior trends to the SQL
temporalfamily. - Added SQLite and DuckDB coverage for fixed and per-entity dynamic cutoffs, including historical outcomes whose availability timestamp is used as the leakage-safe node date key.
[1.10.9] - 2026-08-31
Fixed
- Prevented SQL automatic feature inference from emitting numeric value
aggregates for columns whose inference samples contain no observed values.
This avoids persisting invalid operations such as
AVG(VARCHAR)when an all-null SQL string sample is represented by pandas with a numeric placeholder dtype.
[1.10.3] - 2026-08-27
Added
- Added optional graph-wide SQL auto-feature configuration for feature families, family budgets, time-series periods, categorical cardinality and top-value limits, text features, and inferred annotation limits.
Changed
- Graph-level feature settings now propagate to every node during graph hydration when explicitly supplied, while omitted settings preserve each node's existing configuration.
[1.10.2] - 2026-08-17
Added
- Added an automatic point-in-time age feature for graph parent nodes that define a date key.
Changed
- Extended node time-series periods with the graph compute horizon, expressed in whole days, whenever that horizon exceeds one year.
[1.10.1] - 2026-08-15
Added
- Added training-sample schema profiling with typed, model-agnostic feature manifests for structural, numerical, boolean, categorical, timestamp, and text columns.
- Added explicit cutoff-safety declarations for unavailable or future-derived source columns.
- Added
GraphReduceNode.infer_feature_manifest()to profile a node and optionally apply its safe source-column plan.
Changed
- Exposed feature manifests and schema profiling through the top-level
graphreducepackage API. - Documented how typed manifests compose with the existing automatic categorical indicators and category-gated numeric reductions.
[1.10.0] - 2026-08-13
Added
- Added ordered composite primary keys and relationship keys while preserving the existing scalar-key API.
- Added native multi-column joins and reductions for pandas, Dask, Spark, Daft, and SQL compute layers.
- Added composite-key support for automatic features, labels, time-series grouping, frozen execution plans, and dynamic date-node propagation.
- Added early validation for invalid key definitions, mismatched relationship key arity, and missing join columns.
Changed
- Added
colabbrs()andkey_sql()helpers for custom node implementations that operate on scalar or composite keys. - Composite primary-key episode features retain row-count metrics but skip dialect-dependent distinct-primary-key metrics with an explicit warning.
Fixed
- Fixed reverse-edge joins so their parent and relation key mappings are correctly inverted.
- Prevented automatic feature generation from aggregating composite reduction key components as value columns.
[1.9.17] - 2026-07-28
Added
- Added opt-in SQL auto-feature families for conditional, temporal, episode, semantic, sequence, and peer-context features.
- Added automatic categorical, text, and gated-numeric SQL annotations with configurable cardinality and feature limits.
- Added a
relbenchoptional dependency group for RelBench, CatBoost, PyArrow, and scikit-learn integrations. - Added RelBench task selection and parallel training-frame generation utilities to the end-to-end examples.
Changed
- Isolated temporary SQL tables with a per-execution namespace so concurrent GraphReduce runs do not collide.
- Improved generated SQL feature schemas across cut dates and bounded wide training frames to keep feature generation predictable.
Fixed
- Fixed SQL inference sampling for wide or sparsely populated relations.
- Fixed date-node key propagation through undated intermediate SQL nodes.
- Fixed SQL auto-feature type handling for string-backed numeric semantic types, identifier-like columns, and collection-valued columns.
- Propagated Athena, Redshift, and DuckDB query failures instead of allowing invalid feature plans to continue.
- Handled constant regression targets in the RelBench training workflow.
For older versions, see the PyPI release history.
Metadata
Release files for graphreduce 1.10.17
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| graphreduce-1.10.17.tar.gz | 124.7 kB | Without provenance | Details for graphreduce-1.10.17.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| graphreduce-1.10.17-py3-none-any.whl | Python 3 | none | any | Details for graphreduce-1.10.17-py3-none-any.whl |
Total release size: 218.6 kB
Release files / graphreduce-1.10.17.tar.gz
| Download URL | graphreduce-1.10.17.tar.gz |
|---|---|
| Size | 124.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
aa1f80da83c4a7bd00d1b2c4259ecab41b03d277d93041c0451c75243a3f7c29
|
|
BLAKE2b-256 checksum How to use checksums |
e77526e987ba3bff67e252c2290e86d005aaac55d51ab04a53229c6622cbd7a5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.4
|
Release files / graphreduce-1.10.17-py3-none-any.whl
| Download URL | graphreduce-1.10.17-py3-none-any.whl |
|---|---|
| Size | 93.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
65844ff9f7f2203babbde759d160c01843262ab9e1fc74e7a63bd144484f6248
|
|
BLAKE2b-256 checksum How to use checksums |
22bda9aa6497e23ab46813a7e5015fb7d1181f26918b08ef1456b41106b7c597
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.4
|
Security for graphreduce 1.10.17
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.