Forum Discussion

edwardlee4948's avatar
edwardlee4948
Frequent Visitor
1 year ago
Solved

Help with Python Library for Manipulating Power BI PBIR(report.json) and DIM files

I am trying to build a Python library that can read PBIR and DIM files, specifically for manipulating Power BI reports. I noticed that those are all json format. My goal is to easily copy visuals from one report to another using Python code.

I haven't come across any open-source libraries for this purpose yet. Additionally, I'm finding it difficult to understand the visual configuration files and the various options for Power BI's default visuals (e.g., bar, grid, etc.). I’m wondering if there is a schema available that I could use to convert these configurations into a generic Pydantic dataclass.

I work at a Microsoft partner company, and we need to streamline the process of building Power BI reports quickly. If I've missed any articles or resources related to this topic, please feel free to point me to them.

Thank you!

 

""" example of what I am thinking

platform_content = create_platform(self.report_name)
with open(os.path.join(self.output_path, ".platform"), "w") as f:
f.write(platform_content)
report_config_content = create_report_config()
definition_content = create_definition(self.model_path)
with open(os.path.join(self.output_path, "definition.pbir"), "w") as f:
f.write(definition_content)
report_content = create_report(report_config_content)
self.report = Report(**json.loads(report_content))
report_content = self.report.to_json()
with open(os.path.join(self.output_path, "report.json"), "w") as f:
f.write(report_content)
theme_content = create_theme()
theme_path = os.path.join(self.output_path, THEME_DIR, "CY24SU02.json")
os.makedirs(os.path.dirname(theme_path), exist_ok=True)
with open(
theme_path,
"w",
) as f:
f.write(theme_content)
"""
and
"""
with open(os.path.join(dst, "report.json"), "r") as f:
json_data2 = json.load(f)
report2 = Report(**json_data2)
report2.add_section(tmp_sec)
x = 10
y = 20
z = 0
width = 600
height = 400
report2.add_visual(
display_name=tmp_sec.displayName,
visual_config=create_visual_config(x, y, z, width, height),
x=x,
y=y,
z=z,
width=width,
height=height,
)
with open(os.path.join(dst, "report.json"), "w") as f:
f.write(report2.to_json())
"""

1 Reply