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 <py> tags or <script type="text/python">, and Pytml does the rest.
How It Actually Works
Behind the scenes, pytml.js does four things:
Initializes Pyodide
When the page loads, the script fetches and starts Pyodide (a WebAssembly build of CPython). This takes a couple of seconds, but only once.
Redirects Python I/O
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.
Scans for Python Blocks
It looks for any <py> element or <script type="text/python"> and collects the Python source code inside.
Executes the Code
Once Pyodide is ready, it runs the collected Python code line by line, capturing outputs and errors, and displays them nicely in the browser.
The result? You can write real Python (including basic libraries) and have it behave like it's part of the webpage.
Example
html
<!DOCTYPE html>
<html>
<head>
<script src="pytml.js"></script>
</head>
<body>
<py>
print("Hello from Python!")
for i in range(5):
print(f"Counter: {i}")
</py>
</body>
</html>
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:
PYTML - Python in Your Browser
The easiest way to run Python in HTML. No server. No backend. Just one line of code.
Please leave as a star if our work is useful to you !
Quick Start
Add one line to your HTML:
<script src="https://pytml.vercel.app/pytml.js"></script>
Usage
Option 1: Inline Python (Recommended for mobile/local)
<!DOCTYPE html>
<html>
<head>
<script src="https://pytml.vercel.app/pytml.js"></script>
</head>
<body>
<py>
print("Hello, world!")
name = input("Your name? ")
print(f"Hi {name}!")
</py>
</body>
</html>
Option 2: External Python File (HTTP/HTTPS only)
<!DOCTYPE html>
<html>
<head>
<script src="https://pytml.vercel.app/pytml.js"></script>
</head>
<body>
<script type="text/python" src="script.py"…My portfolio:
Website :
Top comments (1)
Some comments may only be visible to logged-in visitors. Sign in to view all comments.