Skip to content

Instantly share code, notes, and snippets.

@zeddie888
Created December 6, 2025 22:05
Show Gist options
  • Select an option

  • Save zeddie888/b2734039ef53db43179c6a267d936452 to your computer and use it in GitHub Desktop.

Select an option

Save zeddie888/b2734039ef53db43179c6a267d936452 to your computer and use it in GitHub Desktop.
Script to fix your Google Colab ipynb notebooks so they can be rendered properly on GitHub
"""
Script to remove 'metadata.widgets' from Jupyter notebook files so that they can be rendered in-browser on GitHub.
"""
import json
import sys
# Usage: python fix_notebook.py <path to nb>
try:
nb_path = sys.argv[1]
with open(nb_path, 'r', encoding='utf-8') as f:
data = json.load(f)
if 'widgets' in data.get('metadata', {}):
del data['metadata']['widgets']
with open(nb_path, 'w', encoding='utf-8') as f:
json.dump(data, f, indent=1)
print(f"SUCCESS: Removed 'metadata.widgets' from {nb_path}")
else:
print(f"Clean: No 'metadata.widgets' found in {nb_path}")
except IndexError:
print("Error: Please provide a filename. \nUsage: python fix_notebook.py <path to nb>")
except FileNotFoundError:
print(f"Error: Could not find file {sys.argv[1]}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment