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.

  <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>
  <body onload=brython()>
Exit mobile version