I am trying to learn PyScript as it it discussed Here about PyScript, and my simle Hello World script that I got from there fails to work, either as an HTML on my web server or called directly via browser from the file explorer.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Title: PyScript</title>
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
</head>
<body>
<py-script> print("Hello, World!") </py-script>
</body>
</html>
I know how to run Python scripts via command line with no problem, but that’s as far as I can go right now without a framework and an application server platform.
Any ideas? Thanks
Article might be a bit old or out of date, it’s from 2022. I could not get this to work either.
I found another example from the website linked in the article, it’s totally different:
https://pyscript.com/@examples/pyscript-jokes/latest?files=README.md,index.html
Maybe you can follow this guide it seems to be from 2025:
https://docs.pyscript.net/2025.3.1/beginning-pyscript/
I signed up for PyScript and created my own sandbox project. It consisted of index.html, main.py, and pyscript.toml. I copied the files to my /cma folder locally, changed pyscript.toml to pyscript.json, reconfigured it, and then deployed to the webroot for IIS to take a run of it. Going to index.html on localhost/cma doesn’t throw any errors at all, but it also doesn’t display anything, but that, for me, is progress
index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Hello World</title>
<!-- Recommended meta tags -->
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<!-- PyScript CSS -->
<link rel="stylesheet" href="core.css">
<!-- This script tag bootstraps PyScript -->
<script type="module" src="core.js"></script>
</head>
<body>
<script type="py" src="./scripts/main.py" config="./scripts/pyscript.json"></script>
</body>
</html>
main.py:
from cma import app
from flask import Flask
print("Content-type: text/html")
print("Hello World!")
pyscript.json:
{
"name": "Hello World",
"packages": ["wfastcgi", "flask"],
"appSettings": {
"PYTHONPATH": "C:\inetpub\wwwroot\cma",
"WSGI_HANDLER": "cma.app"
},
"system.webServer": {
"handlers": {
"name": "PythonHandler",
"path": "*",
"verb": "*",
"modules": "FastCgiModule",
"scriptProcessor": "C:\Python313\python.exe|C:\Python313\Scripts\wfastcgi.py",
"resourceType": "Unspecified",
"requireAccess": "Script"
}
}
}