Python in the Browser

Anand S

LLM Psychologist @ Straive

Slides: sanand0.github.io/talks/2025-06-pycon-sg/

Hypothesis Forge: Automating Analysis

  • Hypoforge: sanand0.github.io/hypoforge/
  • One-click insights over any CSV right in the browser-no backend, no install
  • Uses Pyodide + Web Worker to run pandas & SciPy in the browser
  • Perfect for classrooms, hackathons, client demos. Just share a URL

Anatomy of the Magic

After the LLM generates code, here's how we run it.

<script src="https://cdn.jsdelivr.net/pyodide/v0.27.7/full/pyodide.js"></script>
<script>
  const pyodide = await loadPyodide();
  await pyodide.loadPackage(['pandas', 'numpy']);
  const df = pyodide.runPython(`
      import pandas as pd, io, base64, sys
      csv = "sepal_length,sepal_width\\n5.1,3.5"
      pd.read_csv(io.StringIO(csv)).describe().to_string()
  `);
  console.log(df);
</script>

How it Works

  • loadPyodide() fetches the 6 MB WASM; cache-able.
  • await pyodide.loadPackage('scikit-learn') lazy-installs wheels from PyPI mirror; tiny overlays.
  • runPython() executes & transparently converts basic types ↔️ JS

Python-in-browser is production-ready today.

Common Pitfalls (and Fixes)

  • UI freezes on first load. Move everything into the worker before loadPyodide()
  • "Module not found" wheels. Pin exact package version; manylibs lag a bit
  • Memory bloat. Call pyodide.runPython('import gc; gc.collect()') between large runs
  • CORS errors hosting locally. Serve with --cors flag or a tiny Express proxy

Use Python in the Browser

Anand S

LLM Psychologist @ Straive

Slides: sanand0.github.io/talks/2025-06-pycon-sg/