dagster-datacontract 0.1.2__tar.gz → 0.2.2__tar.gz

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.
@@ -1,13 +1,12 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dagster-datacontract
3
- Version: 0.1.2
3
+ Version: 0.2.2
4
4
  Summary: Load metadata and asset check spesifications from data contracts.
5
5
  Author-email: Fredrik Bakken <fredrik@dataheim.io>
6
- Requires-Python: >=3.11.10
6
+ Requires-Python: >=3.10.0
7
7
  Description-Content-Type: text/markdown
8
8
  License-File: LICENSE
9
- Requires-Dist: dagster>=1.10.9
10
- Requires-Dist: dagster-webserver>=1.10.9
9
+ Requires-Dist: dagster>=1.10.10
11
10
  Requires-Dist: datacontract-cli>=0.10.23
12
11
  Dynamic: license-file
13
12
 
@@ -52,7 +51,7 @@ data_contract = DataContractLoader(
52
51
  name=asset_name,
53
52
  metadata=data_contract.metadata,
54
53
  tags=data_contract.tags,
55
- description=data_contract.description,
54
+ description=data_contract.load_description(),
56
55
  owners=data_contract.owner,
57
56
  code_version=data_contract.version,
58
57
  )
@@ -39,7 +39,7 @@ data_contract = DataContractLoader(
39
39
  name=asset_name,
40
40
  metadata=data_contract.metadata,
41
41
  tags=data_contract.tags,
42
- description=data_contract.description,
42
+ description=data_contract.load_description(),
43
43
  owners=data_contract.owner,
44
44
  code_version=data_contract.version,
45
45
  )
@@ -23,7 +23,7 @@ class DataContractLoader:
23
23
  )
24
24
  self.metadata = self._load_metadata()
25
25
  self.tags = self._load_tags()
26
- self.description = self._load_description()
26
+ self.description = self.load_description()
27
27
  self.owner = self._load_owner()
28
28
  self.version = self._load_version()
29
29
  self.cron_schedule = self._load_cron_schedule()
@@ -76,23 +76,6 @@ class DataContractLoader:
76
76
 
77
77
  return tags
78
78
 
79
- def _load_description(self) -> str | None:
80
- model_description = self.data_contract_specification.models.get(
81
- self.asset_name
82
- ).description.replace("\n", "\n\n")
83
- info_description = self.data_contract_specification.info.description.replace(
84
- "\n", "\n\n"
85
- )
86
-
87
- if model_description and info_description:
88
- return f"{model_description}\n\n{info_description}"
89
- elif model_description:
90
- return textwrap.dedent(model_description)
91
- elif info_description:
92
- return textwrap.dedent(info_description)
93
-
94
- return None
95
-
96
79
  def _load_owner(self) -> list[str] | None:
97
80
  owner = self.data_contract_specification.info.owner
98
81
 
@@ -112,7 +95,69 @@ class DataContractLoader:
112
95
  except AttributeError:
113
96
  return None
114
97
 
98
+ def load_description(
99
+ self, config: dict[str, Any] | None = None, separator: str = "\n"
100
+ ) -> str | None:
101
+ """Load and return a formatted description string based on the data contract specification.
102
+
103
+ This method composes a description by pulling text from different parts
104
+ of the data contract specification (e.g., model and info descriptions),
105
+ joining them using the specified separator.
106
+
107
+ Args:
108
+ config (dict[str, Any] | None, optional): A configuration dictionary
109
+ specifying the order in which to concatenate the description parts.
110
+ Defaults to `{"order": ["model", "info"]}`.
111
+ separator (str, optional): A string used to separate different parts
112
+ of the description. Defaults to a newline character (`"\n"`).
113
+
114
+ Returns:
115
+ str | None: A single string combining the specified description parts
116
+ if available, otherwise `None`.
117
+
118
+
119
+ Example:
120
+ >>> self.load_description()
121
+ 'Model description...\nInfo description...'
122
+ """
123
+ default_config = {"order": ["model", "info"]}
124
+
125
+ configuration = default_config | (config or {})
126
+
127
+ descriptions = {
128
+ "model": self.data_contract_specification.models.get(
129
+ self.asset_name
130
+ ).description,
131
+ "info": self.data_contract_specification.info.description,
132
+ }
133
+
134
+ parts = []
135
+ for key in configuration["order"]:
136
+ desc = descriptions.get(key).replace("\n", f"{separator}\n")
137
+ if desc:
138
+ parts.append(textwrap.dedent(desc))
139
+
140
+ if parts:
141
+ return f"{separator}\n".join(parts)
142
+
143
+ return None
144
+
115
145
  def load_data_quality_checks(self) -> dg.AssetChecksDefinition:
