apache-hamilton 1.90.0.dev0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. apache_hamilton-1.90.0.dev0.dist-info/METADATA +407 -0
  2. apache_hamilton-1.90.0.dev0.dist-info/RECORD +151 -0
  3. apache_hamilton-1.90.0.dev0.dist-info/WHEEL +4 -0
  4. apache_hamilton-1.90.0.dev0.dist-info/entry_points.txt +9 -0
  5. apache_hamilton-1.90.0.dev0.dist-info/licenses/DISCLAIMER +10 -0
  6. apache_hamilton-1.90.0.dev0.dist-info/licenses/LICENSE +228 -0
  7. apache_hamilton-1.90.0.dev0.dist-info/licenses/NOTICE +5 -0
  8. hamilton/__init__.py +24 -0
  9. hamilton/ad_hoc_utils.py +132 -0
  10. hamilton/async_driver.py +465 -0
  11. hamilton/base.py +466 -0
  12. hamilton/caching/__init__.py +16 -0
  13. hamilton/caching/adapter.py +1475 -0
  14. hamilton/caching/cache_key.py +70 -0
  15. hamilton/caching/fingerprinting.py +287 -0
  16. hamilton/caching/stores/__init__.py +16 -0
  17. hamilton/caching/stores/base.py +242 -0
  18. hamilton/caching/stores/file.py +140 -0
  19. hamilton/caching/stores/memory.py +297 -0
  20. hamilton/caching/stores/sqlite.py +282 -0
  21. hamilton/caching/stores/utils.py +40 -0
  22. hamilton/cli/__init__.py +16 -0
  23. hamilton/cli/__main__.py +328 -0
  24. hamilton/cli/commands.py +126 -0
  25. hamilton/cli/logic.py +338 -0
  26. hamilton/common/__init__.py +76 -0
  27. hamilton/contrib/__init__.py +41 -0
  28. hamilton/data_quality/__init__.py +16 -0
  29. hamilton/data_quality/base.py +198 -0
  30. hamilton/data_quality/default_validators.py +560 -0
  31. hamilton/data_quality/pandera_validators.py +121 -0
  32. hamilton/dataflows/__init__.py +726 -0
  33. hamilton/dataflows/template/README.md +25 -0
  34. hamilton/dataflows/template/__init__.py +54 -0
  35. hamilton/dataflows/template/author.md +28 -0
  36. hamilton/dataflows/template/requirements.txt +0 -0
  37. hamilton/dataflows/template/tags.json +7 -0
  38. hamilton/dataflows/template/valid_configs.jsonl +1 -0
  39. hamilton/dev_utils/__init__.py +16 -0
  40. hamilton/dev_utils/deprecation.py +204 -0
  41. hamilton/driver.py +2112 -0
  42. hamilton/execution/__init__.py +16 -0
  43. hamilton/execution/debugging_utils.py +56 -0
  44. hamilton/execution/executors.py +502 -0
  45. hamilton/execution/graph_functions.py +421 -0
  46. hamilton/execution/grouping.py +430 -0
  47. hamilton/execution/state.py +539 -0
  48. hamilton/experimental/__init__.py +27 -0
  49. hamilton/experimental/databackend.py +61 -0
  50. hamilton/experimental/decorators/__init__.py +16 -0
  51. hamilton/experimental/decorators/parameterize_frame.py +233 -0
  52. hamilton/experimental/h_async.py +29 -0
  53. hamilton/experimental/h_cache.py +413 -0
  54. hamilton/experimental/h_dask.py +28 -0
  55. hamilton/experimental/h_databackends.py +174 -0
  56. hamilton/experimental/h_ray.py +28 -0
  57. hamilton/experimental/h_spark.py +32 -0
  58. hamilton/function_modifiers/README +40 -0
  59. hamilton/function_modifiers/__init__.py +121 -0
  60. hamilton/function_modifiers/adapters.py +900 -0
  61. hamilton/function_modifiers/base.py +859 -0
  62. hamilton/function_modifiers/configuration.py +310 -0
  63. hamilton/function_modifiers/delayed.py +202 -0
  64. hamilton/function_modifiers/dependencies.py +246 -0
  65. hamilton/function_modifiers/expanders.py +1230 -0
  66. hamilton/function_modifiers/macros.py +1634 -0
  67. hamilton/function_modifiers/metadata.py +434 -0
  68. hamilton/function_modifiers/recursive.py +908 -0
  69. hamilton/function_modifiers/validation.py +289 -0
  70. hamilton/function_modifiers_base.py +31 -0
  71. hamilton/graph.py +1153 -0
  72. hamilton/graph_types.py +264 -0
  73. hamilton/graph_utils.py +41 -0
  74. hamilton/htypes.py +450 -0
  75. hamilton/io/__init__.py +32 -0
  76. hamilton/io/data_adapters.py +216 -0
  77. hamilton/io/default_data_loaders.py +224 -0
  78. hamilton/io/materialization.py +500 -0
  79. hamilton/io/utils.py +158 -0
  80. hamilton/lifecycle/__init__.py +67 -0
  81. hamilton/lifecycle/api.py +833 -0
  82. hamilton/lifecycle/base.py +1130 -0
  83. hamilton/lifecycle/default.py +802 -0
  84. hamilton/log_setup.py +47 -0
  85. hamilton/models.py +92 -0
  86. hamilton/node.py +449 -0
  87. hamilton/plugins/README.md +48 -0
  88. hamilton/plugins/__init__.py +16 -0
  89. hamilton/plugins/dask_extensions.py +47 -0
  90. hamilton/plugins/dlt_extensions.py +161 -0
  91. hamilton/plugins/geopandas_extensions.py +49 -0
  92. hamilton/plugins/h_dask.py +331 -0
  93. hamilton/plugins/h_ddog.py +522 -0
  94. hamilton/plugins/h_diskcache.py +163 -0
  95. hamilton/plugins/h_experiments/__init__.py +22 -0
  96. hamilton/plugins/h_experiments/__main__.py +62 -0
  97. hamilton/plugins/h_experiments/cache.py +39 -0
  98. hamilton/plugins/h_experiments/data_model.py +68 -0
  99. hamilton/plugins/h_experiments/hook.py +219 -0
  100. hamilton/plugins/h_experiments/server.py +375 -0
  101. hamilton/plugins/h_kedro.py +152 -0
  102. hamilton/plugins/h_logging.py +454 -0
  103. hamilton/plugins/h_mcp/__init__.py +28 -0
  104. hamilton/plugins/h_mcp/__main__.py +33 -0
  105. hamilton/plugins/h_mcp/_helpers.py +129 -0
  106. hamilton/plugins/h_mcp/_templates.py +417 -0
  107. hamilton/plugins/h_mcp/server.py +328 -0
  108. hamilton/plugins/h_mlflow.py +335 -0
  109. hamilton/plugins/h_narwhals.py +134 -0
  110. hamilton/plugins/h_openlineage.py +400 -0
  111. hamilton/plugins/h_opentelemetry.py +167 -0
  112. hamilton/plugins/h_pandas.py +257 -0
  113. hamilton/plugins/h_pandera.py +117 -0
  114. hamilton/plugins/h_polars.py +304 -0
  115. hamilton/plugins/h_polars_lazyframe.py +282 -0
  116. hamilton/plugins/h_pyarrow.py +56 -0
  117. hamilton/plugins/h_pydantic.py +127 -0
  118. hamilton/plugins/h_ray.py +242 -0
  119. hamilton/plugins/h_rich.py +142 -0
  120. hamilton/plugins/h_schema.py +493 -0
  121. hamilton/plugins/h_slack.py +100 -0
  122. hamilton/plugins/h_spark.py +1380 -0
  123. hamilton/plugins/h_threadpool.py +125 -0
  124. hamilton/plugins/h_tqdm.py +122 -0
  125. hamilton/plugins/h_vaex.py +129 -0
  126. hamilton/plugins/huggingface_extensions.py +236 -0
  127. hamilton/plugins/ibis_extensions.py +93 -0
  128. hamilton/plugins/jupyter_magic.py +622 -0
  129. hamilton/plugins/kedro_extensions.py +117 -0
  130. hamilton/plugins/lightgbm_extensions.py +99 -0
  131. hamilton/plugins/matplotlib_extensions.py +108 -0
  132. hamilton/plugins/mlflow_extensions.py +216 -0
  133. hamilton/plugins/numpy_extensions.py +105 -0
  134. hamilton/plugins/pandas_extensions.py +1763 -0
  135. hamilton/plugins/plotly_extensions.py +150 -0
  136. hamilton/plugins/polars_extensions.py +71 -0
  137. hamilton/plugins/polars_implementations.py +25 -0
  138. hamilton/plugins/polars_lazyframe_extensions.py +302 -0
  139. hamilton/plugins/polars_post_1_0_0_extensions.py +877 -0
  140. hamilton/plugins/polars_pre_1_0_0_extension.py +836 -0
  141. hamilton/plugins/pydantic_extensions.py +98 -0
  142. hamilton/plugins/pyspark_pandas_extensions.py +47 -0
  143. hamilton/plugins/sklearn_plot_extensions.py +129 -0
  144. hamilton/plugins/spark_extensions.py +105 -0
  145. hamilton/plugins/vaex_extensions.py +51 -0
  146. hamilton/plugins/xgboost_extensions.py +91 -0
  147. hamilton/plugins/yaml_extensions.py +89 -0
  148. hamilton/registry.py +254 -0
  149. hamilton/settings.py +18 -0
  150. hamilton/telemetry.py +50 -0
  151. hamilton/version.py +18 -0
