Run Python inside your HTML

Made with JavaScript!


Run Python inside your HTML


PyScript is a framework that allows users to create and run Python in the browser using the HTML interface.

PyScript aims to provide users with a first-class programming language that has consistent style rules, is more expressive, and is easier to learn.


Installation

To implement it is very easy, just include the CDN of CSS and JavaScript in your code HTML, example:

<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>

And then just use the Python code between the <py-script> tags, for example:

<py-script> print('Hello, Python!') </py-script>

You may notice some slowness, if you want it to be a little faster, please download the files and link locally:

wget https://pyscript.net/alpha/pyscript.js https://pyscript.net/alpha/pyscript.css

And the full HTML code here:


<!DOCTYPE html>
<html lang="en">
  <head>
    <title>PyScript</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="./pyscript.css" />
  </head>
  <body>
    <py-script> print('Hello, PyScript!') </py-script>
    <script defer src="./pyscript.js"></script>
  </body>
</html>

For more information visit the PyScript official website .


python html


Share


YouTube channel

Subscribe


Marcos Oliveira

Marcos Oliveira

Software developer
https://github.com/terroo

Related articles