Hamilton
Hamilton is an open-source Python micro-framework for defining data and feature transformation pipelines as plain functions, which it automatically assembles into a dependency graph.
Overview
Hamilton is a lightweight Python library for expressing dataflows — chains of data or feature transformations — as ordinary Python functions rather than as an explicit graph object. It originated at Stitch Fix in 2019, where it was built to manage the growing complexity of shared code that produced large, feature-rich dataframes for time-series forecasting. The original creators later founded DAGWorks Inc. to steward the project, and Hamilton has since been contributed to the Apache Software Foundation, where it is currently developed as Apache Hamilton (incubating).
How it works
In Hamilton, each function's name becomes the name of an output, and its parameter names declare its dependencies on other functions' outputs. Hamilton inspects the module, builds a directed acyclic graph from these naming conventions, and executes only the functions needed to produce the outputs that were requested.
Copy code
# features.py
import pandas as pd
def order_amount(raw_orders: pd.DataFrame) -> pd.Series:
return raw_orders["amount"]
def order_amount_mean_7d(order_amount: pd.Series) -> pd.Series:
return order_amount.rolling(7).mean()
Copy code
# run.py
from hamilton import driver
import features
dr = driver.Builder().with_modules(features).build()
result = dr.execute(["order_amount_mean_7d"], inputs={"raw_orders": raw_orders_df})
Hamilton resolves that order_amount_mean_7d depends on order_amount, executes both in order, and returns just the requested output.
Why it matters
Hamilton is not a scheduler or infrastructure orchestrator like Airflow or Prefect — it has no concept of cron schedules or retries on its own. Instead, it's a way to write testable, self-documenting, dependency-tracked transformation logic that can be called from within an orchestrator's task, or run standalone in a notebook or script. This separation lets teams unit-test individual feature functions in isolation, visualize the resulting dependency graph, and reuse the same transformation code across batch pipelines, notebooks, and services, rather than duplicating logic or maintaining one large, monolithic transformation script.
Related terms
Data transformation is the process of converting data from its raw, source format into a structured form suited to analysis — through operations like cleaning, joining, aggregating, and reshaping.
Apache Airflow →Apache Airflow is an open-source platform for programmatically authoring, scheduling, and monitoring workflows, where pipelines are defined as directed acyclic graphs (DAGs) in Python.
Data orchestration →Data orchestration is the automated coordination, scheduling, and monitoring of interdependent data tasks—such as extracts, transformations, and loads—so they run in the correct order and recover cleanly from failure.
SQL function →A SQL function is a reusable piece of code that performs a specific operation and returns a result.
Directed acyclic graph (DAG) →A directed acyclic graph (DAG) is a graph of nodes connected by one-way edges with no cycles, used to represent task dependencies so that execution order is unambiguous.
Prefect →Prefect is a Python-native workflow orchestration framework that lets engineers turn ordinary functions into scheduled, observable, and fault-tolerant data pipelines.
FAQS
No. Hamilton defines the transformation logic and dependency graph for data or features; it's commonly invoked as a step inside an orchestrator like Airflow or Prefect rather than replacing them.
It turns implicit dependencies buried in long scripts into explicit, named functions that form a self-documenting, independently testable graph, which makes large transformation codebases easier to maintain and reason about.
No. Hamilton works with any Python object type returned by a function, including pandas, Polars, or plain Python data structures; it doesn't require a specific dataframe library.
