semantic_model_writer
sqllocks_spindle.fabric.semantic_model_writer
¶
Export Spindle schemas to Power BI / Fabric semantic model .bim files.
Generates TOM (Tabular Object Model) JSON at compatibilityLevel 1604, including auto-generated DAX measures for fact tables and M expressions for Lakehouse, Warehouse, or SQL Database sources.
No external dependencies — uses only stdlib json/pathlib.
Usage::
from sqllocks_spindle.fabric.semantic_model_writer import SemanticModelExporter
exporter = SemanticModelExporter()
path = exporter.export_bim(
schema=schema,
source_type="lakehouse",
source_name="MyLakehouse",
output_path="retail_model.bim",
include_measures=True,
)
Classes¶
SemanticModelExporter
¶
Export a SpindleSchema to a Power BI .bim (TOM JSON) file.
Generates
- Table definitions with typed columns
- Relationships from SpindleSchema FK definitions
- Auto-generated DAX measures (SUM, COUNTROWS, AVERAGE)
- M (Power Query) partition expressions per source type
Methods:¶
export_bim(schema, source_type='lakehouse', source_name='', output_path='model.bim', include_measures=True, schema_name='dbo')
¶
Export schema to a .bim file (TOM JSON format).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
SpindleSchema
|
A SpindleSchema describing tables and relationships. |
required |
source_type
|
str
|
Data source — |
'lakehouse'
|
source_name
|
str
|
Name of the Lakehouse/Warehouse/Server item. |
''
|
output_path
|
str | Path
|
Destination file path for the .bim output. |
'model.bim'
|
include_measures
|
bool
|
Generate DAX measures for numeric columns. |
True
|
schema_name
|
str
|
SQL schema for warehouse/sql_database sources. |
'dbo'
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the written .bim file. |
to_dict(schema, source_type='lakehouse', source_name='', include_measures=True, schema_name='dbo')
¶
Return the TOM model as a dict (without writing to disk).