• Latest
  • Trending
How to run python code in your browser

How to run python code in your browser

May 16, 2022
Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

July 29, 2025
French Telco Orange Hit by Cyber-Attack

French Telco Orange Hit by Cyber-Attack

July 29, 2025
ATC Ghana supports Girls-In-ICT Program

ATC Ghana supports Girls-In-ICT Program

April 25, 2023
Vice President Dr. Bawumia inaugurates  ICT Hub

Vice President Dr. Bawumia inaugurates ICT Hub

April 2, 2023
Co-Creation Hub’s edtech accelerator puts $15M towards African startups

Co-Creation Hub’s edtech accelerator puts $15M towards African startups

February 20, 2023
Data Leak Hits Thousands of NHS Workers

Data Leak Hits Thousands of NHS Workers

February 20, 2023
EU Cybersecurity Agency Warns Against Chinese APTs

EU Cybersecurity Agency Warns Against Chinese APTs

February 20, 2023
How Your Storage System Will Still Be Viable in 5 Years’ Time?

How Your Storage System Will Still Be Viable in 5 Years’ Time?

February 20, 2023
The Broken Promises From Cybersecurity Vendors

Cloud Infrastructure Used By WIP26 For Espionage Attacks on Telcos

February 20, 2023
Instagram and Facebook to get paid-for verification

Instagram and Facebook to get paid-for verification

February 20, 2023
YouTube CEO Susan Wojcicki steps down after nine years

YouTube CEO Susan Wojcicki steps down after nine years

February 20, 2023
Inaugural AfCFTA Conference on Women and Youth in Trade

Inaugural AfCFTA Conference on Women and Youth in Trade

September 6, 2022
  • Consumer Watch
  • Kids Page
  • Directory
  • Events
  • Reviews
Thursday, 16 July, 2026
  • Login
itechnewsonline.com
  • Home
  • Tech
  • Africa Tech
  • InfoSEC
  • Data Science
  • Data Storage
  • Business
  • Opinion
Subscription
Advertise
No Result
View All Result
itechnewsonline.com
No Result
View All Result

How to run python code in your browser

by ITECHNEWS
May 16, 2022
in Data Science, Leading Stories
0 0
0
How to run python code in your browser

Web App development is a domain where newer tools and technologies emerge rapidly. Nowadays, companies are interested in creating web applications in order to attract customers through interactive web applications rather than shows some HTML pages over the internet to stand out.

Javascript is the queen of web programming languages which comprises almost the entire web development tools and frameworks. We can develop a web application in just a fraction of seconds using Angular, React or the native javascript.

Python is so popular with its library support that most companies prefer it as their best choice for AI and data science projects.

As the demand increases, new changes are aligned to develop the application in a rapid manner where the amalgamation of different technologies plays a vital role. By combining python and HTML, we can render the python codes on HTML pages.

Brython is an implementation of Python 3 which can be used to run python codes in your browser. Last week, Anaconda’s CEO Peter Wang announced a revolutionary technology called PyScript which allows users to run python code in their browser.

In this article, we will try to cover the implementations of python in HTML pages.

The big moves in web development — Brython and PyScript.

Getting Started

Let’s start with Brython.

1. Brython

Python frameworks such as Flask and Django is used to render on the server side whereas Brython is serve python code on the client-side.

Brython is a framework which can be used to inject python code over HTML pages. Its primary objective is to replace Javascript as the scripting language for the web. Brython is capable of interacting with DOM thus making it a promising framework on the scripting side. This ability of Brython can be used to create something new in the browser.

Installation

