BIBB
FABRIC
β€’

Automating Power BI Themes with Fabric, Notebooks and BIBB Theme Generator API: A Complete Guide

Oscar MartΓ­nez
Oscar MartΓ­nez Data, BI and AI | Operational Lead | Power BI & Azure Expert | Governance-Driven Strategy | Product Owner

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
  1. Step 1: Configure your theme using the BIBB Theme Generator
  2. Step 2: Copy the automation script into your Fabric notebook
  3. Step 3: Update parameters with your workspace ID, report ID, email, and theme colors
  4. 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:

  1. Choose your primary colors - Set your brand colors for the main palette
  2. Configure backgrounds - Select card and page background colors
  3. Set text colors - Ensure proper contrast and readability
  4. Select fonts - Choose typography that matches your brand
  5. 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.

Copy the Automation Script

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

  1. Workspace ID: Get this from your Fabric workspace URL

    workspace_id = "12345678-1234-1234-1234-123456789abc"  # Your actual workspace GUID
    
  2. 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
    
  3. 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

  1. Paste the script into a new Python cell in your Microsoft Fabric notebook
  2. Update the parameters as configured in Step 3
  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

Advanced Features

Learning Resources

Transform your Power BI theme management today with automated, professional solutions that scale with your business needs.