146
+ """Define and return a data quality check for the specified asset.
147
+
148
+ This method registers a data quality check using the `@dg.asset_check`
149
+ decorator. The check runs the data contract's `test()` method and returns
150
+ the result as a `dg.AssetCheckResult`. The result is considered "passed"
151
+ if the test outcome matches `ResultEnum.passed`.
152
+
153
+ The check is marked as blocking, which means failures may halt downstream
154
+ processing in a data pipeline.
155
+
156
+ Returns:
157
+ dg.AssetChecksDefinition: The defined asset quality check function,
158
+ registered with Dagster's data quality framework.
159
+ """
160
+
116
161
  @dg.asset_check(
117
162
  asset=self.asset_key,
118
163
  blocking=True,
@@ -130,6 +175,27 @@ class DataContractLoader:
130
175
  return check_asset
131
176
 
132
177
  def load_freshness_checks(self, lower_bound_delta: timedelta):
178
+ """Generate and return freshness checks for the asset based on update recency.
179
+
180
+ This method builds freshness checks using Dagster's
181
+ `build_last_update_freshness_checks` utility. It ensures that the specified
182
+ asset has been updated within a given time window (`lower_bound_delta`).
183
+ A cron schedule (`self.cron_schedule`) defines when the check should run.
184
+
185
+ Args:
186
+ lower_bound_delta (timedelta): The minimum acceptable time difference
187
+ between the current time and the asset's last update timestamp.
188
+ If the asset is older than this delta, the check will fail.
189
+
190
+ Returns:
191
+ list[AssetCheckSpec] | AssetChecksDefinition: A freshness check definition
192
+ that can be returned from `define_asset_checks` to register the check.
193
+
194
+
195
+ Example:
196
+ >>> self.load_freshness_checks(timedelta(hours=24))
197
+ # Ensures the asset was updated in the last 24 hours.
198
+ """
133
199
  freshness_checks = dg.build_last_update_freshness_checks(
134
200
  assets=[self.asset_name],
135
201
  lower_bound_delta=lower_bound_delta,
@@ -1,13 +1,12 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dagster-datacontract
3
- Version: 0.1.2
3
+ Version: 0.2.2
4
4
  Summary: Load metadata and asset check spesifications from data contracts.
5
5
  Author-email: Fredrik Bakken <fredrik@dataheim.io>
6
- Requires-Python: >=3.11.10
6
+ Requires-Python: >=3.10.0
7
7
  Description-Content-Type: text/markdown
8
8
  License-File: LICENSE
9
- Requires-Dist: dagster>=1.10.9
10
- Requires-Dist: dagster-webserver>=1.10.9
9
+ Requires-Dist: dagster>=1.10.10
11
10
  Requires-Dist: datacontract-cli>=0.10.23
12
11
  Dynamic: license-file
13
12
 
@@ -52,7 +51,7 @@ data_contract = DataContractLoader(
52
51
  name=asset_name,
53
52
  metadata=data_contract.metadata,
54
53
  tags=data_contract.tags,
55
- description=data_contract.description,
54
+ description=data_contract.load_description(),
56
55
  owners=data_contract.owner,
57
56
  code_version=data_contract.version,
58
57
  )
@@ -0,0 +1,2 @@
1
+ dagster>=1.10.10
2
+ datacontract-cli>=0.10.23
@@ -1,23 +1,23 @@
1
1
  [project]
2
2
  name = "dagster-datacontract"
3
- version = "0.1.2"
3
+ version = "0.2.2"
4
4
  description = "Load metadata and asset check spesifications from data contracts."
5
5
  authors = [
6
6
  { name = "Fredrik Bakken", email = "fredrik@dataheim.io" }
7
7
  ]
8
8
  readme = "README.md"
9
- requires-python = ">=3.11.10"
9
+ requires-python = ">=3.10.0"
10
10
  dependencies = [
11
- "dagster>=1.10.9",
12
- "dagster-webserver>=1.10.9",
11
+ "dagster>=1.10.10",
13
12
  "datacontract-cli>=0.10.23",
14
13
  ]
15
14
 
16
15
  [dependency-groups]
17
16
  dev = [
18
- "polars>=1.27.0",
17
+ "dagster-webserver>=1.10.10",
18
+ "polars>=1.27.1",
19
19
  "pre-commit>=4.2.0",
20
- "ruff>=0.11.4",
20
+ "ruff>=0.11.5",
21
21
  ]
22
22
 
23
23
  [build-system]
@@ -1,3 +0,0 @@
1
- dagster>=1.10.9
2
- dagster-webserver>=1.10.9
3
- datacontract-cli>=0.10.23