Brython provides CDN links which can be used to integrate with the web application.

  • Add the following code in the HTML file to add the Brython dependency.
  <script src="https://cdn.jsdelivr.net/npm/brython@3.10.5/brython.min.js"></script> 
  <script src="https://cdn.jsdelivr.net/npm/brython@3.10.5/brython_stdlib.js"></script>
  • Bind the function brython() on HTML page load.
  <body onload=brython()>
  • Write Python code inside the tag.
      <body onload="brython()">
      <script type="text/python"> 
        # your python code 
      </script>
      </body>
    

     

    First program

    Let’s try our first Brython framework program which runs on the client-side.

    YOU MAY ALSO LIKE

    French Telco Orange Hit by Cyber-Attack

    ATC Ghana supports Girls-In-ICT Program

      <!DOCTYPE html>
      <html>
      <head>
          <script src="https://cdn.jsdelivr.net/npm/brython@3.10.5/brython.min.js"> </script>
       <script src="https://cdn.jsdelivr.net/npm/brython@3.10.5/brython_stdlib.js"></script>
      </head>
      <body onload="brython()">
          <h2 id="msg"></h2>
          <script type="text/python">
              from browser import document
              document <= "Hello World"
              document['msg'].text = "Hello World"
              print("Hello World")
          </script>    
      </body>
      </html>
    

     

    Brython provides an online console to write and execute the python codes.

    You can include the python console on your website using,

      <iframe src="http://brython.info/console.html" width="800" height="400"></iframe>
    

     

    Brython can interact with DOM elements and Javascript libraries such as Highcharts, jQuery, Socket.io, Three.js, etc. It is easy to fetch data from the server using an ajax call from the brython library.

    If you are interested in trying out brython, checkout the following repositories.

    • brython-dev/brython
    • codemaker2015/brython-demo

    2. PyScript

    During PyCon US 2022, Anaconda’s CEO Peter Wang unveiled a revolutionary framework — PyScript. Which enables users to write python codes in the browser.

    PyScript is a JavaScript framework which allows users to embed python codes inside the HTML page like PHP. It enables the users to use the power of python libraries such as numpy, pandas and scikit-learn on web apps. It also enables users to carry out statistical and AI computations inside the web app rather than processing the data on a server and sending the response back to the client.

    PyScript is built on Pyodide. CPython is a port of Pyodide which is based on WebAssembly. WebAssembly converts human-readable .wat text format language to a binary .wasm format that browsers can run on.

    pyscript
    Image credits: anaconda.cloud/pyscript

    Installation

    PyScript provides CDN links which can be used to integrate with the web application.

    • Add the following code in the HTML file to add the PyScript dependency.
    <link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
    <script defer src="https://pyscript.net/alpha/pyscript.js"></script>
    

     

    • Add PyScript components such as and to the html page to write python code snippets inside the browser.
    • <py-script>: wraps python code that is executable within the web page.
    • <py-repl>: renders the code editor and allows the user to write code in it.
    <py-script> 
        # your python code 
    </py-script>
    

     

    First program

    Let’s try our first PyScript framework program which runs on the client-side.

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Hello World</title>
        <link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
        <script defer src="https://pyscript.net/alpha/pyscript.js"></script>
        <style>
            #msg {
                font-size: x-large;
            }    
        </style>
    </head>
    <body>
        <h1 id="msg">
            <py-script> 
                print('Hello World') 
            </py-script>
        </h1>
    </body>
    </html>
    

     

    You can include the python console on your website using,

    <py-repl>
        print('Hello World')
    </py-repl>
    

     

    For example:

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

     

    If you are interested in trying out pyscript, checkout the following repositories.

    • pyscript/pyscriptjs/examples

    Thanks for reading this article.

    If you enjoyed this article, please click on the heart button ♥ and share to help others find it!

    The full source is available on https://github.com/codemaker2015/python-on-browser-examples

Source: Vishnu Sivan
Via: dev.to
Tags: How to run python code in your browser
ShareTweet

Get real time update about this post categories directly on your device, subscribe now.

Unsubscribe

Search

No Result
View All Result

Recent News

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

July 29, 2025
French Telco Orange Hit by Cyber-Attack

French Telco Orange Hit by Cyber-Attack

July 29, 2025
ATC Ghana supports Girls-In-ICT Program

ATC Ghana supports Girls-In-ICT Program

April 25, 2023

About What We Do

itechnewsonline.com

We bring you the best Premium Tech News.

Recent News With Image

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

July 29, 2025
French Telco Orange Hit by Cyber-Attack

French Telco Orange Hit by Cyber-Attack

July 29, 2025

Recent News

  • Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa July 29, 2025
  • French Telco Orange Hit by Cyber-Attack July 29, 2025
  • ATC Ghana supports Girls-In-ICT Program April 25, 2023
  • Vice President Dr. Bawumia inaugurates ICT Hub April 2, 2023
  • Home
  • InfoSec
  • Opinion
  • Africa Tech
  • Data Storage

© Copyright 2026, All Rights Reserved | iTechNewsOnline.Com - Powered by BackUPDataSystems

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In

Add New Playlist

No Result
View All Result
  • Home
  • Tech
  • Africa Tech
  • InfoSEC
  • Data Science
  • Data Storage
  • Business
  • Opinion

© Copyright 2026, All Rights Reserved | iTechNewsOnline.Com - Powered by BackUPDataSystems

Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?
Go to mobile version