Skip to content
PBIXray

pbixray Python Library

pbixray is an open source Python library for parsing Power BI .pbix files directly from Python, without Power BI Desktop or a live Analysis Services connection.

It is designed for developers who need to inspect semantic models, extract metadata, read Power Query logic, and work with the internals of PBIX files programmatically. The same API also supports Excel .xlsx files that contain embedded PowerPivot models.

Install

pip install pbixray

Quick Start

from pbixray import PBIXRay

model = PBIXRay("path/to/your_report.pbix")

print(model.tables)
print(model.metadata)
print(model.power_query)
print(model.dax_measures)
print(model.relationships)

Supported Inputs

Core Properties

These properties expose the most useful parts of a model as Python values or pandas DataFrames.

PropertyReturns
model.tablesList of table names in the model
model.metadataMetadata about the Power BI configuration used to create the model
model.power_queryDataFrame of Power Query / M expressions with TableName and Expression
model.m_parametersDataFrame of M parameter values and expressions
model.sizeModel size in bytes
model.dax_tablesDataFrame of calculated tables and their DAX expressions
model.dax_measuresDataFrame of measures including names, expressions, folders, and descriptions
model.dax_columnsDataFrame of calculated columns and their expressions
model.schemaDataFrame of table and column schema information with pandas types
model.relationshipsDataFrame of relationship definitions and cardinality details
model.rlsDataFrame of row-level security roles and filter expressions
model.statisticsDataFrame of column cardinality and storage statistics

Common Examples

List tables

print(model.tables)

Read Power Query / M code

power_query = model.power_query
print(power_query[["TableName", "Expression"]])

Inspect measures

measures = model.dax_measures
print(measures[["TableName", "Name", "Expression"]])

Inspect calculated columns

columns = model.dax_columns
print(columns[["TableName", "ColumnName", "Expression"]])

Inspect relationships

relationships = model.relationships
print(
    relationships[
        [
            "FromTableName",
            "FromColumnName",
            "ToTableName",
            "ToColumnName",
            "Cardinality",
            "IsActive",
        ]
    ]
)

Inspect row-level security

rls = model.rls
print(rls[["RoleName", "TableName", "FilterExpression"]])

Read a table’s contents

sales = model.get_table("Sales")
print(sales.head())

Data Model Details

pbixray can be used both as a quick inspection tool and as a lower-level metadata extraction library.

Use it to:

Tabular Model Schema Endpoints

pbixray also exposes direct equivalents of many Analysis Services $System.TMSCHEMA_* DMVs by reading the embedded SQLite metadata database inside the PBIX.

PropertyDMV equivalent
model.tmschema_modelTMSCHEMA_MODEL
model.tmschema_tablesTMSCHEMA_TABLES
model.tmschema_columnsTMSCHEMA_COLUMNS
model.tmschema_partitionsTMSCHEMA_PARTITIONS
model.tmschema_hierarchiesTMSCHEMA_HIERARCHIES
model.tmschema_levelsTMSCHEMA_LEVELS
model.tmschema_datasourcesTMSCHEMA_DATASOURCES
model.tmschema_perspectivesTMSCHEMA_PERSPECTIVES
model.tmschema_perspective_tablesTMSCHEMA_PERSPECTIVE_TABLES
model.tmschema_perspective_columnsTMSCHEMA_PERSPECTIVE_COLUMNS
model.tmschema_perspective_hierarchiesTMSCHEMA_PERSPECTIVE_HIERARCHIES
model.tmschema_perspective_measuresTMSCHEMA_PERSPECTIVE_MEASURES
model.tmschema_kpisTMSCHEMA_KPIS
model.tmschema_annotationsTMSCHEMA_ANNOTATIONS
model.tmschema_extended_propertiesTMSCHEMA_EXTENDED_PROPERTIES
model.tmschema_culturesTMSCHEMA_CULTURES
model.tmschema_translationsTMSCHEMA_OBJECT_TRANSLATIONS
model.tmschema_linguistic_metadataTMSCHEMA_LINGUISTIC_METADATA
model.tmschema_query_groupsTMSCHEMA_QUERY_GROUPS
model.tmschema_calculation_groupsTMSCHEMA_CALCULATION_GROUPS
model.tmschema_calculation_itemsTMSCHEMA_CALCULATION_ITEMS
model.tmschema_calculation_expressionsTMSCHEMA_CALCULATION_EXPRESSIONS
model.tmschema_variationsTMSCHEMA_VARIATIONS
model.tmschema_attribute_hierarchiesTMSCHEMA_ATTRIBUTE_HIERARCHIES
model.tmschema_setsTMSCHEMA_SETS
model.tmschema_refresh_policiesTMSCHEMA_REFRESH_POLICIES
model.tmschema_detail_rows_definitionsTMSCHEMA_DETAIL_ROWS_DEFINITIONS
model.tmschema_format_string_definitionsTMSCHEMA_FORMAT_STRING_DEFINITIONS
model.tmschema_functionsTMSCHEMA_FUNCTIONS
model.tmschema_calendarsTMSCHEMA_CALENDARS
model.tmschema_calendar_column_groupsTMSCHEMA_CALENDAR_COLUMN_GROUPS
model.tmschema_calendar_column_refsTMSCHEMA_CALENDAR_COLUMN_REFERENCES
model.tmschema_alternate_ofTMSCHEMA_ALTERNATE_OF
model.tmschema_related_column_detailsTMSCHEMA_RELATED_COLUMN_DETAILS
model.tmschema_group_by_columnsTMSCHEMA_GROUP_BY_COLUMNS
model.tmschema_binding_infoTMSCHEMA_BINDING_INFO
model.tmschema_analytics_ai_metadataTMSCHEMA_ANALYTICS_AI_METADATA
model.tmschema_data_coverage_definitionsTMSCHEMA_DATA_COVERAGE_DEFINITIONS
model.tmschema_role_membershipsTMSCHEMA_ROLE_MEMBERSHIPS

TMSCHEMA examples

# List all columns with table names and hidden flags
print(model.tmschema_columns[["TableName", "Name", "DataType", "IsHidden"]])

# Inspect incremental refresh policies
print(model.tmschema_refresh_policies)

# Inspect security role memberships
print(model.tmschema_role_memberships)

Requirements