@@ -0,0 +1,224 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The ASF licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ import dataclasses
19
+ import io
20
+ import json
21
+ import os
22
+ import pathlib
23
+ import pickle
24
+ from collections.abc import Collection
25
+ from typing import Any
26
+
27
+ from hamilton.io.data_adapters import DataLoader, DataSaver
28
+ from hamilton.io.utils import get_file_metadata
29
+
30
+
31
+ @dataclasses.dataclass
32
+ class JSONDataLoader(DataLoader):
33
+ path: str
34
+
35
+ @classmethod
36
+ def applicable_types(cls) -> Collection[type]:
37
+ return [dict, list]
38
+
39
+ def load_data(self, type_: type) -> tuple[dict, dict[str, Any]]:
40
+ with open(self.path, "r") as f:
41
+ return json.load(f), get_file_metadata(self.path)
42
+
43
+ @classmethod
44
+ def name(cls) -> str:
45
+ return "json"
46
+
47
+
48
+ @dataclasses.dataclass
49
+ class JSONDataSaver(DataSaver):
50
+ path: str
51
+
52
+ @classmethod
53
+ def applicable_types(cls) -> Collection[type]:
54
+ return [dict, list]
55
+
56
+ @classmethod
57
+ def name(cls) -> str:
58
+ return "json"
59
+
60
+ def save_data(self, data: Any) -> dict[str, Any]:
61
+ with open(self.path, "w") as f:
62
+ json.dump(data, f)
63
+ return get_file_metadata(self.path)
64
+
65
+
66
+ @dataclasses.dataclass
67
+ class RawFileDataLoader(DataLoader):
68
+ path: str
69
+ encoding: str = "utf-8"
70
+
71
+ def load_data(self, type_: type) -> tuple[str, dict[str, Any]]:
72
+ with open(self.path, "r", encoding=self.encoding) as f:
73
+ return f.read(), get_file_metadata(self.path)
74
+
75
+ @classmethod
76
+ def applicable_types(cls) -> Collection[type]:
77
+ return [str]
78
+
79
+ @classmethod
80
+ def name(cls) -> str:
81
+ return "file"
82
+
83
+
84
+ @dataclasses.dataclass
85
+ class RawFileDataSaver(DataSaver):
86
+ path: str
87
+ encoding: str = "utf-8"
88
+
89
+ @classmethod
90
+ def applicable_types(cls) -> Collection[type]:
91
+ return [str]
92
+
93
+ @classmethod
94
+ def name(cls) -> str:
95
+ return "file"
96
+
97
+ def save_data(self, data: Any) -> dict[str, Any]:
98
+ with open(self.path, "w", encoding=self.encoding) as f:
99
+ f.write(data)
100
+ return get_file_metadata(self.path)
101
+
102
+
103
+ @dataclasses.dataclass
104
+ class RawFileDataSaverBytes(DataSaver):
105
+ path: pathlib.Path | str
106
+
107
+ @classmethod
108
+ def applicable_types(cls) -> Collection[type]:
109
+ return [bytes, io.BytesIO]
110
+
111
+ @classmethod
112
+ def name(cls) -> str:
113
+ return "file"
114
+
115
+ def save_data(self, data: bytes | io.BytesIO) -> dict[str, Any]:
116
+ if isinstance(data, io.BytesIO):
117
+ data_bytes = data.getvalue() # Extract bytes from BytesIO
118
+ else:
119
+ data_bytes = data
120
+
121
+ with open(self.path, "wb") as file:
122
+ file.write(data_bytes)
123
+
124
+ return get_file_metadata(str(self.path))
125
+
126
+
127
+ @dataclasses.dataclass
128
+ class PickleLoader(DataLoader):
129
+ path: str
130
+
131
+ @classmethod
132
+ def applicable_types(cls) -> Collection[type]:
133
+ return [object, Any]
134
+
135
+ @classmethod
136
+ def name(cls) -> str:
137
+ return "pickle"
138
+
139
+ def load_data(self, type_: type[object]) -> tuple[object, dict[str, Any]]:
140
+ with open(self.path, "rb") as f:
141
+ return pickle.load(f), get_file_metadata(self.path)
142
+
143
+
144
+ @dataclasses.dataclass
145
+ class PickleSaver(DataSaver):
146
+ path: str
147
+
148
+ @classmethod
149
+ def applicable_types(cls) -> Collection[type]:
150
+ return [object]
151
+
152
+ @classmethod
153
+ def name(cls) -> str:
154
+ return "pickle"
155
+
156
+ def save_data(self, data: Any) -> dict[str, Any]:
157
+ with open(self.path, "wb") as f:
158
+ pickle.dump(data, f)
159
+ return get_file_metadata(self.path)
160
+
161
+
162
+ @dataclasses.dataclass
163
+ class EnvVarDataLoader(DataLoader):
164
+ names: tuple[str, ...]
165
+
166
+ def load_data(self, type_: type[dict]) -> tuple[dict, dict[str, Any]]:
167
+ return {name: os.environ[name] for name in self.names}, {}
168
+
169
+ @classmethod
170
+ def name(cls) -> str:
171
+ return "environment"
172
+
173
+ @classmethod
174
+ def applicable_types(cls) -> Collection[type]:
175
+ return [dict]
176
+
177
+
178
+ @dataclasses.dataclass
179
+ class LiteralValueDataLoader(DataLoader):
180
+ value: Any
181
+
182
+ @classmethod
183
+ def applicable_types(cls) -> Collection[type]:
184
+ return [Any]
185
+
186
+ def load_data(self, type_: type) -> tuple[dict, dict[str, Any]]:
187
+ return self.value, {}
188
+
189
+ @classmethod
190
+ def name(cls) -> str:
191
+ return "literal"
192
+
193
+
194
+ @dataclasses.dataclass
195
+ class InMemoryResult(DataSaver):
196
+ """Class specifically to returning an in memory result without saving it anywhere.
197
+
198
+ Use this to get the result of a combiner easily; depends on their use.
199
+ """
200
+
201
+ @classmethod
202
+ def applicable_types(cls) -> Collection[type]:
203
+ return [Any]
204
+
205
+ def save_data(self, data: Any) -> Any:
206
+ return data
207
+
208
+ @classmethod
209
+ def name(cls) -> str:
210
+ return "memory"
211
+
212
+
213
+ DATA_ADAPTERS = [
214
+ JSONDataSaver,
215
+ JSONDataLoader,
216
+ LiteralValueDataLoader,
217
+ RawFileDataLoader,
218
+ RawFileDataSaver,
219
+ RawFileDataSaverBytes,
220
+ PickleLoader,
221
+ PickleSaver,
222
+ EnvVarDataLoader,
223
+ InMemoryResult,
224
+ ]