Registry / data / sf-hamilton

sf-hamilton

JSON →
library1.90.0pypypi✓ verified 85d ago

Hamilton (current version 1.89.0) is a Python micro-framework for defining dataflows as functions, enabling modular, testable, and maintainable data pipelines. It represents data transformations as a directed acyclic graph (DAG) where nodes are Python functions and edges are dependencies, making it easy to build complex dataframes. It has an active release cadence with frequent updates.

pip install sf-hamilton
INSTALL
IMPORT
SIG · SF-HAMILTON
S
sf-hamilton
datapythonv1.90.0
Install
8.5s avg
Import
1389ms
Disk
185MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.90.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 1.431s · 183.4MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 8.5s · import 1.348s · 176MB
185MB installed
● package 185MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Driver
from hamilton import driver
function_modifiers
from hamilton import function_modifiers as fm

This quickstart defines a simple dataflow: initial transactions are aggregated into daily spend, and then an average daily spend over a specific period is calculated. It demonstrates function-based node definition, the use of a function modifier (`@fm.config.when`), and executing the `Driver` to obtain a specific output.

from hamilton import driver from hamilton import function_modifiers as fm import pandas as pd # Define functions representing nodes in the DAG def initial_transactions() -> pd.DataFrame: """Simulate initial transaction data.""" return pd.DataFrame({ 'user_id': [1, 1, 2, 2, 3], 'amount': [10.0, 15.0, 5.0, 20.0, 30.0], 'date': pd.to_datetime(['2024-01-01', '2024-01-02', '2024-01-01', '2024-01-03', '2024-01-02']) }) def daily_spend(initial_transactions: pd.DataFrame) -> pd.DataFrame: """Calculate daily spend per user.""" return initial_transactions.groupby(['user_id', 'date'])['amount'].sum().reset_index() @fm.config.when(period='30_day') def avg_spend__30_day(daily_spend: pd.DataFrame) -> pd.DataFrame: """Calculate average daily spend over a configured 30-day period.""" # In a real scenario, this would filter for the last 30 days return daily_spend.groupby('user_id')['amount'].mean().reset_index().rename(columns={'amount': 'avg_30_day_spend'}) # Create and run the driver dr = driver.Driver({'period': '30_day'}) result = dr.execute(final_outputs=['avg_spend__30_day']) print(result['avg_spend__30_day'])
hamilton --version
Debug
Known issues
breakingMajor Refactor in Version 1.0.0. If upgrading from versions prior to 1.0.0, expect significant breaking changes, including how configuration is handled and the removal of `base_functions`. The `function_modifiers.extract_fields` replaced older patterns.
fix
Consult the official migration guide for versions 1.0.0 and above. Redesign dataflow functions to align with the new Hamilton paradigm.
affects: <1.0.0
gotchaFunction Parameter Naming is Crucial. Hamilton resolves dependencies by matching function parameter names to other function names (or configured variable names). A typo in a parameter name will lead to a 'missing required parameter' error, as the DAG cannot be correctly constructed.
fix
Ensure that the parameter names in your functions exactly match the names of the functions producing their required inputs, or the names of initial inputs provided to the Driver.
affects: All
gotchaOutputs Must Be Explicit. When using `driver.execute()` or `driver.materialize()`, you must explicitly list all desired outputs in the `final_outputs` parameter. If a function is defined but not specified as an output or a dependency for a requested output, it won't be executed.
fix
Always add the name of the desired output function(s) to the `final_outputs` list in your `driver.execute()` or `driver.materialize()` call.
affects: All
Errors
Common errors & fixes
hamilton.graph.GraphException: Nodes ['some_output_name'] were not found in the graph.
The requested output function `some_output_name` does not exist in the DAG. This could be due to a typo, the function not being defined, or not being accessible to the `Driver`.
fix
Check the spelling of `some_output_name`. Ensure the function `def some_output_name(...)` is correctly defined in an imported module or directly in the script, and that the `Driver` is aware of it.
TypeError: Missing required parameter for function 'my_transform': 'some_dependency_name'
The function `my_transform` requires an input named `some_dependency_name`, but no function named `some_dependency_name` exists in the graph, nor was it provided as an initial input to the `Driver`.
fix
Define a function `def some_dependency_name(...)` to provide the required input, or pass `some_dependency_name` as an initial input argument to the `Driver`'s constructor or `execute` method (e.g., `driver.execute(inputs={'some_dependency_name': ...}, ...) `).
ModuleNotFoundError: No module named 'pygraphviz' or OSError: failed to execute ['dot', '-V'], exit code 1, stderr: b'sh: dot: command not found\n'
You are trying to visualize the DAG (e.g., `driver.visualize_execution()`) but the necessary visualization tools (`pygraphviz` Python package and/or the `graphviz` system tool) are not installed or not in the system PATH.
fix
Install `pygraphviz` via `pip install "sf-hamilton[visualization]"`. For the underlying `graphviz` command-line tool, install it via your system's package manager (e.g., `sudo apt-get install graphviz` on Debian/Ubuntu, `brew install graphviz` on macOS) and ensure it's in your system's PATH.
Upgrade
Version history
1.90.0latest on PyPI · released Apr 25, 2026
Audit
Dependencies
pandasoptionalFundamental for working with DataFrames, which is Hamilton's primary use case. Often installed as part of a `[pandas]` extra or by the user's project.
pygraphvizoptionalRequired for visualizing the DAG (e.g., `driver.visualize_execution()`). Also requires the system-level `graphviz` executable.
Agent activity
26 hits · last 30 days
node
22
OpenAI (training)
1
Resources
sf-hamilton — pip install sf-hamilton · libregistry