Extract metadata from Power BI .pbit templates and evaluate them using AI models.
Project description
PowerBIMentor
A Python package for extracting metadata from Power BI .pbit templates and evaluating them using AI models like Google Gemini.
Features
- 📊 PBIT Processing: Extract and parse Power BI template metadata (DataModelSchema)
- 🤖 AI Evaluation: Evaluate DAX formulas, visualizations, and written answers using Google Gemini
- 📝 Detailed Reports: Generate comprehensive grading reports from Power BI models
- 📦 ZIP Support: Automatically handles ZIP file submissions - no manual extraction needed
- 🔧 Easy Integration: Simple API for evaluating student assignments and projects
Installation
From Source
git clone https://github.com/yourusername/PowerBIMentor.git
cd PowerBIMentor
pip install -e .
Using pip (when published)
pip install PowerBIMentor
Quick Start
from PowerBIMentor import PowerBIMentor
# Initialize with your Gemini API key
mentor = PowerBIMentor(api_key="your-api-key")
# Evaluate a DAX assignment
# Works with both directories AND ZIP files!
result = mentor.evaluate_dax(
answer_path="path/to/assignment/", # or "submission.zip"
question="Create measures for total sales and profit margin",
prompt="Evaluate the DAX implementation for correctness and best practices"
)
print(f"Score: {result['score']}/100")
print(f"Feedback: {result['feedback']}")
Package Structure
PowerBIMentor/
├── __init__.py # Main package entry point
├── core.py # PowerBIMentor class with evaluation methods
├── models/ # AI model wrappers
│ ├── __init__.py
│ ├── model.py # Abstract base model
│ └── gemini.py # Google Gemini implementation
└── utils/ # Utility functions
├── __init__.py
├── processor.py # PBIT parsing and report generation
├── checker.py # File discovery helpers
└── extractor.py # ZIP extraction utilities
Core Components
PowerBIMentor Class
The main class provides three evaluation methods:
evaluate_dax(answer_path, question, prompt): Evaluates Power BI data models and DAX formulasevaluate_visual(answer_path, question, prompt): Evaluates dashboard visualizations from PDFsevaluate_write(answer_path, question, prompt): Evaluates written answers from text filesevaluate_all(answer_path, questions, prompts): Evaluates all three aspects at once
PBIT Processor
PowerBIMentor.utils.processor provides functions for processing Power BI templates:
pbit_to_json(pbit_path)
Extracts and parses the DataModelSchema from a .pbit file:
- Handles UTF-16 encoding and quote normalization
- Returns the parsed JSON model structure
extract_grading_info(model)
Extracts key elements for grading:
- Tables, columns, and measures (excluding hidden/private items)
- Relationships (excluding LocalDateTable)
- Hierarchies (excluding template hierarchies)
- Data source information from M code
generate_grading_report(grading_info)
Formats extracted information into a readable text report
analyze_pbit(pbit_path)
Convenience function that chains all three steps above
AI Models
Gemini Model
PowerBIMentor.models.gemini.Gemini
from PowerBIMentor.models import Gemini
model = Gemini(api_key="your-api-key", model_name="gemini-2.0-flash-exp")
# Evaluate text-based answers
result = model.evaluate(
question="What is DAX?",
answer="DAX stands for Data Analysis Expressions...",
prompt="Evaluate for accuracy and completeness"
)
# Evaluate PDF visualizations
result = model.evaluate_visual(
question="Review the dashboard design",
prompt="Evaluate layout, clarity, and best practices",
pdf_path="dashboard.pdf"
)
Response Format:
{
"score": 85,
"feedback": "Strong implementation with minor issues..."
}
Configuration
API Key Setup
Create a .env file in your project root:
API_KEY=your_gemini_api_key_here
Load it in your code:
from dotenv import load_dotenv
import os
load_dotenv()
api_key = os.getenv("API_KEY")
Detailed Usage Examples
1. Analyze a PBIT File
from PowerBIMentor.utils import analyze_pbit
# Generate a detailed report from a Power BI template
report = analyze_pbit("path/to/file.pbit")
print(report)
Sample Output:
Model: Sales Analysis
Compatibility Level: 1550
Data Source:
Type: File
Path: C:\Data\Sales.xlsx
Tables:
- Sales
Columns:
• Date (type=dateTime, summarize_by=none, calculated=False)
• Product (type=string, summarize_by=none, calculated=False)
• Amount (type=double, summarize_by=sum, calculated=False)
Measures:
• Total Sales
• Profit Margin
Measures (details):
- Total Sales (table: Sales)
SUM(Sales[Amount])
- Profit Margin (table: Sales)
DIVIDE([Total Profit], [Total Sales], 0)
Relationships:
- Sales[Date] -> Calendar[Date] (standard)
Summary:
- main_table: Sales
- total_columns: 3
- total_measures: 2
- total_relationships: 1
- has_time_intelligence: False
2. Complete Evaluation Pipeline
from PowerBIMentor import PowerBIMentor
mentor = PowerBIMentor(api_key="your-api-key")
# Define questions and prompts for each evaluation type
questions = {
"dax": "Create measures for total sales and YoY growth",
"visual": "Create a sales dashboard with KPIs and trends",
"write": "Explain your dashboard design choices"
}
prompts = {
"dax": "Evaluate DAX correctness, best practices, and time intelligence",
"visual": "Evaluate layout, chart selection, and design principles",
"write": "Evaluate clarity, justification, and understanding"
}
# Evaluate all aspects
results = mentor.evaluate_all(
answer_path="path/to/student/submission/",
questions=questions,
prompts=prompts
)
print(f"DAX Score: {results['dax']['score']}/100")
print(f"Visual Score: {results['visual']['score']}/100")
print(f"Written Score: {results['write']['score']}/100")
3. Custom Model Usage
from PowerBIMentor.models import Gemini
from PowerBIMentor.utils import analyze_pbit
# Initialize with specific model
model = Gemini(api_key="your-api-key", model_name="gemini-2.0-flash-exp")
# Get PBIT analysis
analysis = analyze_pbit("assignment.pbit")
# Evaluate with custom prompt
result = model.evaluate(
question="Implement sales analysis with time intelligence",
answer=analysis,
prompt="""
Evaluate the implementation considering:
1. Correct use of DAX functions
2. Time intelligence measures
3. Proper relationships
4. Performance optimization
"""
)
print(f"Score: {result['score']}/100")
print(f"Feedback:\n{result['feedback']}")
Examples
The examples/ directory contains comprehensive usage examples:
quick_start.py: Simplest introduction (start here!)basic_usage.py: Comprehensive guide to core featuresadvanced_usage.py: Advanced features and batch processingclassroom_grading.py: Practical example for grading student assignments
See examples/README.md for detailed documentation.
# Run the quick start example
python examples/quick_start.py
# Run comprehensive examples
python examples/basic_usage.py
Development
Running Tests
# Run processor tests
python tests/processors/processor.py
# Run model tests
python tests/models/gemini.py
# Run integration tests
python tests/test.py
Project Dependencies
Core:
google-genai>=1.0.0- Google Gemini API clientpython-dotenv>=1.0.0- Environment variable management
Optional:
google-cloud-aiplatform>=1.0.0- For Vertex AI support
Requirements
- Python 3.9 or higher
- Google Gemini API key (get one at Google AI Studio)
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT License - see LICENSE file for details
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file powerbimentor-0.1.0.tar.gz.
File metadata
- Download URL: powerbimentor-0.1.0.tar.gz
- Upload date:
- Size: 15.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90687046bb73cb35e0b028f1ee41d2d760e9d8660462b8703b45adc297724774
|
|
| MD5 |
26f03da56028a40460f55f50e7b9f182
|
|
| BLAKE2b-256 |
e7b0529384aab822bec8a21b6cff0929a314cbaa6635c22db7ae661804fa6ffe
|
File details
Details for the file powerbimentor-0.1.0-py3-none-any.whl.
File metadata
- Download URL: powerbimentor-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd66fe83f30eadeef0b456e24a5ed92bc859c2400d73f69202afb2b7f8c2842a
|
|
| MD5 |
489aca08c9e15d93cbe0454ededf55f1
|
|
| BLAKE2b-256 |
a7e8a5df5cadb651edc53637228857954bb1338156f66aba653154d35771dbca
|