TechAE Blogs - Explore now for new leading-edge technologies

TechAE Blogs - a global platform designed to promote the latest technologies like artificial intelligence, big data analytics, and blockchain.

Full width home advertisement

Post Page Advertisement [Top]


Pyscript | Run Python In Your HTML

At PyCon US 2022, Anaconda released a new version called PyScript, a Javascript framework that will let you create python applications using both Python and standard HTML.


In this blog, I will explore this new feature through a hands-on example.


You can write and run Python code in HTML, call Javascript libraries in PyScript, and do all your web development in Python. It enables drop-in content and application hosting without the reliance on server-side configuration. It uses Pyodide and Web-Assembly to communicate between two languages JavaScript and Python.

1. Create HTML Document

Let's first create an index.html document, we are using Bootstrap for the frontend purposes and also adding some CSS to design our elements.

<!doctype html>
<html lang="en">
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- Bootstrap CSS -->
    <link href="" rel="stylesheet"
        integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    <link rel="preconnect" href="">
    <link rel="preconnect" href="" crossorigin>
    <link href=";700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="./css/app.min.css">
    <title>Pyscript Testing</title>

<body class="d-flex h-100 text-center text-white">
    <div class="cover-container d-flex justify-content-center w-100 h-100 p-3 mx-auto flex-column">
        <main class="px-3">
            <h1 class="display-2 fw-bold mb-5">Pyscript Testing</h1>
            <p class="lead mb-4">Framework that allows users to create sophisticated browser applications with Python</p>

    <script src=""


Now our page looks like this:
Initial Page

2. Install PyScript

To install PyScript, just you have to import the appropriate pyscript files to your HTML page within the <head></head> tags.

<link rel="stylesheet" href="" />
<script defer src=""></script>

Well, that's a piece of cake!

3. Add Python Packages

We can load the python packages like NumPy, Pandas, and Scipy using py-env into our environment. We can also import local modules using this, I have added using paths.

        - numpy
        - matplotlib
        - pandas
        - paths:
            - ./

4. Write Python Code

By adding the py-script tag, we can embed Python code in it. You can get the file from my GitHub.

print("Hello World!")
import antigravity

Finally, after adding py-script, you can see python code running in your HTML document. I have used the antigravity example project to explain the work, you can check the live version here.

Final Image

Note: Be careful in adding indentation within py-script tags.

To Conclude:

PyScript brings a new idea to the Python and JavaScript ecosystems. Data scientists who wish to share their research with the world can do it more easily now. We have more to explore in this new stunning field.

More Resources:


  1. I read a article under the same title some time ago, but this articles quality is much, much better. How you do this.. esx scripts

  2. Your blog contains lots of valuable data. It is a factual and beneficial article for us.Learn Python Functions Online USA Thankful to you for sharing an article like this.


Thank you for submitting your comment! We appreciate your feedback and will review it as soon as possible. Please note that all comments are moderated and may take some time to appear on the site. We ask that you please keep your comments respectful and refrain from using offensive language or making personal attacks. Thank you for contributing to the conversation!

Bottom Ad [Post Page]