pbi-semantic-doc 0.2.0__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.
- pbi_semantic_doc-0.2.0/LICENSE +21 -0
- pbi_semantic_doc-0.2.0/PKG-INFO +284 -0
- pbi_semantic_doc-0.2.0/README.md +259 -0
- pbi_semantic_doc-0.2.0/pbi_semantic_doc/__init__.py +30 -0
- pbi_semantic_doc-0.2.0/pbi_semantic_doc/cli.py +294 -0
- pbi_semantic_doc-0.2.0/pbi_semantic_doc/generator.py +176 -0
- pbi_semantic_doc-0.2.0/pbi_semantic_doc/parser.py +647 -0
- pbi_semantic_doc-0.2.0/pbi_semantic_doc/report_generator.py +182 -0
- pbi_semantic_doc-0.2.0/pbi_semantic_doc/report_models.py +363 -0
- pbi_semantic_doc-0.2.0/pbi_semantic_doc/report_parser.py +416 -0
- pbi_semantic_doc-0.2.0/pbi_semantic_doc.egg-info/PKG-INFO +284 -0
- pbi_semantic_doc-0.2.0/pbi_semantic_doc.egg-info/SOURCES.txt +18 -0
- pbi_semantic_doc-0.2.0/pbi_semantic_doc.egg-info/dependency_links.txt +1 -0
- pbi_semantic_doc-0.2.0/pbi_semantic_doc.egg-info/entry_points.txt +2 -0
- pbi_semantic_doc-0.2.0/pbi_semantic_doc.egg-info/top_level.txt +1 -0
- pbi_semantic_doc-0.2.0/pyproject.toml +46 -0
- pbi_semantic_doc-0.2.0/setup.cfg +4 -0
- pbi_semantic_doc-0.2.0/tests/test_integration.py +230 -0
- pbi_semantic_doc-0.2.0/tests/test_parser.py +150 -0
- pbi_semantic_doc-0.2.0/tests/test_report.py +673 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 viciuslios
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pbi-semantic-doc
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Automatic documentation generator and analyzer for Power BI semantic models (TMDL) and reports (PBIR)
|
|
5
|
+
Author: viciuslios
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/viciuslios/pbi-semantic-doc
|
|
8
|
+
Project-URL: Issues, https://github.com/viciuslios/pbi-semantic-doc/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/viciuslios/pbi-semantic-doc/blob/main/CHANGELOG.md
|
|
10
|
+
Keywords: power-bi,tmdl,semantic-model,documentation,pbip,pbir,report,dataops
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: Information Technology
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Documentation
|
|
22
|
+
Classifier: Topic :: Software Development :: Documentation
|
|
23
|
+
Requires-Python: >=3.9
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# pbi-semantic-doc
|
|
27
|
+
|
|
28
|
+
**Automatic documentation generator and analyzer for Power BI projects.**
|
|
29
|
+
|
|
30
|
+
[](https://pypi.org/project/pbi-semantic-doc/)
|
|
31
|
+
[](https://pypi.org/project/pbi-semantic-doc/)
|
|
32
|
+
[](LICENSE)
|
|
33
|
+
[](#)
|
|
34
|
+
|
|
35
|
+
Built with ❤️ by [viciuslios](https://github.com/viciuslios) in collaboration with [Claude AI](https://claude.ai) (Anthropic).
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
If your Power BI project lives in a Git repository as a `.pbip` project, this tool can:
|
|
40
|
+
|
|
41
|
+
- **Document semantic models** (TMDL format) — tables, columns, measures, relationships, DAX patterns, complexity index
|
|
42
|
+
- **Analyze reports** (PBIR and PBIR-Legacy) — pages, visuals, bookmarks, visual type distribution, complexity index
|
|
43
|
+
|
|
44
|
+
Zero configuration. Zero external dependencies. Drop it into any pipeline.
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install pbi-semantic-doc
|
|
48
|
+
|
|
49
|
+
# Document a semantic model
|
|
50
|
+
pbi-semantic-doc ./MyProject.SemanticModel --output docs/MODEL.md
|
|
51
|
+
|
|
52
|
+
# Analyze a report
|
|
53
|
+
pbi-semantic-doc ./MyProject.Report --analyze-report --output docs/REPORT.md
|
|
54
|
+
|
|
55
|
+
# Both at once (from the .pbip project folder)
|
|
56
|
+
pbi-semantic-doc ./MyProject --combined --output docs/FULL.md
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## Why this exists
|
|
62
|
+
|
|
63
|
+
Power BI semantic models have become real codebases. With `.pbip` projects and TMDL, every table, measure, and relationship is a text file you can version, review, and diff. The tooling around that workflow is still catching up: there is no built-in way to generate human-readable documentation from a semantic model without opening Power BI Desktop or paying for a third-party service.
|
|
64
|
+
|
|
65
|
+
`pbi-semantic-doc` fills that gap. It is a plain Python CLI tool you can drop into any pipeline — a pre-commit hook, a GitHub Action, a local script — and get documentation that stays in sync with your model automatically.
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## Installation
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pip install pbi-semantic-doc
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Or from source:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
git clone https://github.com/viciuslios/pbi-semantic-doc
|
|
79
|
+
cd pbi-semantic-doc
|
|
80
|
+
pip install -e .
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## Usage
|
|
86
|
+
|
|
87
|
+
### Semantic Model Documentation
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
# Basic — writes MODEL_DOC.md inside the model folder
|
|
91
|
+
pbi-semantic-doc ./MyProject.SemanticModel
|
|
92
|
+
|
|
93
|
+
# Specify output path
|
|
94
|
+
pbi-semantic-doc ./MyProject.SemanticModel --output ./docs/MODEL.md
|
|
95
|
+
|
|
96
|
+
# Point to the .pbip parent folder (auto-discovers the .SemanticModel subfolder)
|
|
97
|
+
pbi-semantic-doc . --output MODEL.md
|
|
98
|
+
|
|
99
|
+
# Suppress console output (useful in CI)
|
|
100
|
+
pbi-semantic-doc ./MyProject.SemanticModel --output ./docs/MODEL.md --quiet
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Report Analysis
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
# Markdown output (default)
|
|
107
|
+
pbi-semantic-doc ./MyProject.Report --analyze-report --output ./docs/REPORT.md
|
|
108
|
+
|
|
109
|
+
# JSON output for programmatic use
|
|
110
|
+
pbi-semantic-doc ./MyProject.Report --analyze-report --format json --output analysis.json
|
|
111
|
+
|
|
112
|
+
# Text summary to console
|
|
113
|
+
pbi-semantic-doc ./MyProject.Report --analyze-report --format text
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Combined Analysis
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
# Analyze both model and report from a .pbip project folder
|
|
120
|
+
pbi-semantic-doc ./MyProject --combined --output ./docs/FULL.md
|
|
121
|
+
|
|
122
|
+
# JSON combined output
|
|
123
|
+
pbi-semantic-doc ./MyProject --combined --format json --output analysis.json
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### CLI reference
|
|
127
|
+
|
|
128
|
+
| Flag | Description |
|
|
129
|
+
|------|-------------|
|
|
130
|
+
| `PATH` | Path to `.SemanticModel`, `.Report`, or `.pbip` project folder |
|
|
131
|
+
| `--analyze-report` | Analyze report instead of semantic model |
|
|
132
|
+
| `--combined` | Analyze both semantic model and report |
|
|
133
|
+
| `--format` | Output format: `md` (default), `json`, `text` |
|
|
134
|
+
| `--output`, `-o` | Output file path |
|
|
135
|
+
| `--quiet`, `-q` | Suppress console output |
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
## Expected folder structure
|
|
140
|
+
|
|
141
|
+
```
|
|
142
|
+
MyProject/
|
|
143
|
+
├── MyProject.pbip
|
|
144
|
+
├── MyProject.SemanticModel/
|
|
145
|
+
│ └── definition/
|
|
146
|
+
│ ├── model.tmdl
|
|
147
|
+
│ ├── relationships.tmdl
|
|
148
|
+
│ └── tables/
|
|
149
|
+
│ ├── Sales.tmdl
|
|
150
|
+
│ └── Calendar.tmdl
|
|
151
|
+
└── MyProject.Report/
|
|
152
|
+
└── definition/
|
|
153
|
+
├── version.json
|
|
154
|
+
├── pages/ # PBIR format (new)
|
|
155
|
+
│ └── Page1/
|
|
156
|
+
│ ├── page.json
|
|
157
|
+
│ └── visuals/
|
|
158
|
+
│ └── Visual1/
|
|
159
|
+
│ └── visual.json
|
|
160
|
+
├── bookmarks/
|
|
161
|
+
│ └── Bookmark1.bookmark.json
|
|
162
|
+
├── reportExtensions.json
|
|
163
|
+
└── report.json # PBIR-Legacy format (old)
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## Features
|
|
169
|
+
|
|
170
|
+
### Semantic Model Documentation
|
|
171
|
+
- Parses standard TMDL folder structure (`.pbip` projects, Power BI Desktop)
|
|
172
|
+
- Documents tables, columns (data types, descriptions, hidden status), measures (full DAX), and relationships
|
|
173
|
+
- Generates automatic DAX pattern descriptions when no manual description is present
|
|
174
|
+
- Extracts model name from the `.SemanticModel` folder name
|
|
175
|
+
- **Complexity Index** — normalized 0–1 score per model (see below)
|
|
176
|
+
|
|
177
|
+
### Report Analysis
|
|
178
|
+
- Supports **PBIR** (folder-based, new) and **PBIR-Legacy** (`report.json`) formats
|
|
179
|
+
- Classifies all standard and custom visual types
|
|
180
|
+
- Detects mobile layouts, drill-through pages, hidden pages, filters
|
|
181
|
+
- Identifies custom marketplace visuals by name
|
|
182
|
+
- **Complexity Index** — normalized 0–1 score per report (see below)
|
|
183
|
+
- Outputs Markdown, JSON, and plain text
|
|
184
|
+
|
|
185
|
+
### General
|
|
186
|
+
- Zero external dependencies — pure Python 3.9+ stdlib
|
|
187
|
+
- Installable via pip; works as a CLI or Python library
|
|
188
|
+
- CI/CD ready (GitHub Actions, pre-commit hooks)
|
|
189
|
+
- Windows-compatible (Unicode on cp1252 terminals)
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## Complexity Index
|
|
194
|
+
|
|
195
|
+
Both the semantic model and the report get a normalized **0–1 complexity score**.
|
|
196
|
+
|
|
197
|
+
### Semantic Model
|
|
198
|
+
|
|
199
|
+
| Dimension | Weight | Reference maximum |
|
|
200
|
+
|-----------|--------|-------------------|
|
|
201
|
+
| Visible tables | 20% | 30 tables |
|
|
202
|
+
| Measures | 30% | 150 measures |
|
|
203
|
+
| Measure DAX complexity (avg) | 30% | — |
|
|
204
|
+
| Relationships | 10% | 50 relationships |
|
|
205
|
+
| Columns | 10% | 300 columns |
|
|
206
|
+
|
|
207
|
+
**Measure DAX complexity** is itself a 0–1 score per measure, combining:
|
|
208
|
+
- Expression length (40%) — normalized to 500 characters
|
|
209
|
+
- Detected pattern count (60%) — CALCULATE, VAR, time intelligence, iterators, filter modifiers, RANKX, SWITCH, USERELATIONSHIP (max 5 distinct categories)
|
|
210
|
+
|
|
211
|
+
### Report
|
|
212
|
+
|
|
213
|
+
| Dimension | Weight | Reference maximum |
|
|
214
|
+
|-----------|--------|-------------------|
|
|
215
|
+
| Pages | 25% | 50 pages |
|
|
216
|
+
| Visuals | 45% | 300 visuals |
|
|
217
|
+
| Bookmarks | 20% | 30 bookmarks |
|
|
218
|
+
| Report-level measures | 10% | 10 measures |
|
|
219
|
+
|
|
220
|
+
A score of **0.5 (50%)** indicates a moderately complex model or report. Both scores are always in the 0–1 range.
|
|
221
|
+
|
|
222
|
+
---
|
|
223
|
+
|
|
224
|
+
## DAX pattern recognition
|
|
225
|
+
|
|
226
|
+
Automatic measure descriptions are generated by inspecting DAX expressions. Recognized patterns:
|
|
227
|
+
|
|
228
|
+
| Category | Functions |
|
|
229
|
+
|----------|-----------|
|
|
230
|
+
| Aggregations | `SUM`, `AVERAGE`, `COUNT`, `DISTINCTCOUNT`, `MIN`, `MAX` |
|
|
231
|
+
| Iterators | `SUMX`, `AVERAGEX`, `COUNTX`, `FILTER` |
|
|
232
|
+
| Time intelligence | `TOTALYTD`, `TOTALMTD`, `SAMEPERIODLASTYEAR`, `DATEADD`, `PARALLELPERIOD` |
|
|
233
|
+
| Context modification | `CALCULATE`, `ALL`, `ALLEXCEPT`, `KEEPFILTERS` |
|
|
234
|
+
| Variables | `VAR`/`RETURN` |
|
|
235
|
+
| Safe division | `DIVIDE` |
|
|
236
|
+
| Conditional logic | `IF`, `SWITCH` |
|
|
237
|
+
| Ranking | `RANKX`, `TOPN` |
|
|
238
|
+
| Cross-table | `RELATED`, `USERELATIONSHIP` |
|
|
239
|
+
|
|
240
|
+
Manual descriptions in Power BI Desktop always take precedence over auto-generated ones.
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
244
|
+
## Roadmap
|
|
245
|
+
|
|
246
|
+
### v0.3 — Data Sources & Power Query
|
|
247
|
+
- **Data source discovery**: extract connection strings, server/database names, SharePoint/OneLake endpoints from TMDL partitions
|
|
248
|
+
- **Power Query (M) extraction**: expose the full M expression for each table partition
|
|
249
|
+
- **Custom query detection**: flag tables using `Value.NativeQuery` or inline SQL — a common maintenance risk
|
|
250
|
+
- **Dataflow & lakehouse references**: identify tables sourced from Power BI Dataflows, Fabric Lakehouses, or Warehouses
|
|
251
|
+
|
|
252
|
+
### v0.4 — Deep Model Analysis
|
|
253
|
+
- **Column lineage**: trace which measures reference which columns across tables
|
|
254
|
+
- **Unused columns**: detect columns not referenced in any measure, relationship, or visual
|
|
255
|
+
- **Measure dependency graph**: DAG of measure-to-measure dependencies
|
|
256
|
+
- **Hidden object inventory**: report on all hidden tables and columns
|
|
257
|
+
|
|
258
|
+
### v0.5 — Report Deep Dive
|
|
259
|
+
- **Visual-to-measure mapping**: detect which measures each visual uses (from `prototypeQuery`)
|
|
260
|
+
- **Filter analysis**: page-level and visual-level filters with target fields and values
|
|
261
|
+
- **Theme extraction**: color palette and font settings from theme files
|
|
262
|
+
- **Tooltip page detection**: pages used exclusively as tooltip layers
|
|
263
|
+
|
|
264
|
+
### Future
|
|
265
|
+
- Interactive single-file HTML output
|
|
266
|
+
- Pre-commit hook configuration helper
|
|
267
|
+
- VS Code extension wrapper
|
|
268
|
+
|
|
269
|
+
---
|
|
270
|
+
|
|
271
|
+
## Contributing
|
|
272
|
+
|
|
273
|
+
Issues and pull requests are welcome at [github.com/viciuslios/pbi-semantic-doc](https://github.com/viciuslios/pbi-semantic-doc).
|
|
274
|
+
|
|
275
|
+
```bash
|
|
276
|
+
pip install pytest
|
|
277
|
+
pytest tests/ -v # 138 tests
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
---
|
|
281
|
+
|
|
282
|
+
## License
|
|
283
|
+
|
|
284
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
# pbi-semantic-doc
|
|
2
|
+
|
|
3
|
+
**Automatic documentation generator and analyzer for Power BI projects.**
|
|
4
|
+
|
|
5
|
+
[](https://pypi.org/project/pbi-semantic-doc/)
|
|
6
|
+
[](https://pypi.org/project/pbi-semantic-doc/)
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
[](#)
|
|
9
|
+
|
|
10
|
+
Built with ❤️ by [viciuslios](https://github.com/viciuslios) in collaboration with [Claude AI](https://claude.ai) (Anthropic).
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
If your Power BI project lives in a Git repository as a `.pbip` project, this tool can:
|
|
15
|
+
|
|
16
|
+
- **Document semantic models** (TMDL format) — tables, columns, measures, relationships, DAX patterns, complexity index
|
|
17
|
+
- **Analyze reports** (PBIR and PBIR-Legacy) — pages, visuals, bookmarks, visual type distribution, complexity index
|
|
18
|
+
|
|
19
|
+
Zero configuration. Zero external dependencies. Drop it into any pipeline.
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pip install pbi-semantic-doc
|
|
23
|
+
|
|
24
|
+
# Document a semantic model
|
|
25
|
+
pbi-semantic-doc ./MyProject.SemanticModel --output docs/MODEL.md
|
|
26
|
+
|
|
27
|
+
# Analyze a report
|
|
28
|
+
pbi-semantic-doc ./MyProject.Report --analyze-report --output docs/REPORT.md
|
|
29
|
+
|
|
30
|
+
# Both at once (from the .pbip project folder)
|
|
31
|
+
pbi-semantic-doc ./MyProject --combined --output docs/FULL.md
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## Why this exists
|
|
37
|
+
|
|
38
|
+
Power BI semantic models have become real codebases. With `.pbip` projects and TMDL, every table, measure, and relationship is a text file you can version, review, and diff. The tooling around that workflow is still catching up: there is no built-in way to generate human-readable documentation from a semantic model without opening Power BI Desktop or paying for a third-party service.
|
|
39
|
+
|
|
40
|
+
`pbi-semantic-doc` fills that gap. It is a plain Python CLI tool you can drop into any pipeline — a pre-commit hook, a GitHub Action, a local script — and get documentation that stays in sync with your model automatically.
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Installation
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install pbi-semantic-doc
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Or from source:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
git clone https://github.com/viciuslios/pbi-semantic-doc
|
|
54
|
+
cd pbi-semantic-doc
|
|
55
|
+
pip install -e .
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## Usage
|
|
61
|
+
|
|
62
|
+
### Semantic Model Documentation
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
# Basic — writes MODEL_DOC.md inside the model folder
|
|
66
|
+
pbi-semantic-doc ./MyProject.SemanticModel
|
|
67
|
+
|
|
68
|
+
# Specify output path
|
|
69
|
+
pbi-semantic-doc ./MyProject.SemanticModel --output ./docs/MODEL.md
|
|
70
|
+
|
|
71
|
+
# Point to the .pbip parent folder (auto-discovers the .SemanticModel subfolder)
|
|
72
|
+
pbi-semantic-doc . --output MODEL.md
|
|
73
|
+
|
|
74
|
+
# Suppress console output (useful in CI)
|
|
75
|
+
pbi-semantic-doc ./MyProject.SemanticModel --output ./docs/MODEL.md --quiet
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Report Analysis
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
# Markdown output (default)
|
|
82
|
+
pbi-semantic-doc ./MyProject.Report --analyze-report --output ./docs/REPORT.md
|
|
83
|
+
|
|
84
|
+
# JSON output for programmatic use
|
|
85
|
+
pbi-semantic-doc ./MyProject.Report --analyze-report --format json --output analysis.json
|
|
86
|
+
|
|
87
|
+
# Text summary to console
|
|
88
|
+
pbi-semantic-doc ./MyProject.Report --analyze-report --format text
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Combined Analysis
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
# Analyze both model and report from a .pbip project folder
|
|
95
|
+
pbi-semantic-doc ./MyProject --combined --output ./docs/FULL.md
|
|
96
|
+
|
|
97
|
+
# JSON combined output
|
|
98
|
+
pbi-semantic-doc ./MyProject --combined --format json --output analysis.json
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### CLI reference
|
|
102
|
+
|
|
103
|
+
| Flag | Description |
|
|
104
|
+
|------|-------------|
|
|
105
|
+
| `PATH` | Path to `.SemanticModel`, `.Report`, or `.pbip` project folder |
|
|
106
|
+
| `--analyze-report` | Analyze report instead of semantic model |
|
|
107
|
+
| `--combined` | Analyze both semantic model and report |
|
|
108
|
+
| `--format` | Output format: `md` (default), `json`, `text` |
|
|
109
|
+
| `--output`, `-o` | Output file path |
|
|
110
|
+
| `--quiet`, `-q` | Suppress console output |
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## Expected folder structure
|
|
115
|
+
|
|
116
|
+
```
|
|
117
|
+
MyProject/
|
|
118
|
+
├── MyProject.pbip
|
|
119
|
+
├── MyProject.SemanticModel/
|
|
120
|
+
│ └── definition/
|
|
121
|
+
│ ├── model.tmdl
|
|
122
|
+
│ ├── relationships.tmdl
|
|
123
|
+
│ └── tables/
|
|
124
|
+
│ ├── Sales.tmdl
|
|
125
|
+
│ └── Calendar.tmdl
|
|
126
|
+
└── MyProject.Report/
|
|
127
|
+
└── definition/
|
|
128
|
+
├── version.json
|
|
129
|
+
├── pages/ # PBIR format (new)
|
|
130
|
+
│ └── Page1/
|
|
131
|
+
│ ├── page.json
|
|
132
|
+
│ └── visuals/
|
|
133
|
+
│ └── Visual1/
|
|
134
|
+
│ └── visual.json
|
|
135
|
+
├── bookmarks/
|
|
136
|
+
│ └── Bookmark1.bookmark.json
|
|
137
|
+
├── reportExtensions.json
|
|
138
|
+
└── report.json # PBIR-Legacy format (old)
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## Features
|
|
144
|
+
|
|
145
|
+
### Semantic Model Documentation
|
|
146
|
+
- Parses standard TMDL folder structure (`.pbip` projects, Power BI Desktop)
|
|
147
|
+
- Documents tables, columns (data types, descriptions, hidden status), measures (full DAX), and relationships
|
|
148
|
+
- Generates automatic DAX pattern descriptions when no manual description is present
|
|
149
|
+
- Extracts model name from the `.SemanticModel` folder name
|
|
150
|
+
- **Complexity Index** — normalized 0–1 score per model (see below)
|
|
151
|
+
|
|
152
|
+
### Report Analysis
|
|
153
|
+
- Supports **PBIR** (folder-based, new) and **PBIR-Legacy** (`report.json`) formats
|
|
154
|
+
- Classifies all standard and custom visual types
|
|
155
|
+
- Detects mobile layouts, drill-through pages, hidden pages, filters
|
|
156
|
+
- Identifies custom marketplace visuals by name
|
|
157
|
+
- **Complexity Index** — normalized 0–1 score per report (see below)
|
|
158
|
+
- Outputs Markdown, JSON, and plain text
|
|
159
|
+
|
|
160
|
+
### General
|
|
161
|
+
- Zero external dependencies — pure Python 3.9+ stdlib
|
|
162
|
+
- Installable via pip; works as a CLI or Python library
|
|
163
|
+
- CI/CD ready (GitHub Actions, pre-commit hooks)
|
|
164
|
+
- Windows-compatible (Unicode on cp1252 terminals)
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## Complexity Index
|
|
169
|
+
|
|
170
|
+
Both the semantic model and the report get a normalized **0–1 complexity score**.
|
|
171
|
+
|
|
172
|
+
### Semantic Model
|
|
173
|
+
|
|
174
|
+
| Dimension | Weight | Reference maximum |
|
|
175
|
+
|-----------|--------|-------------------|
|
|
176
|
+
| Visible tables | 20% | 30 tables |
|
|
177
|
+
| Measures | 30% | 150 measures |
|
|
178
|
+
| Measure DAX complexity (avg) | 30% | — |
|
|
179
|
+
| Relationships | 10% | 50 relationships |
|
|
180
|
+
| Columns | 10% | 300 columns |
|
|
181
|
+
|
|
182
|
+
**Measure DAX complexity** is itself a 0–1 score per measure, combining:
|
|
183
|
+
- Expression length (40%) — normalized to 500 characters
|
|
184
|
+
- Detected pattern count (60%) — CALCULATE, VAR, time intelligence, iterators, filter modifiers, RANKX, SWITCH, USERELATIONSHIP (max 5 distinct categories)
|
|
185
|
+
|
|
186
|
+
### Report
|
|
187
|
+
|
|
188
|
+
| Dimension | Weight | Reference maximum |
|
|
189
|
+
|-----------|--------|-------------------|
|
|
190
|
+
| Pages | 25% | 50 pages |
|
|
191
|
+
| Visuals | 45% | 300 visuals |
|
|
192
|
+
| Bookmarks | 20% | 30 bookmarks |
|
|
193
|
+
| Report-level measures | 10% | 10 measures |
|
|
194
|
+
|
|
195
|
+
A score of **0.5 (50%)** indicates a moderately complex model or report. Both scores are always in the 0–1 range.
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
## DAX pattern recognition
|
|
200
|
+
|
|
201
|
+
Automatic measure descriptions are generated by inspecting DAX expressions. Recognized patterns:
|
|
202
|
+
|
|
203
|
+
| Category | Functions |
|
|
204
|
+
|----------|-----------|
|
|
205
|
+
| Aggregations | `SUM`, `AVERAGE`, `COUNT`, `DISTINCTCOUNT`, `MIN`, `MAX` |
|
|
206
|
+
| Iterators | `SUMX`, `AVERAGEX`, `COUNTX`, `FILTER` |
|
|
207
|
+
| Time intelligence | `TOTALYTD`, `TOTALMTD`, `SAMEPERIODLASTYEAR`, `DATEADD`, `PARALLELPERIOD` |
|
|
208
|
+
| Context modification | `CALCULATE`, `ALL`, `ALLEXCEPT`, `KEEPFILTERS` |
|
|
209
|
+
| Variables | `VAR`/`RETURN` |
|
|
210
|
+
| Safe division | `DIVIDE` |
|
|
211
|
+
| Conditional logic | `IF`, `SWITCH` |
|
|
212
|
+
| Ranking | `RANKX`, `TOPN` |
|
|
213
|
+
| Cross-table | `RELATED`, `USERELATIONSHIP` |
|
|
214
|
+
|
|
215
|
+
Manual descriptions in Power BI Desktop always take precedence over auto-generated ones.
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
## Roadmap
|
|
220
|
+
|
|
221
|
+
### v0.3 — Data Sources & Power Query
|
|
222
|
+
- **Data source discovery**: extract connection strings, server/database names, SharePoint/OneLake endpoints from TMDL partitions
|
|
223
|
+
- **Power Query (M) extraction**: expose the full M expression for each table partition
|
|
224
|
+
- **Custom query detection**: flag tables using `Value.NativeQuery` or inline SQL — a common maintenance risk
|
|
225
|
+
- **Dataflow & lakehouse references**: identify tables sourced from Power BI Dataflows, Fabric Lakehouses, or Warehouses
|
|
226
|
+
|
|
227
|
+
### v0.4 — Deep Model Analysis
|
|
228
|
+
- **Column lineage**: trace which measures reference which columns across tables
|
|
229
|
+
- **Unused columns**: detect columns not referenced in any measure, relationship, or visual
|
|
230
|
+
- **Measure dependency graph**: DAG of measure-to-measure dependencies
|
|
231
|
+
- **Hidden object inventory**: report on all hidden tables and columns
|
|
232
|
+
|
|
233
|
+
### v0.5 — Report Deep Dive
|
|
234
|
+
- **Visual-to-measure mapping**: detect which measures each visual uses (from `prototypeQuery`)
|
|
235
|
+
- **Filter analysis**: page-level and visual-level filters with target fields and values
|
|
236
|
+
- **Theme extraction**: color palette and font settings from theme files
|
|
237
|
+
- **Tooltip page detection**: pages used exclusively as tooltip layers
|
|
238
|
+
|
|
239
|
+
### Future
|
|
240
|
+
- Interactive single-file HTML output
|
|
241
|
+
- Pre-commit hook configuration helper
|
|
242
|
+
- VS Code extension wrapper
|
|
243
|
+
|
|
244
|
+
---
|
|
245
|
+
|
|
246
|
+
## Contributing
|
|
247
|
+
|
|
248
|
+
Issues and pull requests are welcome at [github.com/viciuslios/pbi-semantic-doc](https://github.com/viciuslios/pbi-semantic-doc).
|
|
249
|
+
|
|
250
|
+
```bash
|
|
251
|
+
pip install pytest
|
|
252
|
+
pytest tests/ -v # 138 tests
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
## License
|
|
258
|
+
|
|
259
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""pbi-semantic-doc — automatic documentation generator for Power BI semantic models and report analyzer."""
|
|
2
|
+
|
|
3
|
+
from .parser import TmdlParser, SemanticModel, ModelMetrics, Table, Column, Measure, Relationship
|
|
4
|
+
from .generator import MarkdownGenerator
|
|
5
|
+
from .report_parser import ReportParser
|
|
6
|
+
from .report_models import Report, ReportPage, Visual, Bookmark, ReportMetrics, ReportFormat, VisualType
|
|
7
|
+
from .report_generator import ReportGenerator
|
|
8
|
+
|
|
9
|
+
__version__ = "0.2.0"
|
|
10
|
+
__all__ = [
|
|
11
|
+
# Semantic Model
|
|
12
|
+
"TmdlParser",
|
|
13
|
+
"SemanticModel",
|
|
14
|
+
"ModelMetrics",
|
|
15
|
+
"Table",
|
|
16
|
+
"Column",
|
|
17
|
+
"Measure",
|
|
18
|
+
"Relationship",
|
|
19
|
+
"MarkdownGenerator",
|
|
20
|
+
# Report Analysis
|
|
21
|
+
"ReportParser",
|
|
22
|
+
"Report",
|
|
23
|
+
"ReportPage",
|
|
24
|
+
"Visual",
|
|
25
|
+
"Bookmark",
|
|
26
|
+
"ReportMetrics",
|
|
27
|
+
"ReportFormat",
|
|
28
|
+
"VisualType",
|
|
29
|
+
"ReportGenerator",
|
|
30
|
+
]
|