Home

Awesome

<div align="center"> <h1><img src="https://github.com/DAGWorks-Inc/hamilton/assets/2328071/feb6abaa-b6d5-4271-a320-0ae4a18d8aa7" width="50"/> Hamilton β€” portable & expressive <br> data transformation DAGs</h1> <a href='https://hamilton.dagworks.io/en/latest/?badge=latest'> <img src='https://readthedocs.org/projects/hamilton/badge/?version=latest' alt='Documentation Status' /> </a><a href="https://www.python.org/downloads/" target="_blank"> <img src="https://img.shields.io/badge/python-3.8|%203.9|%203.10|%203.11|%203.12-blue.svg" alt="Python supported"/> </a> <a href="https://pypi.org/project/sf-hamilton/" target="_blank"> <img src="https://badge.fury.io/py/sf-hamilton.svg" alt="PyPi Version"/> </a> <a href="https://pepy.tech/project/sf-hamilton" target="_blank"> <img src="https://pepy.tech/badge/sf-hamilton" alt="Total Downloads"/> </a> <a href="https://pepy.tech/project/sf-hamilton" target="_blank"> <img src="https://static.pepy.tech/badge/sf-hamilton/month" alt="Total Monthly Downloads"/> </a> <br/> <a target="_blank" href="https://linkedin.com/showcase/dagster" style="background:none"> <img src="https://img.shields.io/badge/DAGWorks-Follow-purple.svg?logo=linkedin" /> </a> <a href="https://join.slack.com/t/hamilton-opensource/shared_invite/zt-2niepkra8-DGKGf_tTYhXuJWBTXtIs4g" target="_blank"> <img src="https://img.shields.io/badge/Hamilton-Join-purple.svg?logo=slack" alt="Hamilton Slack"/> </a> <a href="https://twitter.com/hamilton_os" target="_blank"> <img src="https://img.shields.io/badge/HamiltonOS-Follow-purple.svg?logo=X"/> </a> <a href="https://twitter.com/dagworks" target="_blank"> <img src="https://img.shields.io/badge/DAGWorks-Follow-purple.svg?logo=X"/> </a> </div> <br></br>

Hamilton is a lightweight Python library for directed acyclic graphs (DAGs) of data transformations. Your DAG is portable; it runs anywhere Python runs, whether it's a script, notebook, Airflow pipeline, FastAPI server, etc. Your DAG is expressive; Hamilton has extensive features to define and modify the execution of a DAG (e.g., data validation, experiment tracking, remote execution).

To create a DAG, write regular Python functions that specify their dependencies with their parameters. As shown below, it results in readable code that can always be visualized. Hamilton loads that definition and automatically builds the DAG for you!

<div align="center"> <img src="./docs/_static/abc_highlight.png" alt="Create a project" width="65%"/> </div> <div align="center"> Functions <code>B()</code> and <code>C()</code> refer to function <code>A</code> via their parameters </div> <br>

Hamilton brings modularity and structure to any Python application moving data: ETL pipelines, ML workflows, LLM applications, RAG systems, BI dashboards, and the Hamilton UI allows you to automatically visualize, catalog, and monitor execution.

Hamilton is great for DAGs, but if you need loops or conditional logic to create an LLM agent or a simulation, take a look at our sister library Burr πŸ€– .

Installation

Hamilton supports Python 3.8+. We include the optional visualization dependency to display our Hamilton DAG. For visualizations, Graphviz needs to be installed on your system separately.

pip install "sf-hamilton[visualization]"

To use the Hamilton UI, install the ui and sdk dependencies.

pip install "sf-hamilton[ui,sdk]"

To try Hamilton in the browser, visit www.tryhamilton.dev

Why use Hamilton?

Data teams write code to deliver business value, but few have the resources to standardize practices and provide quality assurance. Moving from proof-of-concept to production and cross-function collaboration (e.g., data science, engineering, ops) remain challenging for teams, big or small. Hamilton is designed to help throughout a project's lifecycle:

Hamilton UI

You can track the execution of your Hamilton DAG in the Hamilton UI. It automatically populates a data catalog with lineage / tracing and provides execution observability to inspect results and debug errors. You can run it as a local server or a self-hosted application using Docker.

<p align="center"> <img src="./docs/_static/hamilton_1.jpeg" alt="Description1" width="30%" style="margin-right: 20px;"/> <img src="./docs/_static/hamilton_2.jpeg" alt="Description2" width="30%" style="margin-right: 20px;"/> <img src="./docs/_static/hamilton_3.jpeg" alt="Description3" width="30%"/> </p> <p align="center"> <em>DAG catalog, automatic dataset profiling, and execution tracking</em> </p>

Get started with the Hamilton UI

  1. To use the Hamilton UI, install the dependencies (see Installation section) and start the server with

    hamilton ui
    
  2. On the first connection, create a username and a new project (the project_id should be 1).

