Skip to content

Instantly share code, notes, and snippets.

@drscotthawley
Last active November 18, 2025 23:55
Show Gist options
  • Select an option

  • Save drscotthawley/e6927f1389f262ecbabfe41d31989e1c to your computer and use it in GitHub Desktop.

Select an option

Save drscotthawley/e6927f1389f262ecbabfe41d31989e1c to your computer and use it in GitHub Desktop.
fixes up jupyter notebook widgets state so GitHub can visualize notebooks again
# Usage: python fix_notebook.py <.ipynb file>
# WARNING: this overwrites the file, so save a backup first
# To execute on a whole folder of files, run this bash command:
# find . -name "*.ipynb" -exec python fix_notebook.py {} \;
import json
import sys
def fix_notebook(filename):
with open(filename, 'r') as f:
nb = json.load(f)
# Remove metadata.widgets entirely (safest approach)
if 'metadata' in nb and 'widgets' in nb['metadata']:
del nb['metadata']['widgets']
with open(filename, 'w') as f:
json.dump(nb, f, indent=2)
print(f"Fixed {filename}")
# Usage: python fix_notebook.py notebook.ipynb
if __name__ == "__main__":
fix_notebook(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment