1. Pyodide (Best for client-side Python)
Pyodide compiles CPython to WebAssembly, allowing Python to run entirely in the browser without a server.
Advantages:
-
No installation required for users
-
Access to many scientific libraries (NumPy, Pandas, Matplotlib)
-
Can interact with JavaScript and the DOM
-
Runs offline after loading
Example:
2. PyScript (Easiest)
PyScript builds on Pyodide and lets you write Python directly in HTML.
3. Brython
Brython is a Python interpreter written in JavaScript.
4. Server-side Python
The browser displays HTML, while Python runs on the server.
Frameworks include:
-
Flask
-
Django
-
FastAPI
-
Bottle
-
Tornado
This is the standard approach for production web applications.
5. WebAssembly (CPython)
The newest versions of CPython can be compiled to WebAssembly, enabling a nearly full Python interpreter in the browser.
Can Python manipulate HTML?
Yes.
Example with PyScript:
Can Python call JavaScript?
Yes.
Which is best?
| Purpose | Recommendation |
|---|
| Full web application | Flask, FastAPI, or Django |
| Interactive browser application | PyScript |
| Scientific computing in browser | Pyodide |
| Teaching Python | PyScript |
| Offline browser application | Pyodide |
| Desktop-like web app | PyScript + Bootstrap |
Since you've been building Bootstrap 5 applications with MariaDB and PHP, a practical architecture is:
-
Frontend: Bootstrap 5 + JavaScript
-
Client-side Python (optional): PyScript or Pyodide for calculations, data processing, or AI features in the browser
-
Backend: Python (FastAPI or Flask), or PHP if you prefer
-
Database: MariaDB