PyScript • How to run Python in a browser

pixegami · Beginner ·🌐 Frontend Engineering ·4y ago

Key Takeaways

Explains PyScript framework for running Python in a browser

Full Transcript

pi script is a new framework that was released just earlier this month which lets you run python code directly in the browser and this is quite a big deal because this is the first time that something like this is widely possible with python my name is jack and in this video i'm going to explain what the pi script framework does i'll show you some examples and then i'm going to talk about what i think this means for the future of python and web development so pyscript was unveiled in may 2022 by anaconda and in case you're not familiar with who they are then they are the company behind one of python's most popular data science platforms so needless to say this team has a solid track record the main selling point of pi script is that it lets you run actual python code directly in the browser and this is quite a new thing before this if you wanted to run a python application on the website it would typically have to be a back-end server that you communicated with either via http endpoints or a socket connection with pi script it's a lot easier you don't even have to install anything if you load up a web page that imports the pi script framework which is just two lines that you need to add to an html file then it's ready to execute python code this means it's now possible to distribute any python project that you create directly in the browser whether that's just a simple automation script a complex data science project or even a game like mario and people will be able to just go to that url and use it without having to install python in fact it should even work on mobile devices environment management is also very much part of the package with pi script that means if you have several files and scripts you wanted to run then pi script would support that this extends to external packages as well in fact a major selling point of pyscript is that it lets you access the entire python ecosystem so that means libraries like scikit-learn pandas and matplotlib are all available for you to use i see this as a particularly strong use case for pyscript because i feel that the existing front-end javascript frameworks today have a bit of a gap in the data science and analytics functionality now at this point you're probably wondering how pi script interacts with the front-end or in other words the html that is being rendered on the page well one way is that pi script exposes some helper classes to your code that lets you find certain html elements by their class or id and then you can change its text or even remove and append the content so if you've used jquery before then this should all sound quite familiar another way is that pi script offers bi-directional communication between python and javascript objects i haven't had a chance to test that functionality out yet myself but i assume that if you're using a framework like react or svelt then pi script will let you interact with it directly from your code now let's take a moment to deep dive how all of this magic actually works behind the scenes the main technology behind pi script is something called webassembly which is sort of a standard for writing code that can be compiled into something that browsers can run this code can be written in any language and as long as you can compile it to a binary in the webassembly format then it can be downloaded and executed directly in the browser webassembly itself is relatively new and has only recently been adopted as a web standard so as of this moment pi script is really on the cutting edge of web technology let's now dive into some examples so that you would have a better practical understanding of how to use pyscript let's start with a blank html file we can add pyscript by just pasting these two lines you don't have to download or install anything pi script will be downloaded by the browser when you open this page you can now use this tag to write python code directly into your html for example print hello world and you'll see it appearing directly in the page now i don't know about you but i actually prefer to write python code in an actual python file so let's do that here and then we can import it into the html like this you can also have things like buttons and input fields which you'll identify with html tags or class names and then you can use those things to interact directly with your python functions you can add new elements to the page and you can even import libraries and plot a graph directly in the browser and that's still just the tip of the iceberg if you visit the official pi script github page then you'll be able to see even more code examples of what it can do now i always find it exciting when new technology like this comes out but is it going to be something revolutionary or is it just a passing fad i think at this point it's too early to tell but here are my first impressions running python in the browser is going to be very handy in use cases where there is a gap in the existing front-end frameworks today so things like data science machine learning and image processing come to mind but i'm sure there's other things as well it will also improve the web development experience for python developers without having to learn javascript and there's a lot of python developers out there as it is one of the most popular programming languages so i'm sure they will be happy about that pi script also opens up the possibility of developing static sites with python logic something that i'm personally excited about and keen to explore that means you can develop a web distributed python app without needing a server or a backend games made with python could also be deployed in a similar manner however it's not all positive stuff there's some drawbacks as well each time the browser loads it needs to download the entire python binary and its libraries that is a major upfront cost and the performance won't be good enough for sites that need to load quickly which is most websites also the python ecosystem is still far behind the javascript ecosystem for web ui for that reason it's hard to see it replace something like react anytime soon but that's okay because i still think it solves a different problem and opens up some very exciting opportunities so that pretty much wraps up my take on pi script if you have any questions or comments about pi script or if you're keen to see a pie script tutorial then please let me know in the comments below otherwise i hope you found this useful and thank you for watching

Original Description

PyScript is a new framework that lets you run Python code in the web browser. In this video, I will explain what PyScript is and show you some code examples of how it works. I'll also talk about my first impressions of PyScript. Do you think this is a revolutionary new technology, or will it be a passing fad? 🔗 PyScript: https://pyscript.net/ Chatpers 00:00 Introduction 00:27 What is Pyscript? 01:36 Environment management in Pyscript 02:14 Interacting with HTML/Javascript 03:04 Deep dive: WebAssembly 03:35 Pyscript code examples 04:49 First impressions #pyscript #python
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from pixegami · pixegami · 16 of 60

