MCPcopy
hub / github.com/feast-dev/feast / DbtCodeGenerator

Class DbtCodeGenerator

sdk/python/feast/dbt/codegen.py:178–379  ·  view source on GitHub ↗

Generates Python code for Feast objects from dbt models. This class creates complete, importable Python files containing Entity, DataSource, and FeatureView definitions. Example:: generator = DbtCodeGenerator( data_source_type="bigquery", timestamp

Source from the content-addressed store, hash-verified

176
177
178class DbtCodeGenerator:
179 """
180 Generates Python code for Feast objects from dbt models.
181
182 This class creates complete, importable Python files containing
183 Entity, DataSource, and FeatureView definitions.
184
185 Example::
186
187 generator = DbtCodeGenerator(
188 data_source_type="bigquery",
189 timestamp_field="event_timestamp",
190 ttl_days=7
191 )
192 code = generator.generate(
193 models=models,
194 entity_column="user_id",
195 manifest_path="target/manifest.json",
196 project_name="my_project"
197 )
198 with open("features.py", "w") as f:
199 f.write(code)
200 """
201
202 def __init__(
203 self,
204 data_source_type: str = "bigquery",
205 timestamp_field: str = "event_timestamp",
206 ttl_days: int = 1,
207 ):
208 self.data_source_type = data_source_type.lower()
209 self.timestamp_field = timestamp_field
210 self.ttl_days = ttl_days
211
212 # Set up Jinja2 environment
213 self.env = Environment(
214 loader=BaseLoader(),
215 trim_blocks=True,
216 lstrip_blocks=True,
217 )
218 self.template = self.env.from_string(FEAST_FILE_TEMPLATE)
219
220 def generate(
221 self,
222 models: List[DbtModel],
223 entity_columns: Union[str, List[str]],
224 manifest_path: str = "",
225 project_name: str = "",
226 exclude_columns: Optional[List[str]] = None,
227 online: bool = True,
228 ) -> str:
229 """
230 Generate Python code for Feast objects from dbt models.
231
232 Args:
233 models: List of DbtModel objects to generate code for
234 entity_columns: Entity column name(s) - single string or list of strings
235 manifest_path: Path to the dbt manifest (for documentation)

Callers 4

test_basic_generationMethod · 0.90
test_exclude_columnsMethod · 0.90
generate_feast_codeFunction · 0.85

Calls

no outgoing calls

Tested by 3

test_basic_generationMethod · 0.72
test_exclude_columnsMethod · 0.72