Python

What is Brython?

Rajdeep Singh
FrontEnd web
Published in
3 min readJan 31, 2021

--

I deep love for Python and Javascript. I'm always trying to find a solution to run the python directly inside the web browser. One day luckily, I found a youtube video by Traversy Media. Traversy media tells us about Brython with the demo. You use Brython to write python code directly inside the browser.

After I became more curious about Brython, I learned more about Brython(Browser Python).

python language
Photo by George Stewart on Unsplash

Whats is Brython(Browser Python)?

Brython is a new library written in python3. Use Brython, and you run python directly inside your web browser. The Brython aims to replace the javascript.

Brython is a new way of javascript. Brython is easy to understandable and usable. You easily interact with dom(Dom Object Model) and change dom help of python.

Main features

Brython supports most of the syntax of Python 3, including generators, metaclasses, imports, etc., and many modules of Python.

It supports the latest specs of HTML5/CSS3, and also you use CSS Frameworks like Bootstrap 3, LESS, SASS, etc.

How to install Brython?

You install Brython very easily help of pip and CDN.

using pip:

pip install brython

Then create an empty folder/ directory and run the following command.

brython-cli --install

If Brython-cli does not work. then follow this command

python -m brython --install

Folder structure

The folder structure looks like

Run the Web server app

Run webserver locally use of python.

python -m http.serverorpython -m http.server 8001

After some time, Brython launches the new version. You update Brython's with two commands.

pip install brython --upgrade
brython-cli --update

Now you start working on Brython.

Using CDN:

You use Brython's help of CDN (Contact delivery network). You copy CDN links on the official Brython website. after paste links inside your HTML page.

<script src="https://cdn.jsdelivr.net/npm/brython@3.9.0/brython.min.js"> </script> <script src="https://cdn.jsdelivr.net/npm/brython@3.9.0/brython_stdlib.js"> </script>

Update your Brython. Just change CDN links on your site.

How to use Brython?

Use Brython very easily inside your project. follow all steps

  1. Firstly, install Brython help of CDN and npm.
  2. Secondly, Call the function brython() on page load, like <body onload="brython()">.
  3. Write Python code inside script tags. <script type="text/python">.
<body onload="brython()" >   <script type="text/python"> # write python code here </script></body>

Hello World Example

In the Hello World example, you show hello world inside the dom.

Hello world example

Mouse Event Example

Mouse Event Example you understand the basics of event handling in Brython

mouse example

Alert Example

In this Alert example, I Create an alert in the browser

alert example

Dialog box example

In this example, I create a dialog box in the browser use of python

dialog box example

Future of Brython

In my opinion, Brython's future is not clear. Every New Technology Coming with own thought. Brython Launch official Nav 22 2016.

After 4-year Brython did not create a big impact on the developers' community. Maybe in the future developer's mind change. The developer shows more interested in Brython.

Conclusion

You write python code and run it directly inside the web browser. But Brython does not replace clear javascript.

You use Brython to handle the frontend and backend in one place. I think this feature is very cool for me.

If you hire me, then follow me on Upwork and Fiverr.

Fiverr:
https://www.fiverr.com/users/officialrajdeep/

Upwork:
https://www.upwork.com/freelancers/~01a4e8ba7a41795229

--

--

Rajdeep Singh
FrontEnd web

JavaScript | TypeScript | Reactjs | Nextjs | Rust | Biotechnology | Bioinformatic | Frontend Developer | Author | https://linktr.ee/officialrajdeepsingh