{"library":"sf-hamilton","title":"Hamilton","description":"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.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install sf-hamilton","pip install \"sf-hamilton[pandas, visualization]\""],"cli":{"name":"hamilton","version":"Traceback (most recent call last):"}},"imports":["from hamilton import driver","from hamilton import function_modifiers as fm"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"from hamilton import driver\nfrom hamilton import function_modifiers as fm\nimport pandas as pd\n\n# Define functions representing nodes in the DAG\ndef initial_transactions() -> pd.DataFrame:\n    \"\"\"Simulate initial transaction data.\"\"\"\n    return pd.DataFrame({\n        'user_id': [1, 1, 2, 2, 3],\n        'amount': [10.0, 15.0, 5.0, 20.0, 30.0],\n        'date': pd.to_datetime(['2024-01-01', '2024-01-02', '2024-01-01', '2024-01-03', '2024-01-02'])\n    })\n\ndef daily_spend(initial_transactions: pd.DataFrame) -> pd.DataFrame:\n    \"\"\"Calculate daily spend per user.\"\"\"\n    return initial_transactions.groupby(['user_id', 'date'])['amount'].sum().reset_index()\n\n@fm.config.when(period='30_day')\ndef avg_spend__30_day(daily_spend: pd.DataFrame) -> pd.DataFrame:\n    \"\"\"Calculate average daily spend over a configured 30-day period.\"\"\"\n    # In a real scenario, this would filter for the last 30 days\n    return daily_spend.groupby('user_id')['amount'].mean().reset_index().rename(columns={'amount': 'avg_30_day_spend'})\n\n# Create and run the driver\ndr = driver.Driver({'period': '30_day'})\nresult = dr.execute(final_outputs=['avg_spend__30_day'])\n\nprint(result['avg_spend__30_day'])","lang":"python","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}