1 How to Build an AWS Lambda Function in Python in Just 7 Minutes!
How to Build an AWS Lambda Function in Python in Just 7 Minutes!
pixegami
2 AWS CDK Tutorial: Deploy a Python Lambda Function using AWS
AWS CDK Tutorial: Deploy a Python Lambda Function using AWS
pixegami
3 I used GPT-3 to Write Poetry • Is AI the Future of Creative Writing?
I used GPT-3 to Write Poetry • Is AI the Future of Creative Writing?
pixegami
4 Create NFT Generative Art with Python! (Full Tutorial)
Create NFT Generative Art with Python! (Full Tutorial)
pixegami
5 Build an AI-driven SaaS Application: FULLSTACK Tutorial with Python, React, and AWS
Build an AI-driven SaaS Application: FULLSTACK Tutorial with Python, React, and AWS
pixegami
6 NextJS and TailwindCSS: How to Build a Portfolio Site from Scratch
NextJS and TailwindCSS: How to Build a Portfolio Site from Scratch
pixegami
7 Python Web Scraping Tutorial • Step by Step Beginner's Guide
Python Web Scraping Tutorial • Step by Step Beginner's Guide
pixegami
8 Build Wordle in Python • Word Game Python Project for Beginners
Build Wordle in Python • Word Game Python Project for Beginners
pixegami
9 How to create 1000+ unique NFT-style images (like Cryptopunk) | Python Tutorial
How to create 1000+ unique NFT-style images (like Cryptopunk) | Python Tutorial
pixegami
10 Top 10 Python Modules 2022
Top 10 Python Modules 2022
pixegami
11 How to Send SMS Text Messages with Python & Twilio - Quick and Simple!
How to Send SMS Text Messages with Python & Twilio - Quick and Simple!
pixegami
12 How To Write Unit Tests in Python • Pytest Tutorial
How To Write Unit Tests in Python • Pytest Tutorial
pixegami
13 How to Style Your React Landing Page with Tailwind CSS
How to Style Your React Landing Page with Tailwind CSS
pixegami
14 FastAPI Python Tutorial - Learn How to Build a REST API
FastAPI Python Tutorial - Learn How to Build a REST API
pixegami
15 How to Deploy FastAPI on AWS EC2: Quick and Easy Steps!
How to Deploy FastAPI on AWS EC2: Quick and Easy Steps!
pixegami
PyScript • How to run Python in a browser
PyScript • How to run Python in a browser
pixegami
17 My Custom Ubuntu Linux Terminal with Themes and Plug-ins 💻
My Custom Ubuntu Linux Terminal with Themes and Plug-ins 💻
pixegami
18 Deploy FastAPI on AWS Lambda ⚡ Serverless hosting!
Deploy FastAPI on AWS Lambda ⚡ Serverless hosting!
pixegami
19 NextJS Firebase Auth Tutorial • How to Authenticate Users for Your App
NextJS Firebase Auth Tutorial • How to Authenticate Users for Your App
pixegami
20 AWS Lambda Python functions with a database (DynamoDB)
AWS Lambda Python functions with a database (DynamoDB)
pixegami
21 How To Build a CRUD (TO-DO) App on AWS using FastAPI and Python
How To Build a CRUD (TO-DO) App on AWS using FastAPI and Python
pixegami
22 How to Make a Discord Bot with Python
How to Make a Discord Bot with Python
pixegami
23 How To Use GitHub Copilot (with Python Examples)
How To Use GitHub Copilot (with Python Examples)
pixegami
24 PyTest • REST API Integration Testing with Python
PyTest • REST API Integration Testing with Python
pixegami
25 Python Beginner Project: Build a Caesar Cipher Encryption App
Python Beginner Project: Build a Caesar Cipher Encryption App
pixegami
26 Decorators in Python: How to Write Your Own Custom Decorators
Decorators in Python: How to Write Your Own Custom Decorators
pixegami
27 NextJS 13 Tutorial: Create a Static Blog from Markdown Files
NextJS 13 Tutorial: Create a Static Blog from Markdown Files
pixegami
28 Exploring ChatGPT for Coding and Business ✨ 8 Real Examples!
Exploring ChatGPT for Coding and Business ✨ 8 Real Examples!
pixegami
29 How I Would Learn Python (if I had to start over) • A Roadmap for 2023
How I Would Learn Python (if I had to start over) • A Roadmap for 2023
pixegami
30 Build an AI Pokemon Generator with Python and Midjourney
Build an AI Pokemon Generator with Python and Midjourney
pixegami
31 Why You Should Learn Python in 2023 (as your first programming language)
Why You Should Learn Python in 2023 (as your first programming language)
pixegami
32 ChatGPI API in Python ✨ How to Build a Custom AI Chat App
ChatGPI API in Python ✨ How to Build a Custom AI Chat App
pixegami
33 Learn Python • #1 Installation and Setup • Get Started With Python!
Learn Python • #1 Installation and Setup • Get Started With Python!
pixegami
34 Learn Python • #2 Variables and Data Types • Python's Building Blocks
Learn Python • #2 Variables and Data Types • Python's Building Blocks
pixegami
35 Learn Python • #3 Operators • Add, Subtract and More...
Learn Python • #3 Operators • Add, Subtract and More...
pixegami
36 Learn Python • #4 Conditions • If / Else Statements
Learn Python • #4 Conditions • If / Else Statements
pixegami
37 Learn Python • #5 Lists • Storing Collections of Data
Learn Python • #5 Lists • Storing Collections of Data
pixegami
38 Learn Python • #6 Loops • How to Repeat Code Execution
Learn Python • #6 Loops • How to Repeat Code Execution
pixegami
39 Learn Python • #7 Dictionaries • The Most Useful Data Structure?
Learn Python • #7 Dictionaries • The Most Useful Data Structure?
pixegami
40 Learn Python • #8 Tuples and Sets • More Ways To Store Data!
Learn Python • #8 Tuples and Sets • More Ways To Store Data!
pixegami
41 Learn Python • #9 Functions • Python's Most Important Concept?
Learn Python • #9 Functions • Python's Most Important Concept?
pixegami
42 Learn Python • #10 User Input • 4 Ways To Get Input From Your User
Learn Python • #10 User Input • 4 Ways To Get Input From Your User
pixegami
43 Learn Python • #11 Classes • Create and Use Classes in Python
Learn Python • #11 Classes • Create and Use Classes in Python
pixegami
44 Learn Python • #12 Final Project • Build an Expense Tracking App!
Learn Python • #12 Final Project • Build an Expense Tracking App!
pixegami
45 Stripe & Firebase Tutorial • Add Payments To Your NextJS App
Stripe & Firebase Tutorial • Add Payments To Your NextJS App
pixegami
46 How To Use GitHub Actions • Automate Your AWS Deployments
How To Use GitHub Actions • Automate Your AWS Deployments
pixegami
47 How to Run a Python Docker Image on AWS Lambda
How to Run a Python Docker Image on AWS Lambda
pixegami
48 My MacOS Terminal Setup for HIGH Productivity
My MacOS Terminal Setup for HIGH Productivity
pixegami
49 Host a Python Discord Bot on AWS Lambda (Free and Easy)
Host a Python Discord Bot on AWS Lambda (Free and Easy)
pixegami
50 Python FastAPI Tutorial: Build a REST API in 15 Minutes
Python FastAPI Tutorial: Build a REST API in 15 Minutes
pixegami
51 Pydantic Tutorial • Solving Python's Biggest Problem
Pydantic Tutorial • Solving Python's Biggest Problem
pixegami
52 How to Get Started with AWS • Crash Course
How to Get Started with AWS • Crash Course
pixegami
53 Python Requests Tutorial: HTTP Requests and Web Scraping
Python Requests Tutorial: HTTP Requests and Web Scraping
pixegami
54 Amazon Bedrock Tutorial: Generative AI on AWS
Amazon Bedrock Tutorial: Generative AI on AWS
pixegami
55 How to Publish a Python Package to PyPI (pip)
How to Publish a Python Package to PyPI (pip)
pixegami
56 Langchain: The BEST Library For Building AI Apps In Python?
Langchain: The BEST Library For Building AI Apps In Python?
pixegami
57 RAG + Langchain Python Project: Easy AI/Chat For Your Docs
RAG + Langchain Python Project: Easy AI/Chat For Your Docs
pixegami
58 Python Dataclasses: Here's 7 Ways It Will Improve Your Code
Python Dataclasses: Here's 7 Ways It Will Improve Your Code
pixegami
59 Build a Custom AI RPG Game with OpenAI GPTs
Build a Custom AI RPG Game with OpenAI GPTs
pixegami
60 Create a Custom AI Assistant + API in 10 Mins
Create a Custom AI Assistant + API in 10 Mins
pixegami

Related Reads

Chapters (7)

Introduction
0:27 What is Pyscript?
1:36 Environment management in Pyscript
2:14 Interacting with HTML/Javascript
3:04 Deep dive: WebAssembly
3:35 Pyscript code examples
4:49 First impressions
Up next
Elementor Angie Ai Plugin Tutorial
Quick Tips - Web Desiign & Ai Tools
Watch →