---
title: "Hamilton"
description: "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."
canonical: "https://motherduck.com/glossary/hamilton/"
related:
  - title: "What if a full data pipeline was one prompt away?"
    url: "https://motherduck.com/blog/full-data-pipeline-one-prompt/"
  - title: "Orchestration | MotherDuck Docs"
    url: "https://motherduck.com/docs/integrations/orchestration/"
  - title: "Together AI: Scaling a Data Platform while Scaling the Company"
    url: "https://motherduck.com/case-studies/together-ai-scaling-with-motherduck/"
---

# 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.

```python
# 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()
```

```python
# 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.