Automating Power BI Themes with Fabric, Notebooks and BIBB Theme Generator API: A Complete Guide
Transform Your Power BI Theme Management with Automation
Managing Power BI themes across multiple reports can be time-consuming and error-prone when done manually. This comprehensive guide shows you how to automate the entire process using Microsoft Fabric, Python, and the BIBB Theme Generator API.
Youβll learn to streamline theme creation and application, ensuring consistent branding across your entire Power BI portfolio while saving hours of manual work. Whether youβre managing a handful of reports or hundreds, this automation solution scales with your needs.
Prerequisites and Requirements
Before using this automation script, ensure you have:
Microsoft Fabric Setup:
- Fabric workspace with Contributor or Admin role
- Python/Spark environment enabled in your workspace
- Power BI reports in PBIR format (Fabric-native, not PBIX)
API Access:
- BIBB Theme Generator API access (free for newsletter subscribers)
- Valid email address for API authentication
- Subscribe to newsletter for instant free access
Permissions:
- Edit access to target Power BI reports
- Ability to modify report themes and resources
Quick Start Summary
- Step 1: Configure your theme using the BIBB Theme Generator
- Step 2: Copy the automation script into your Fabric notebook
- Step 3: Update parameters with your workspace ID, report ID, email, and theme colors
- Step 4: Run the notebook cell and verify successful theme application
Benefits and Use Cases
This automation solution transforms Power BI theme management by providing:
- Time Savings: Eliminate hours of manual theme application across multiple reports
- Consistency: Ensure uniform branding across your entire Power BI portfolio
- Scalability: Easily update hundreds of reports with a single script execution
- Professional Quality: Generate accessibility-compliant themes with optimal color palettes
- Version Control: Maintain audit trails and track theme changes over time
- Rapid Response: Quickly adapt to branding changes or new design requirements
Common Use Cases
- Enterprise Deployment: Apply consistent corporate branding across all departmental reports
- Rebranding Projects: Update entire Power BI portfolios when brand guidelines change
- Multi-tenant Solutions: Generate custom themes for different clients or business units
- Accessibility Compliance: Ensure all reports meet WCAG color contrast requirements
Step-by-Step Implementation Guide
Step 1: Configure Your Theme with BIBB Theme Generator
Before automating the process, letβs first configure your custom theme using the BIBB Theme Generator. This visual approach helps you design the perfect theme that matches your brand requirements.
Design Your Theme Visually
Visit the BIBB Theme Generator and customize your Power BI theme:
- Choose your primary colors - Set your brand colors for the main palette
- Configure backgrounds - Select card and page background colors
- Set text colors - Ensure proper contrast and readability
- Select fonts - Choose typography that matches your brand
- Preview the theme - See how your theme looks in real-time
Step 2: Copy the Automation Script
Now that you have your theme configured, copy the complete automation script into your Microsoft Fabric notebook.
Ready-to-Use Script
Complete Fabric Notebook Script
Copy this entire code block into a Microsoft Fabric Python notebook cell:
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# Power BI Theme Automation with BIBB Theme Generator
# Copy this entire cell into your Microsoft Fabric Python notebook
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# 1οΈβ£ One-off package install
%pip install --quiet --upgrade semantic-link-labs requests
# 2οΈβ£ Parameters - Update these with your actual values
workspace_id = "00000000-0000-0000-0000-000000000000" # β Fabric workspace GUID
report_id = "00000000-0000-0000-0000-000000000000" # β Report GUID (must be PBIR, not PBIX)
api_email = "yourname@email.pro" # β Your email for BIBB API
# 4οΈβ£ Call BIBB Theme Generator API
import requests, json
print("π Generating theme via BIBB API...")
endpoint = "https://api.bibb.pro/generate"
payload = {"email": api_email, "styles": styles}
try:
r = requests.post(endpoint, json=payload, timeout=30)
r.raise_for_status()
# The service returns the complete theme JSON
theme_json = r.json() if isinstance(r.json(), dict) else json.loads(r.text)
print(f"π¨ Theme \"{theme_json.get('name', styles.get('themeName'))}\" received!")
except requests.exceptions.RequestException as e:
print(f"β API Error: {e}")
exit()
# 5οΈβ£ Apply theme to Power BI report in Fabric
from sempy_labs.report import connect_report
print("π Connecting to Power BI report...")
REPORT_JSON_PATH = "definition/report.json"
try:
with connect_report(report=report_id,
workspace=workspace_id,
readonly=False) as rpt:
# Locate existing theme pointer (if any)
current_pointer = rpt.get(
file_path=REPORT_JSON_PATH,
json_path="$.themeCollection.customTheme"
) or {}
# Handle edge cases with tuple outputs
if isinstance(current_pointer, list) and current_pointer:
current_pointer = current_pointer[0][1]
current_name = current_pointer.get("name")
current_path = (f"StaticResources/RegisteredResources/{current_name}"
if current_name else None)
# Smart overwrite or creation
if current_path and current_path in rpt.list_paths()["Path"].values:
rpt.update(file_path=current_path, payload=theme_json)
print(f"β»οΈ Overwrote existing theme file: {current_name}")
else:
# Maintain stable file names to avoid duplicates
stable_name = "BIBBTheme.json"
theme_json["name"] = stable_name.removesuffix(".json")
rpt.set_theme(theme_json=theme_json)
print(f"π Added theme and set pointer: {stable_name}")
print("β
Theme applied successfully β report should open with new theme!")
except Exception as e:
print(f"β Report Update Error: {e}")
print("π‘ Make sure:")
print(" β’ Report ID is correct and in PBIR format")
print(" β’ Workspace ID is correct")
print(" β’ You have Contributor/Admin access to the workspace")
Step 3: Update Parameters
Before running the script, you need to update the parameters with your specific values:
Required Parameters
-
Workspace ID: Get this from your Fabric workspace URL
workspace_id = "12345678-1234-1234-1234-123456789abc" # Your actual workspace GUID
-
Report ID: Get this from your Power BI report URL (must be PBIR format)
report_id = "87654321-4321-4321-4321-cba987654321" # Your actual report GUID
-
Email Address: Your email for BIBB API access
api_email = "your.email@company.com" # The email you used to subscribe
Step 4: Run the Notebook
Once youβve updated all parameters, youβre ready to execute the automation:
Execution Steps
- Paste the script into a new Python cell in your Microsoft Fabric notebook
- Update the parameters as configured in Step 3
- Run the cell - the script will automatically:
- Install required packages
- Generate your theme via BIBB API
- Connect to your Power BI report
- Apply the new theme
Expected Output
When successful, youβll see output similar to:
π’ The report definition has been updated successfully.
β
Theme applied successfully β report should open with new theme!
Troubleshooting
If you encounter errors, check:
- Report ID is correct and in PBIR format (not PBIX)
- Workspace ID is correct
- You have Contributor/Admin access to the workspace
- Your email is valid for BIBB API access
Additional Documentation
For deeper understanding of the technologies used in this automation solution, refer to these official Microsoft resources:
Core Technologies
- Microsoft Fabric Notebooks - Complete guide to using notebooks in Fabric
- Semantic Link Overview - Connecting Power BI with Fabric data science
- Power BI Report Themes - Official theme creation and JSON format specification
Advanced Features
- Semantic Link Labs - Microsoftβs official automation library used in this solution
- Power BI Theme JSON Schema - Official schema for theme validation
Learning Resources
- Get Started with Microsoft Fabric - Official Microsoft Learn training path
- Work with Semantic Models in Fabric - Deep dive into semantic link capabilities
Transform your Power BI theme management today with automated, professional solutions that scale with your business needs.