CodeNewbie Community 🌱

Cover image for PyScript - Python in the Web Browser
Aadarsh Kannan
Aadarsh Kannan

Posted on

PyScript - Python in the Web Browser

PyScript is a framework that combines the power of Pyodide, WASM, and contemporary web technologies with the HTML interface to let users build robust Python applications in the browser.

The PyScript programming language would not be possible without basing it on a recent version of Pyodide. Pyodide is an interpreter for the CPython language that has been compiled with Emscripten into WebAssembly. This enables Python to run in a web browser.

It is a single-page application (SPA) written in TypeScript using the Svelte framework styled with Tailwind CSS and bundled with rollup.js. According to one of the comments in an early Git commit.

PyScript is not trying to convert professional web developers. Instead, it’s designed for the 99% of web users who aren’t professional developers - Peter Wang [Anaconda co-founder and CEO]

Just like in every other language, Let's start with the hello world in PyScript.

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <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-script>print("Hello, World!")</py-script>
</body>

</html>
Enter fullscreen mode Exit fullscreen mode

First, import the necessary PyScript's JS and CSS module, then get started by entering the content in the py-script tag. Run the server and you will be able to see "Hello, World!" as a result.

Here's my repo that is curated for sharing and learning pyscript in one place. Check it out!

GitHub logo dotAadarsh / Everythings-PyScript

This repo is curated for sharing and learning pyscript in one place.

PyScript

This repo is curated for sharing and learning pyscript in one place.

Python in the Web Browser | programming for the 99%

Articles πŸ“°

  • Getting started with PyScript ↗️
  • A First Look at PyScript: Python in the Web Browser ↗️
  • How to Use PyScript – A Python Frontend Framework ↗️
  • Intro to PyScript: Run Python in the browser ↗️
  • PyScript – or rather Python in your browser + what can be done with it? ↗️

Podcasts 🎧

  • #367: Say Hello to PyScript (WebAssembly Python) | Talk Python To Me | Spotify ↗️
  • S8:E7 - Faking DEI Efforts, Ruby at Scale, and Diving Into PyScript | DevNews | Spotify ↗️
  • Digging Into PyScript & Preventing or Handling Python Errors | The Real Python Podcast | Spotify ↗️

Videos πŸŽ₯

  • PyScript - Run Python in the Browser…

Thanks for the read! Stay tuned!

- Aadarsh K

Top comments (0)