Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I have notebook code that has been exported as .py file and is formatted like this:
# Fabric notebook source
# METADATA ********************
# META {
# META "kernel_info": {
# META "name": "synapse_pyspark"
# META },
# META "dependencies": {
# META "lakehouse": {
# META "default_lakehouse": "<Lakehouse ID>",
# META "default_lakehouse_name": "Metadata",
# META "default_lakehouse_workspace_id": "<Workspace ID>"
# META }
# META }
# META }
# MARKDOWN ********************
# # Import Core Code
# CELL ********************
%run "./00 - Connections"
If I import this, it just puts all this code into a single cell in a new notebook (which is obviously not what I want). Am I doing something wrong? It would be an enormous waste of my time to reformat all of this manually. Any help is much appreciated!
Solved! Go to Solution.
Hi @Anonymous,
Thanks for your response! You’re right when exporting a Fabric notebook as a .py file and re-importing it, Fabric does not automatically split it into multiple cells. Currently, Fabric only maintains cell structure when working with .ipynb files.
If you need to frequently transfer notebooks, I recommend working with .ipynb instead of .py for seamless import/export.
I agree that Fabric should ideally recognize its own .py format properly. If this is an important workflow for you, I encourage you to share your feedback and vote for this idea on the Power BI Ideas Forum:🔗 Home, This helps the Microsoft team prioritize feature enhancements based on user demand.
If this helps, then please Accept it as a solution and dropping a "Kudos" so other members can find it more easily.
Thank you.
Hi @Anonymous,
Thank you for reaching out to the Microsoft Fabric Community.
I understand that you are facing an issue were importing a .py file into a notebook results in all the code being placed into a single cell.
You can modify the .py script to include markers or comments that can be recognized by the notebook environment to split the code into different cells automatically.
(OR)
Another approach is to import the .py file as a module in the notebook. This allows you to call functions and classes defined in the .py file without having to reformat the entire script. Here are the steps:
I hope these suggestions assist you in resolving the issue. If they do, please accept it as a solution and give a "Kudos" to help other members find it more easily.
Thank you.
Thanks for your reply!
I don't want the code as module.
I know I can modify the code to be recognized correctly as several notebook cells, but that's exactly what I hoped to avoid. Also, as far as I can tell, if I download a notebook as .py, and upload the result, it also gets put into a single cell. So Fabric doesn't even recognize its own formatting and only the .ipynb-format is correctly recognized upon import. Or am I missing something?
Hi @Anonymous,
Thanks for your response! You’re right when exporting a Fabric notebook as a .py file and re-importing it, Fabric does not automatically split it into multiple cells. Currently, Fabric only maintains cell structure when working with .ipynb files.
If you need to frequently transfer notebooks, I recommend working with .ipynb instead of .py for seamless import/export.
I agree that Fabric should ideally recognize its own .py format properly. If this is an important workflow for you, I encourage you to share your feedback and vote for this idea on the Power BI Ideas Forum:🔗 Home, This helps the Microsoft team prioritize feature enhancements based on user demand.
If this helps, then please Accept it as a solution and dropping a "Kudos" so other members can find it more easily.
Thank you.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Fabric update to learn about new features.