Pytml
| Developer(s) | Aswanth R |
|---|---|
| Initial release | June 2026 |
| Stable release | 2.5.1
/ October 19, 2026 |
| Written in | JavaScript |
| Engine | |
| Type | Software library |
| License | Apache-2.0 |
| Website | pytml |
Search Pytml on Amazon.
Pytml is an open-source JavaScript library that runs Python code written inside HTML pages. It uses Pyodide, a port of Python to WebAssembly, so the code executes in the visitor's browser and no Python server is needed.[1] It is developed by Aswanth R and released under the Apache License 2.0.[2]
The library was written with teaching in mind. Its developer has said the aim was to let people who already know some Python make a web page interactive without first learning JavaScript and the browser's Document Object Model (DOM) interfaces.[1] It overlaps in purpose with PyScript, and the project's own documentation describes it as a lightweight alternative to that framework.[2]
Design
Syntax
A page loads Pytml with one <script> tag. Python code is then placed between <py> tags, in a script element of type text/python, or in an external file named by a src attribute.[2][1] When the page loads, Pytml starts Pyodide, finds these blocks and runs them.[3]
Tags written as <py1>, <py2> and so on mark separate programs. The number is an identifier and not a file name: blocks that share a number share one namespace, and blocks with different numbers do not.[2] Version 2.5 also recognises numbered interface tags (<btnN>, <inputN> and <txtN>) inside a Python block. Before the code reaches Python, a preprocessing step removes these tags from the source, leaves the surrounding text and its indentation unchanged, and inserts the matching button or text field into the page.[1]
Page elements and events
Elements that have an id attribute are made available to Python as variables with the same name. Each variable is a thin wrapper around the browser's own DOM object, with properties such as text and value.[1] Event handlers are attached with an on() method, which passes the browser event to a Python function as a dictionary-like object and returns a function that removes the handler again.[1] Because this design relies on direct access to the page's DOM, it runs on the browser's main thread and not in a web worker.[1]
Input and output
Text sent to print() is shown on the page, and uncaught exceptions are reported there as well.[3] Python's input() normally pauses a program until the user types something, which a browser cannot do without freezing the page. Pytml therefore rewrites such calls using Python's abstract syntax tree tools so that they wait asynchronously for a text field on the page.[1]
Packages and browser features
Packages are installed through Pyodide's micropip tool. Packages that Pyodide already provides, including NumPy, pandas and Matplotlib, can be used.[2] Beyond basic DOM access, the library includes helpers for mouse, touch, keyboard and scroll events, timers, the clipboard, browser storage, file downloads, full-screen mode, the HTML canvas, audio and video, gamepads, and an on-screen touch joystick.[1]
Example
The following page contains a button and a paragraph. Python changes the paragraph's text when the button is clicked.[1]
<script src="https://pytml.vercel.app/pytml.js"></script>
<button id="hello">Click me</button>
<p id="output"></p>
<py>
def clicked(event):
output.text = "Hello!"
hello.on("click", clicked)
</py>
Here hello and output are the elements with those ids, and no JavaScript is written by the page's author.
Security
Pytml's text property writes to the browser's textContent interface, so any markup in the string is displayed as literal characters and is not run. A separate html property writes to innerHTML, which can execute scripts if it is given untrusted input. The project's documentation advises against passing user input to html directly and provides a pytml.escape() function for that purpose.[2]
Limitations
The Pytml script is about 15 KB, but it loads the Pyodide runtime, which is roughly 6 MB and must be downloaded on a visitor's first load. Later visits can use the browser cache.[3] Packages with C extensions work only if a WebAssembly build exists for them.[3] The developer lists tutorials, technical blog posts and small data demonstrations as intended uses, and puts heavy back-end processing, database work and production APIs outside the project's scope.[3]
Relationship to other projects
Several other projects run Python in the browser on top of Pyodide. The Pyodide documentation lists them as related projects, and its list includes PyScript, which defines <script type="py"> elements for HTML, marimo notebooks and JupyterLite.[4] Pytml appears in the same list, which describes it as a small library that connects HTML elements to Python variables.[4] Python application frameworks such as Streamlit and Gradio present their own interface components. Pytml instead keeps the page as an ordinary HTML document and exposes its elements to Python.[1]
History
Pytml was first released in June 2026. Version 2.5.0 was published in October 2026, and 2.5.1 was the latest release as of November 2026.[5] In an October 2026 post on the Pyodide project's blog, its developer described the numbered-tag syntax added in version 2.5 and said he was considering a larger compiler-based design for a later version.[1]
Reception
The project received limited coverage in its first months. On 19 November 2026 the Python Weekly newsletter included it in a list of new projects and libraries.[6] The technology site LockerGnome reviewed it the day before. Its writer, Chris Pirillo, said the library suits short interactive examples in lessons, and noted that the small size quoted for the script does not include the much larger interpreter download. He also pointed out that browser Python is limited by package compatibility, and that the project's claims about privacy apply only to code execution, because the page still loads an interpreter from a content delivery network.[3]
Availability and archiving
The source code is hosted on GitHub, and a copy of the repository has been archived on Zenodo with a digital object identifier (DOI) for citation.[7] The project is also listed on OpenForge, an open-source software platform run by the Government of India,[8] and in the Research Software Directory.[9] The developer has also published descriptions of the project on DEV Community[10] and on Coderlegion.[11] The project was also submitted to the hackathon platform Devpost.[12]
See also
References
- ↑ 1.00 1.01 1.02 1.03 1.04 1.05 1.06 1.07 1.08 1.09 1.10 1.11 R, Aswanth (19 October 2026). "Pytml: Python in Your HTML with a Single Script Tag". Pyodide blog. Retrieved 22 November 2026.
- ↑ 2.0 2.1 2.2 2.3 2.4 2.5 "NodeX-AR/Pytml". GitHub. Retrieved 22 November 2026.
- ↑ 3.0 3.1 3.2 3.3 3.4 3.5 Pirillo, Chris (18 November 2026). "Pytml runs Python inside HTML tags by loading a browser-side interpreter". LockerGnome. Retrieved 22 November 2026.
- ↑ "Releases · NodeX-AR/Pytml". GitHub. Retrieved 22 November 2026.
- ↑ Chaudhary, Rahul (19 November 2026). "Python Weekly (Issue 772 November 19 2026)". Python Weekly. Retrieved 22 November 2026.
- ↑ "Pytml". Zenodo. doi:10.5281/zenodo.20786716. Retrieved 22 November 2026.
- ↑ "Pytml". OpenForge. Government of India. Retrieved 22 November 2026.
- ↑ "Pytml". Research Software Directory. Retrieved 22 November 2026.
- ↑ R, Aswanth. "Pytml: Running Python in the Browser Without a Backend". DEV Community. Retrieved 22 November 2026.
- ↑ "Pytml: Running Python in the Browser Without a Backend". Coderlegion. Retrieved 22 November 2026.
- ↑ "Pytml". Devpost. Retrieved 22 November 2026.
External links
Category:JavaScript libraries Category:Python (programming language) libraries Category:Free software programmed in JavaScript Category:WebAssembly
This article "Pytml" is from Wikipedia. The list of its authors can be seen in its historical and/or the page Edithistory:Pytml. Articles copied from Draft Namespace on Wikipedia could be seen on the Draft Namespace of Wikipedia and not main one.
