I wanted a lazy way to write Python and have it just work inside a webpage — no backend servers, no external APIs, just pure Python running in the browser.
So I built Pytml.
What is Pytml?
Pytml is a minimal JavaScript library that lets you embed and execute Python code directly inside HTML. It wraps around Pyodide – a full Python interpreter compiled to WebAssembly – so the code runs locally in the visitor's browser.
You don't need to install anything.
You don't need a Python server.
You just write tags or , and Pytml does the rest.</p>
<p>How It Actually Works<br>
Behind the scenes, pytml.js does four things:</p>
<p>Initializes Pyodide<br>
When the page loads, the script fetches and starts Pyodide (a WebAssembly build of CPython). This takes a couple of seconds, but only once.</p>
<p>Redirects Python I/O<br>
Normally Python's print() writes to the console. Pytml overrides print() and input() so they write into a visible HTML output container inside your page. No console digging.</p>
<p>Scans for Python Blocks<br>
It looks for any <py> element or <script type="text/python"> and collects the Python source code inside.</p>
<p>Executes the Code<br>
Once Pyodide is ready, it runs the collected Python code line by line, capturing outputs and errors, and displays them nicely in the browser.</p>
<p>The result? You can write real Python (including basic libraries) and have it behave like it's part of the webpage.</p>
<p>Example<br>
html<br>
<!DOCTYPE html><br>
<html><br>
<head><br>
<script src="pytml.js">
print("Hello from Python!")
for i in range(5):
print(f"Counter: {i}")
No backend. No Flask. No Django. Just HTML and Python.
Real Limitations (Because Honesty Matters)
Pyodide is heavy (≈ 6-7 MB download on first load). It's not for tiny pages.
Startup latency – the first execution can take a second or two while WebAssembly boots.
Limited Python libraries – Pyodide supports many pure-Python packages, but C-extensions need to be recompiled to Wasm.
Why I Built It
I'm a Class 12 student who loves Python but found it annoying to switch contexts between backend and frontend. I wanted a lazy bridge – something that lets me show my Python projects working live on a webpage without setting up a server.
Pytml isn't meant to replace React or Flask. It's a learning tool, a prototyping sandbox, and maybe the start of something bigger.
Links
GitHub repo: https://github.com/NodeX-AR/Pytml
My portfolio: https://a-r.is-a.dev
Top comments (0)