You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Pyodide: Interesting Approach to Python in the Browser #1072
I think it could be used in conjunction with what we have now. Linking to the Pyodide notebooks somewhere on the README and maybe intro/index.ipynb could work. In terms of requirements, our notebooks don't use any libraries outside the matplotlib/numpy, so we should be fine.
This is definitely something to keep an eye on, maybe the GSoC student can port some stuff over?
Depends on the goals. It's interesting how Pyodide might fit into current aima-python framework. Seems aima-python has dealt mainly with AI algorithms; infrastructure / use in production has not been a significant topic. Pyodide might give a usability enhancement - ease notebook usage (although the demo seems slow), sth like "aima-python in browser". This could be also a component of a new "feature" (and a set of directories), sth like "aima-python in web dev" - many people could be interested in this. Or a step towards high volume data processing ("scaling aima-python up ").
Closing as a stale discussion. Pyodide has matured a lot since 2019, but there's no concrete task/owner here — running aima-python's notebooks in the browser would be its own focused effort. Happy to reopen if someone wants to drive a specific browser-execution goal.
Context for this issue, from ~10 years ago: There was a desire to have an interactive web companion to AIMA. We tried some Python tech but nothing worked at the time, so we started a sister project, aima-javascript, to reimplement things in JS. We only got a few chapters implemented https://aimacode.github.io/aima-javascript/ (for example, chapter 5). But Javascript isn't the preferred language for AI projects, and the project didn't gain traction. So if there were a specific idea here I think it would be to make a web companion of the textbook using python instead of javascript.
There are more ways to put notebooks on the web now than in 2019 when this issue was created, and they seem more polished. For example the new book from Gabriel Peyre https://www.gpeyre.com/ot4ml/myst/_build/html/semidiscrete-w1/ has interactive diagrams created from python notebooks.
Reopening — thanks @redblobgames, that context is really helpful, and I agree this is worth keeping open as a forward-looking direction now that the tooling has caught up.
Concretely, a Python web companion looks feasible today with options that didn't exist (or weren't polished) in 2019:
JupyterLite / Pyodide — run the existing *.ipynb notebooks fully in the browser, no server, deployable as static files.
Jupyter Book / MyST — a textbook-style interactive site built from the notebooks (like the Peyré example you linked), with executable/interactive cells.
There's also a nice synergy: we just set up a GitHub Pages deployment for the Sphinx API docs (now live at https://aimacode.github.io/aima-python/), so the same Pages pipeline could host a JupyterLite/MyST companion alongside the reference docs.
Keeping this open to track the idea; a good first concrete step would be a small JupyterLite proof-of-concept deploying one or two notebooks (e.g. search.ipynb) to Pages.
A JupyterLite build that runs aima notebooks fully in the browser via Pyodide — no server, no install.
Three PoC notebooks: Welcome, search (BFS/UCS/A* on the Romania map) and games (minimax/alpha-beta on Tic-Tac-Toe), restricted to modules that import only Pyodide-provided packages (numpy).
The aima wheel is built at deploy time and bundled into piplite, so each notebook installs it offline with piplite.install("aima", deps=False). The heavy native deps in requirements.txt (TensorFlow/Keras, OpenCV, cvxopt, qpsolvers) aren't available in Pyodide, so they're skipped and the demo set is limited accordingly.
Deployment — reuses the GitHub Pages pipeline we set up for the Sphinx docs: docs.yml now builds the lite site into docs/_build/html/lite and publishes it next to the reference docs. Once the next Pages deploy lands it'll be live at:
The lite build step is continue-on-error, so a Pyodide toolchain hiccup can never block the API-docs deploy.
Verified so far: the static site builds and bundles the aima wheel into the offline piplite index; and in a numpy-only environment with aima installed --no-deps (the closest headless proxy for Pyodide), both PoC notebooks import and run correctly.
Still open / next steps (keeping this issue open until it's a real companion):
Verify in-browser execution across browsers — Pyodide only runs in a real browser, so CI can prove the site builds but not that every cell runs.
Port more lightweight notebooks (logic, csp, planning, probability) once confirmed in-browser (csp needs sortedcontainers, logic needs networkx — both pure-Python, installable in Pyodide).
Decide whether to grow this into a full MyST / Jupyter Book textbook companion (the Peyré-style interactive book @redblobgames linked).
Ported two more lightweight notebooks to the JupyterLite companion (eb0c05f): logic (propositional model checking / DPLL + first-order forward chaining on the "West is a criminal" KB) and csp (map colouring with AC-3 / backtracking + 8-queens with min-conflicts).
Both rely only on pure-Python packages Pyodide already ships (networkx for logic, sortedcontainers for csp), preloaded for the kernel. One small change was needed in aima.agents (which logic/csp import): the optional ipythonblocks GUI dependency is now imported lazily inside GraphicEnvironment, so those modules import cleanly in Pyodide (and in any environment) without it.
The companion now ships five in-browser notebooks: Welcome, search, games, logic, csp.
Added two more notebooks to the JupyterLite companion (b2a7185): planning (STRIPS spare-tire and air-cargo problems solved with GraphPlan, then linearized to an executable action sequence) and probability (exact inference via enumeration / variable elimination plus approximate inference via likelihood weighting on the burglary network).
No source changes were needed — both modules use only Pyodide-provided packages (planning: numpy + networkx + sortedcontainers; probability: numpy), and the earlier lazy-ipythonblocks change lets them import aima.agents cleanly.
The companion now ships seven in-browser notebooks: Welcome, search, games, logic, csp, planning, probability.
Completed the port: the JupyterLite companion now has a notebook for every Pyodide-compatible module (4293776), 15 in total.
New this round: agents (reflex vs. model-based vacuum world), mdp (value/policy iteration on the 4×3 grid), reinforcement_learning (Q-learning), game_theory (Nash equilibria, zero-sum value, Shapley value), knowledge (current-best-hypothesis learning), nlp (probabilistic CYK parsing), learning (decision tree + naive Bayes on an inline dataset) and text (n-gram language models). These join search, games, csp, logic, planning and probability.
Two small source tweaks let learning import in the browser: qpsolvers is now a lazy import (only the SVM classes use it), and the example datasets it builds at import time are guarded so the module still imports when the aima-data files are absent (as in Pyodide).
Out of scope (Pyodide lacks the native wheels): deep_learning (TensorFlow/Keras), perception (OpenCV), and the SVM path in learning (cvxopt/qpsolvers).
Verified: full test suite 407 passed; the lite site builds with all 15 notebooks; and every notebook's code runs in a numpy/networkx/sortedcontainers/scipy environment mirroring Pyodide. Real in-browser execution still wants a manual cross-browser check, so keeping this open.
In-browser execution verified. Added lite/verify_browser.py, which loads real Pyodide in headless Chromium, installs the deployed aima wheel, and executes every notebook's actual code cells (the piplite install cell included).
Result: all 15 notebooks run successfully end-to-end in a real browser, with correct outputs — A* finds the cost-418 Romania route, alpha-beta never loses at Tic-Tac-Toe, the prisoner's-dilemma/coordination Nash equilibria come out right, value/policy iteration agree on the MDP policy, the decision tree and naive Bayes classify the tennis data, CYK fills a 52-entry chart, etc.
So build.sh proves the site builds and verify_browser.py proves it runs. The companion is functionally complete; keeping #1072 open only to optionally wire the browser check into CI (it needs a headless browser, so a heavier separate job) and to consider a fuller MyST / Jupyter Book companion.
This is interesting; thanks for this work. I think it is good to offer several options for a professor or an individual student. They want to integrate into their current environment in VSCode or whatever; they may want a setup-free browser experience, they may want a logi-free or license-free entry. I think Google CoLab is a pretty good option for many users, but it does require a Google account.
Activity
antmarakis commentedon Apr 17, 2019
I think it could be used in conjunction with what we have now. Linking to the Pyodide notebooks somewhere on the
READMEand maybeintro/index.ipynbcould work. In terms of requirements, our notebooks don't use any libraries outside the matplotlib/numpy, so we should be fine.This is definitely something to keep an eye on, maybe the GSoC student can port some stuff over?
JaakTepandi commentedon Apr 26, 2019
Depends on the goals. It's interesting how Pyodide might fit into current aima-python framework. Seems aima-python has dealt mainly with AI algorithms; infrastructure / use in production has not been a significant topic. Pyodide might give a usability enhancement - ease notebook usage (although the demo seems slow), sth like "aima-python in browser". This could be also a component of a new "feature" (and a set of directories), sth like "aima-python in web dev" - many people could be interested in this. Or a step towards high volume data processing ("scaling aima-python up ").
dmeoli commentedon Jun 27, 2026
Closing as a stale discussion. Pyodide has matured a lot since 2019, but there's no concrete task/owner here — running aima-python's notebooks in the browser would be its own focused effort. Happy to reopen if someone wants to drive a specific browser-execution goal.
redblobgames commentedon Jun 27, 2026
Context for this issue, from ~10 years ago: There was a desire to have an interactive web companion to AIMA. We tried some Python tech but nothing worked at the time, so we started a sister project, aima-javascript, to reimplement things in JS. We only got a few chapters implemented https://aimacode.github.io/aima-javascript/ (for example, chapter 5). But Javascript isn't the preferred language for AI projects, and the project didn't gain traction. So if there were a specific idea here I think it would be to make a web companion of the textbook using python instead of javascript.
There are more ways to put notebooks on the web now than in 2019 when this issue was created, and they seem more polished. For example the new book from Gabriel Peyre https://www.gpeyre.com/ot4ml/myst/_build/html/semidiscrete-w1/ has interactive diagrams created from python notebooks.
dmeoli commentedon Jun 27, 2026
Reopening — thanks @redblobgames, that context is really helpful, and I agree this is worth keeping open as a forward-looking direction now that the tooling has caught up.
Concretely, a Python web companion looks feasible today with options that didn't exist (or weren't polished) in 2019:
*.ipynbnotebooks fully in the browser, no server, deployable as static files.There's also a nice synergy: we just set up a GitHub Pages deployment for the Sphinx API docs (now live at https://aimacode.github.io/aima-python/), so the same Pages pipeline could host a JupyterLite/MyST companion alongside the reference docs.
Keeping this open to track the idea; a good first concrete step would be a small JupyterLite proof-of-concept deploying one or two notebooks (e.g.
search.ipynb) to Pages.Add JupyterLite browser-companion proof-of-concept (#1072)
dmeoli commentedon Jun 29, 2026
Started on the JupyterLite proof-of-concept I mentioned above — committed in 266e024.
What's in it (under
lite/):aimanotebooks fully in the browser via Pyodide — no server, no install.Welcome,search(BFS/UCS/A* on the Romania map) andgames(minimax/alpha-beta on Tic-Tac-Toe), restricted to modules that import only Pyodide-provided packages (numpy).aimawheel is built at deploy time and bundled into piplite, so each notebook installs it offline withpiplite.install("aima", deps=False). The heavy native deps inrequirements.txt(TensorFlow/Keras, OpenCV, cvxopt, qpsolvers) aren't available in Pyodide, so they're skipped and the demo set is limited accordingly.Deployment — reuses the GitHub Pages pipeline we set up for the Sphinx docs:
docs.ymlnow builds the lite site intodocs/_build/html/liteand publishes it next to the reference docs. Once the next Pages deploy lands it'll be live at:The lite build step is
continue-on-error, so a Pyodide toolchain hiccup can never block the API-docs deploy.Verified so far: the static site builds and bundles the
aimawheel into the offline piplite index; and in a numpy-only environment withaimainstalled--no-deps(the closest headless proxy for Pyodide), both PoC notebooks import and run correctly.Still open / next steps (keeping this issue open until it's a real companion):
sortedcontainers, logic needsnetworkx— both pure-Python, installable in Pyodide).Port logic and csp notebooks to the JupyterLite companion (#1072)
dmeoli commentedon Jun 29, 2026
Ported two more lightweight notebooks to the JupyterLite companion (eb0c05f): logic (propositional model checking / DPLL + first-order forward chaining on the "West is a criminal" KB) and csp (map colouring with AC-3 / backtracking + 8-queens with min-conflicts).
Both rely only on pure-Python packages Pyodide already ships (
networkxfor logic,sortedcontainersfor csp), preloaded for the kernel. One small change was needed inaima.agents(which logic/csp import): the optionalipythonblocksGUI dependency is now imported lazily insideGraphicEnvironment, so those modules import cleanly in Pyodide (and in any environment) without it.The companion now ships five in-browser notebooks: Welcome, search, games, logic, csp.
Port planning and probability notebooks to the JupyterLite companion (#…
dmeoli commentedon Jun 29, 2026
Added two more notebooks to the JupyterLite companion (b2a7185): planning (STRIPS spare-tire and air-cargo problems solved with GraphPlan, then linearized to an executable action sequence) and probability (exact inference via enumeration / variable elimination plus approximate inference via likelihood weighting on the burglary network).
No source changes were needed — both modules use only Pyodide-provided packages (planning: numpy + networkx + sortedcontainers; probability: numpy), and the earlier lazy-
ipythonblockschange lets them importaima.agentscleanly.The companion now ships seven in-browser notebooks: Welcome, search, games, logic, csp, planning, probability.
Port all remaining Pyodide-compatible modules to the JupyterLite comp…
dmeoli commentedon Jun 30, 2026
Completed the port: the JupyterLite companion now has a notebook for every Pyodide-compatible module (4293776), 15 in total.
New this round: agents (reflex vs. model-based vacuum world), mdp (value/policy iteration on the 4×3 grid), reinforcement_learning (Q-learning), game_theory (Nash equilibria, zero-sum value, Shapley value), knowledge (current-best-hypothesis learning), nlp (probabilistic CYK parsing), learning (decision tree + naive Bayes on an inline dataset) and text (n-gram language models). These join search, games, csp, logic, planning and probability.
Two small source tweaks let
learningimport in the browser:qpsolversis now a lazy import (only the SVM classes use it), and the example datasets it builds at import time are guarded so the module still imports when theaima-datafiles are absent (as in Pyodide).Out of scope (Pyodide lacks the native wheels):
deep_learning(TensorFlow/Keras),perception(OpenCV), and the SVM path inlearning(cvxopt/qpsolvers).Verified: full test suite 407 passed; the lite site builds with all 15 notebooks; and every notebook's code runs in a numpy/networkx/sortedcontainers/scipy environment mirroring Pyodide. Real in-browser execution still wants a manual cross-browser check, so keeping this open.
Add real-browser verification for the JupyterLite companion (#1072)
dmeoli commentedon Jun 30, 2026
In-browser execution verified. Added
lite/verify_browser.py, which loads real Pyodide in headless Chromium, installs the deployedaimawheel, and executes every notebook's actual code cells (thepipliteinstall cell included).Result: all 15 notebooks run successfully end-to-end in a real browser, with correct outputs — A* finds the cost-418 Romania route, alpha-beta never loses at Tic-Tac-Toe, the prisoner's-dilemma/coordination Nash equilibria come out right, value/policy iteration agree on the MDP policy, the decision tree and naive Bayes classify the tennis data, CYK fills a 52-entry chart, etc.
So
build.shproves the site builds andverify_browser.pyproves it runs. The companion is functionally complete; keeping #1072 open only to optionally wire the browser check into CI (it needs a headless browser, so a heavier separate job) and to consider a fuller MyST / Jupyter Book companion.norvig commentedon Jun 30, 2026
This is interesting; thanks for this work. I think it is good to offer several options for a professor or an individual student. They want to integrate into their current environment in VSCode or whatever; they may want a setup-free browser experience, they may want a logi-free or license-free entry. I think Google CoLab is a pretty good option for many users, but it does require a Google account.
I also wonder about integration with https://pythontutor.com/