<div align="center"> <img src="./docs/_static/new_project.png" alt="Create a project" width="70%"/> </div> <br>
  1. Track your Hamilton DAG by creating a HamiltonTracker object with your username and project_id and adding it to your Builder. Now, your DAG will appear in the UI's catalog and all executions will be tracked!

    from hamilton import driver
    from hamilton_sdk.adapters import HamiltonTracker
    import my_dag
    
    # use your `username` and `project_id`
    tracker = HamiltonTracker(
       username="my_username",
       project_id=1,
       dag_name="hello_world",
    )
    
    # adding the tracker to the `Builder` will add the DAG to the catalog
    dr = (
       driver.Builder()
       .with_modules(my_dag)
       .with_adapters(tracker)  # add your tracker here
       .build()
    )
    
    # executing the `Driver` will track results
    dr.execute(["C"])
    

Documentation & learning resources

How does Hamilton compare to X?

Hamilton is not an orchestrator (you might not need one), nor a feature store (but you can use it to build one!). Its purpose is to help you structure and manage data transformations. If you know dbt, Hamilton does for Python what dbt does for SQL.

Another way to frame it is to think about the different layers of a data stack. Hamilton is at the asset layer. It helps you organize data transformations code (the expression layer), manage changes, and validate & test data.

<div align="center" style="width: 100%"> <table> <colgroup> <col style="width: 20%"> <col style="width: 40%"> <col style="width: 40%"> </colgroup> <thead> <tr> <th>Layer</th> <th>Purpose</th> <th>Example Tools</th> </tr> </thead> <tbody> <tr> <td>Orchestration</td> <td>Operational system for the creation of assets</td> <td>Airflow, Metaflow, Prefect, Dagster</td> </tr> <tr> <td>Asset</td> <td>Organize expressions into meaningful units <br> (e.g., dataset, ML model, table)</td> <td><b>Hamilton</b>, dbt, dlt, SQLMesh, <a href="https://github.com/dagworks-inc/burr">Burr</a></td> </tr> <tr> <td>Expression</td> <td>Language to write data transformations</td> <td>pandas, SQL, polars, Ibis, LangChain</td> </tr> <tr> <td>Execution</td> <td>Perform data transformations</td> <td>Spark, Snowflake, DuckDB, RAPIDS</td> </tr> <tr> <td>Data</td> <td>Physical representation of data, inputs and outputs</td> <td>S3, Postgres, file system, Snowflake</td> </tr> </tbody> </table> </div>

See our page on Why use Hamilton? and framework code comparisons for more information.

πŸ“‘ License

Hamilton is released under the BSD 3-Clause Clear License. See LICENSE for details.

🌎 Community

πŸ‘¨β€πŸ’» Contributing

We're very supportive of changes by new contributors, big or small! Make sure to discuss potential changes by creating an issue or commenting on an existing one before opening a pull request. Good first contributions include creating an example or an integration with your favorite Python library!

To contribute, checkout our contributing guidelines, our developer setup guide, and our Code of Conduct.

😎 Used by

Hamilton was started at Stitch Fix before the original creators founded DAGWorks Inc! The library is battle-tested and has been supporting production use cases since 2019.

Read more about the origin story.

🀝 Code Contributors

Contributors

πŸ™Œ Special Mentions & 🦟 Bug Hunters

Thanks to our awesome community and their active involvement in the Hamilton library.

Nils Olsson, MichaΕ‚ Siedlaczek, Alaa Abedrabbo, Shreya Datar, Baldo Faieta, Anwar Brini, Gourav Kumar, Amos Aikman, Ankush Kundaliya, David Weselowski, Peter Robinson, Seth Stokes, Louis Maddox, Stephen Bias, Anup Joseph, Jan Hurst, Flavia Santos, Nicolas Huray, Manabu Niseki, Kyle Pounder, Alex Bustos, Andy Day, Alexander Cai, Nils MΓΌller-Wendt, Paul Larsen, Kemal Eren, Jernej Frank, Noah Ridge

πŸŽ“ Citations

We'd appreciate citing Hamilton by referencing one of the following:

@inproceedings{DBLP:conf/vldb/KrawczykI22,
  title     = {Hamilton: a modular open source declarative paradigm for high level
               modeling of dataflows},
  author    = {Stefan Krawczyk and Elijah ben Izzy},
  editor    = {Satyanarayana R. Valluri and Mohamed Za{\"{\i}}t},
  booktitle = {1st International Workshop on Composable Data Management Systems,
               CDMS@VLDB 2022, Sydney, Australia, September 9, 2022},
  year      = {2022},
  url       = {https://cdmsworkshop.github.io/2022/Proceedings/ShortPapers/Paper6\_StefanKrawczyk.pdf},
  timestamp = {Wed, 19 Oct 2022 16:20:48 +0200},
  biburl    = {https://dblp.org/rec/conf/vldb/KrawczykI22.bib},
  bibsource = {dblp computer science bibliography, https://dblp.org}
}
@inproceedings{CEURWS:conf/vldb/KrawczykIQ22,
  title     = {Hamilton: enabling software engineering best practices for data transformations via generalized dataflow graphs},
  author    = {Stefan Krawczyk and Elijah ben Izzy and Danielle Quinn},
  editor    = {Cinzia Cappiello and Sandra Geisler and Maria-Esther Vidal},
  booktitle = {1st International Workshop on Data Ecosystems co-located with 48th International Conference on Very Large Databases (VLDB 2022)},
  pages     = {41--50},
  url       = {https://ceur-ws.org/Vol-3306/paper5.pdf},
  year      = {2022}
}

πŸ“š Libraries built on / for Hamilton