Learn Python with Talk Python's 270 hours of courses

#367: Say Hello to PyScript (WebAssembly Python) Transcript

Recorded on Thursday, May 12, 2022.

00:00 Despite Python being overwhelmingly popular and reactions to it positive, there are major areas of computing where Python is not present, most notably on mobile and on the front-end side of the web.

00:11 PyScript, a new project launched by Fabio Pliger from Anaconda, just might change that.

00:18 It was made public and announced at PyCon just two weeks ago by Peter Wang and now has over 10,000 GitHub stars.

00:25 But what is hype versus reality versus projected hopes and dreams?

00:30 We're going to find out on this episode.

00:32 Fabio is here to tell us all about his new project.

00:35 This is Talk Python To Me, episode 367, recorded May 12, 2022.

00:53 Welcome to Talk Python To Me, a weekly podcast on Python.

00:56 This is your host, Michael Kennedy.

00:58 Follow me on Twitter where I'm @mkennedy and keep up with the show and listen to past episodes at talkpython.fm.

01:04 And follow the show on Twitter via at Talk Python.

01:07 We've started streaming most of our episodes live on YouTube.

01:11 Subscribe to our YouTube channel over at talkpython.fm/youtube to get notified about upcoming shows and be part of that episode.

01:19 This episode is sponsored by Microsoft for Startups Founders Hub.

01:23 Check them out at talkpython.fm/foundershub to get early support for your startup.

01:29 And it's brought to you by us over at Talk Python Training.

01:32 Did you know we have one of the largest course libraries for Python courses?

01:37 They're all available without a subscription.

01:39 So check it out over at talkpython.fm.

01:42 Just click on courses.

01:44 Transcripts for this and all of our episodes are brought to you by Assembly AI.

01:48 Do you need a great automatic speech-to-text API?

01:50 Get human-level accuracy in just a few lines of code.

01:53 Visit talkpython.fm/assemblyai.

01:56 Hey, before we jump into the interview with Fabio, creator of PyScript, I want to just tell you really quickly about this new YouTube video I made.

02:04 After chatting with Fabio, but before this episode is released, I decided to play around with PyScript some more.

02:12 It's really, really cool.

02:13 Turns out that one of the things there's not a great example for is how do I take and build a regular web application,

02:21 something you might do with Vue.js or something like that, with PyScript using Python on the front end.

02:28 And is it possible to actually avoid downloading the CPython runtime as a WebAssembly that comes out of Pyodide and all those things

02:37 and make your code sort of installed locally and run really fast and have actually a pretty great user experience?

02:44 Well, it turns out the answer is yes.

02:46 So I put together a 30-minute demo tutorial of that over on YouTube.

02:50 If you want to dive in a little bit and see that in action, after you listen to this episode, be sure to jump over to YouTube.

02:56 The link is at the bottom of the show notes in your podcast player on the episode page.

03:00 Head on over to my personal YouTube channel and check out that video.

03:03 I think you'll be pretty impressed.

03:05 And it'll just make you want to do more stuff with PyScript, I'm sure.

03:08 All right, let's chat with Fabio about PyScript.

03:10 Fabio, welcome to Talk Python to Me.

03:14 Thank you.

03:14 I'm really happy to be here.

03:16 Yeah, you're welcome.

03:17 And I'm excited to have you here because I am quite excited about the PyScript announcement that you have put so much work into.

03:24 I'm very excited about the possibility of finding Python in other places than where it has really great strongholds, right?

03:33 For as much as Python is, the incredible growth of Python that Stack Overflow blogged about in 2017 and all the growth in different metrics.

03:43 But by some metrics, first, most popular language or second, depending.

03:46 But for all of that, there's still very notable places where Python is not.

03:52 And what you're working on has the possibility to unlock one or more of those places or a whole different set of contingency.

04:00 The people of data scientists, web developers, UI developers, maybe just for desktop even.

04:06 So exciting.

04:07 Yeah, I think it captured a lot of the things behind the project.

04:11 Really happy to talk about all of those because, yeah, that's the reason we started it.

04:16 So excited.

04:17 Yeah, and it's super exciting.

04:19 There's been some attempts at this and we're going to get into, I want to sort of start our conversation about the history of what has come before and so on.

04:28 Before we do, though, let's just hear a bit about you.

04:31 How did you get into programming in Python?

04:32 So programming, I was being curious about a lot of things and probably doing too many things still today.

04:39 Early on, I got into programming through friends who had computers and Commodore or things like that.

04:48 We would pop on.

04:49 I had a, in my dad at some point bought a, I don't even know the version.

04:54 It was like similar to Commodore, but it was in Brazil, a gradient MSX or something.

05:01 It was a local, like a national branded computer, but it allowed you to jump in and do basic stuff and programming.

05:09 So I remember trying to play with my friends and try to code games.

05:13 Of course, we never get anything done.

05:15 But I always been passionate about computers and games and stuff like that.

05:19 So into college, I took a computer science degree, dreaming to become a game developer also never happened because I got...

05:27 I think it's really interesting that so many people want to get into game development and then they kind of see the sort of grinding mode of that industry, right?

05:35 It's like both fascinating and has this great pull.

05:37 Then you're like, but it's really hard on humans as well.

05:40 Yes, it's a very hard industry and very competitive.

05:43 My brother is an indie game developer and a lot of sleepless nights and working hard trying to get his thing out there.

05:53 And so, yeah, I think...

05:55 And through life, I also...

05:57 Just life happened.

05:58 I met my now wife and started to be a little more serious about, you know, gaming is great, but I also need to make plans for the future.

06:06 So I ended up graduating and started to work for a company that's automation, like machines automation and big industries, many on pharmaceuticals.

06:17 And I worked there for a while and I was in the team that would develop high level applications for analytics.

06:26 And we would usually do for big pharmaceutical production lines.

06:30 So providing all the charts and everything they need to say this production batch is valid for whatever FDA or whatever entity is approving them.

06:41 A lot of paperwork, a lot of things.

06:43 Eventually, at some point, my unit became a big part of the company.

06:47 So my, at the time, the CEO of the company asked, hey, do you want a startup spinoff of our company?

06:55 Just focus on software.

06:56 So I did that.

06:58 That sounds like a pretty fun challenge.

07:00 Yes.

07:01 Like do a startup without quite the risk of actually being a startup.

07:04 Yeah.

07:05 Yes.

07:06 Like you're going to get paid.

07:07 You know what I mean?

07:07 Yes.

07:08 You're going to get paid.

07:09 It also, I think the startup reality in Italy, I was still in Italy at the time, is very different from here.

07:16 It's really hard to have investors or, you know, to have, to collect money.

07:21 And basically you need to, it boils down to you investing on yourself, in your own company, and then trying to get profit within a number of years.

07:30 Okay.

07:30 It's got to be way more bootstrapped, self-funded, you know, sort of thing, huh?

07:34 Okay.

07:34 Yeah.

07:35 Do you think that's changed or is that still the same?

07:37 I think it's changing.

07:38 Yeah.

07:38 The last 10 years, I think a lot changed just from like the industry in general became way stronger in Europe as well.

07:46 There's a different mindset.

07:47 And I think culturally, South Europe has this culture of a different way to see money and investments compared to the US, for instance.

07:58 Sure.

07:58 But eventually, like this experience led me to the Python community early on.

08:04 I actually got into Python not by myself.

08:08 I heard about the language.

08:09 I was curious.

08:09 But someone within the company said, oh, we, you know, the son of this customer is really big in the Python community.

08:17 He could help us see if it's a good fit for our use case.

08:21 And it was around early 2000s.

08:23 And it was around early 2000s, maybe 2002, one.

08:25 Pretty early days of Python, really.

08:27 Yes.

08:27 And early days of, you know, scientific Python as well.

08:31 You know, the whole separation between Numerae and NumPy, numeric, all of that.

08:38 So I started.

08:40 I loved the language.

08:41 I started to use it in our tools.

08:43 It was a funny time where it was definitely unknown as a language.

08:48 And to get into big companies, it was a little tricky on the QA point of view.

08:53 And then, but it was interesting.

08:55 Eventually, I started to get more engaged with community, started to go to meetups in Italy and everything.

09:02 And then I think it was around 2004 or 2005, I started to go to my first conferences in Europe, love the community, started to, how can I get involved?

09:13 So at that point, later, late 2000s, I started the, with a bunch of friends in the Italian community, we started the Python Italia Association, which is basically nonprofit trying to push the language.

09:26 And the main focus was organizing the Python Italy conference.

09:31 We started in 2007.

09:33 Also that great, great community, a lot of work, but also paid back.

09:38 I remember the first year we were like, let's do this thing.

09:41 We were very passionate.

09:43 And we ended up in negative.

09:44 And all the members of the society.

09:46 Yes.

09:47 So just to say that big props to everyone in the community doing a lot of the community work, because it's a lot of work and it often is not paid or can even be out of each one.

09:59 You might have to pay to do the work.

10:01 Yes.

10:01 With the opposite of getting paid.

10:02 Yeah.

10:03 Long story short, I started to be also more engaged with the European community.

10:09 And we organized the European Python in 2011.

10:14 So for three years in a row.

10:16 And that got me into the European society.

10:18 Eventually became chairman of that, which basically means your Python society is this European nonprofit that pretty much in line with the PSF, tried in different ways, but tries to engage with community, organize conferences, raise some money to invest back in the community through grants and things like this.

10:39 And then I did that for a number of years.

10:43 So eventually, well, back in the day when I was starting to learn Python, I also started to use a lot of the scientific libraries.

10:51 And one of them was Chaco, which was a graphic plotting library for Python that Peter Wang developed with Brian VandenVen.

11:00 I think he was in the show.

11:01 Peter Wang being the CEO of Anaconda.

11:04 Yes, today, CEO of Anaconda.

11:07 And we met for the first time in person at Europython in Florence.

11:11 And he was like, okay, we know each other from the internet for a while.

11:14 Let's get more involved.

11:17 That year, I was still trying to make my company be successful.

11:21 It wasn't the right time.

11:23 The following year, I met with Travis Oliphant, the other founder of Anaconda in Berlin.

11:29 We just figured out, you know, like we're doing a lot of things that are similar.

11:32 We're passionate about the same thing.

11:34 So I eventually joined Anaconda in 2014.

11:37 And then eventually that following year, I moved to the U.S.

11:41 I joined the company full time.

11:42 Fantastic.

11:43 Well, it's quite the journey.

11:44 Yes.

11:45 This is interesting language.

11:46 Let me just start participating in some of the meetups.

11:48 Meetups become conferences.

11:50 Conference become continent-wide conferences.

11:53 And I think it's a pretty good takeaway for people who want to get more involved in the community.

11:58 And like every one of those steps probably didn't feel massive other than maybe moving to the U.S.

12:03 and joining Anaconda.

12:04 But, you know, they all probably seem like really iterative and sort of incremental.

12:08 But at the same time, it builds up to this really cool place where you're maybe building amazing Python things in the browser at Anaconda.

12:16 Right.

12:17 Yeah.

12:17 My experience has very much been what, you know, a lot of people say.

12:21 You come from the language, you stay for the community.

12:23 That is really my experience.

12:26 Yeah.

12:26 And then, yeah.

12:27 Anaconda allowed me to work on a lot of interesting things.

12:30 Like, as you said, Python in the browser is the ultimate project.

12:33 But when I joined, I started with being a core developer for Bokeh, which had some of that.

12:39 Bokeh is a visualization library for Python on the browser.

12:42 And with your project you have now, you can still put Bokeh in the browser.

12:45 Exactly.

12:45 It can stay in the browser.

12:48 Exactly.

12:49 Yes, exactly.

12:50 Even more in the browser than before, I guess.

12:52 Yeah.

12:52 All right.

12:53 Let's dive in.

12:53 Now, before we dive in real quick, since you talked about gaming, want to be in game development and your brother and so on.

12:59 Have you watched the documentary Power On, the story of Xbox?

13:02 I haven't.

13:03 No.

13:03 This is a documentary that came out.

13:05 It's a four-hour show.

13:07 You can watch it on YouTube.

13:08 Cool.

13:09 And it's like the history of Xbox.

13:11 Nice.

13:11 And if you're just into, like, tech history documentaries, this thing is pretty interesting.

13:15 But let's not talk about games.

13:16 Let's talk about the birth and death of JavaScript.

13:19 Have you seen this presentation?

13:21 Yes.

13:21 Great.

13:22 It is so good, isn't it?

13:24 Yes.

13:25 One of my favorite funny talks, you know.

13:27 The reason I bring this up is there's a lot of interesting building blocks that I suspect many people in the Python community are fully unaware of.

13:34 There's been all these developments over in the JavaScript world.

13:38 And Gary Bernhardt did this talk at PyCon 2014, the birth and death of JavaScript.

13:43 And no, I'm not mispronouncing it.

13:45 That's how it's done in the talk.

13:46 It tells this hilarious story of the future of, like, weird human evolution and programming and JavaScript and how we don't do JavaScript, but everything's JavaScript.

13:55 But what is the underlying theme is, like, an actual interesting technical history, how people started doing crazy stuff with JavaScript pre-WebAssembly.

14:04 So there were compilers, like in Scriptum, that will compile C code to JavaScript.

14:10 And then the JavaScript JITs have become so fast.

14:13 So one of the examples was, like, Chrome running Firefox, running something else, like maybe like an embedded Windows.

14:20 I can't remember what it was.

14:21 But just there were, like, layers and layers of JavaScript doing wild stuff that we wouldn't imagine otherwise, right?

14:28 Yeah.

14:28 Yeah.

14:29 And I think that's part of also one of the reasons with Peter we said, OK, this is the right time to try this out because the browsers became so powerful.

14:40 And so they are basically, if you see from a different perspective, they are mini virtual machines.

14:46 They have their own file system.

14:47 They have their own isolation networking.

14:50 A lot of the things, you can really see that as a VM.

14:54 Like the JVM, like the .NET CLR, and to some degree, like Python, right?

14:58 Right.

14:58 Right.

14:59 The CPython on a regular machine.

15:00 Yeah.

15:01 You can run full operating systems on top of, in the browser.

15:05 And honestly, the explosion of interesting things in the last few years have been crazy and doesn't seem to decelerate at all.

15:13 So the level of maturity is kind of encouraging.

15:16 It is.

15:17 And the performance, while not native performance, is not that far off.

15:21 At least some of the examples that Gary gave, it was like 50%.

15:25 You could run Doom at 50% speed when you compile it to the browser or something insane like that.

15:30 Right.

15:30 Yeah.

15:31 It's good enough.

15:32 It's more than good enough.

15:33 Yeah.

15:33 I mean, because the alternative so often is, well, we're going to send a request over to the server, and that might be native and fast, but it's also network latency, and it's also a shared compute resource.

15:43 With a thousand other people.

15:44 And here you are sitting on your MacBook Pro Max with 16 cores, and you're just waiting.

15:51 Yeah.

15:51 Yeah.

15:52 That's actually one aspect that a lot of people don't consider.

15:56 There is the performance in terms of how fast it goes.

16:01 But there are a few aspects that you also need to consider overall in the overall experience.

16:07 How long for the developer side of a point of view, how long before they can actually get in front of something usable or spinning up their environments and things like this.

16:17 Then there's loading time versus execution time.

16:21 Also very different.

16:22 But from the eyes of the user, it kind of sums up.

16:25 There are so many small niches or small verticals that we can work on in the whole JavaScript or browser ecosystem that I think we can make a lot of improvements the next few years.

16:37 Yeah.

16:38 You think of grid computing and distributed computing, part of the power of the cloud is that I could just go say, I need more.

16:47 We have four servers, but a bunch of people showed up.

16:50 So give me 20 servers and scale my Kubernetes cluster across that for now.

16:54 And four to 20 is amazing.

16:57 But four to 100 million is really different.

17:00 If we can push a lot of that compute to everybody's personal computers, even our iPhones are like unimaginably fast little devices.

17:09 Right.

17:10 Like the whole M1 crazy transition is basically an iPhone chip with more voltage, you know, and better cooling.

17:16 Right.

17:16 There's not much more to it than that.

17:18 So finding ways to execute more of our code on the clients is pretty interesting.

17:24 Yeah.

17:25 Totally agree.

17:26 We already see that even on the server side, projects like BASC, where very popular pushing computing on nodes and, you know, the distributed architecture is very powerful and it is needed.

17:38 We can have the possibility to make the same thing on the client side on the browser as well.

17:43 Yeah.

17:43 Yeah.

17:44 DESC, for those out there who don't know, is a Pandas-like, NumPy-like API that you can just say, but run it distributed across these machines on the cluster automatically.

17:55 You know, Matthew Rocklin started Coiled and, you know, former Anaconda alumni.

18:00 A lot of tie-ins there.

18:02 Yeah.

18:02 Yeah.

18:03 Cool.

18:03 It's not the same thing in any way, but it is a way that really takes Python and gives it way more compute resources potentially.

18:11 So are there any particular sort of set the stage with this compile-to-see and stuff, but is there any other sort of building blocks in the history of how we got to what you all built in the JavaScript stack that you want to call out?

18:25 Yes, definitely.

18:26 I think one major thing that, you know, I want to give props as much as we can, the Pyodide project, which is, you know, a runtime for Python on the browser.

18:36 And they've been extremely, like, one of the reasons we could work on PyScript was because it has a level of maturity and performance right now that is really stable, right?

18:49 And actually also been, they're a great community, very supportive.

18:54 So a big shout out to them, Hood and Roman specifically, the two main core developers.

19:01 And the whole work underneath that project as well, you know, like the progress of the MScript and WASM and WebAssembly, there is a huge community behind that.

19:14 So actually, that's one of the principles that we try to, at the core of PyScript, is we don't want to reinvent anything that we don't need.

19:23 We want to be really additive to the ecosystem, glue things together, provide nice and easy APIs and high-level APIs so that we can lower the barrier, basically give more accessibility to the tools, to the users, rather than reinventing something that's not needed.

19:40 Yeah, so PyIodide.

19:42 This project is a cool project.

19:45 I interviewed Michael from the project about this way, way back, a couple years ago.

19:53 But yeah, it uses this MScript and WebAssembly story to basically compile a port of CPython to run in WebAssembly in the browser, which is fantastic, right?

20:05 I mean, that's, and to some degree, that's the building block that you all really needed, right?

20:09 Yes, yeah.

20:10 Yeah, definitely.

20:10 Yeah.

20:11 I must mention also, yeah, Michael Dropbom and Christian Himes, who has been also pushing a lot of the Python on WASM ecosystem.

20:20 Yes.

20:21 Yeah.

20:21 There's a lot of good energy in the Python community to actually try to push that together, right?

20:27 Yeah.

20:27 And also Brett Cannon has been a big proponent of making that happen.

20:31 I don't know how directly he evolved with the day-to-day, like, let's make it compile, but I know he's been really pushing on that effort as well.

20:37 This portion of Talk Python to Me is brought to you by Microsoft for Startups Founders Hub.

20:44 Starting a business is hard. By some estimates, over 90% of startups will go out of business in

20:50 just their first year. With that in mind, Microsoft for Startups set out to understand

20:55 what startups need to be successful and to create a digital platform to help them overcome those

21:00 challenges. Microsoft for Startups Founders Hub was born. Founders Hub provides all founders at

21:06 any stage with free resources to solve their startup challenges. The platform provides technology

21:12 benefits, access to expert guidance and skilled resources, mentorship and networking connections,

21:18 and much more. Unlike others in the industry, Microsoft for Startups Founders Hub doesn't

21:23 require startups to be investor-backed or third-party validated to participate. Founders Hub is truly open

21:31 to all. So what do you get if you join them? You speed up your development with free access to

21:35 GitHub and Microsoft Cloud computing resources and the ability to unlock more credits over time.

21:41 To help your startup innovate, Founders Hub is partnering with innovative companies like OpenAI,

21:46 a global leader in AI research and development, to provide exclusive benefits and discounts.

21:51 Through Microsoft for Startups Founders Hub, becoming a founder is no longer about who you know.

21:56 You'll have access to their mentorship network, giving you a pool of hundreds of mentors across a range

22:01 of disciplines and areas like idea validation, fundraising, management and coaching, sales and

22:07 marketing, as well as specific technical stress points. You'll be able to book a one-on-one meeting

22:12 with the mentors, many of whom are former founders themselves. Make your idea a reality today with the

22:17 critical support you'll get from Founders Hub. To join the program, just visit talkpython.fm slash

22:23 foundershub, all one word, no links in your show notes. Thank you to Microsoft for supporting the show.

22:28 Let's get to your announcement. I mean, I didn't go to PyCon this year, mostly just not ready to be in a

22:38 room with people from around the world for that long and to give the world a chance to try it out,

22:43 then I'll see how it goes and do it next year. But I missed everyone there. And, but I got a lot of

22:47 messages. One was friends saying, why aren't you here? Why can't we have a beer together? Which,

22:52 sorry, I really missed that. And then the other is, have you heard of PyScript? Oh my goodness,

22:57 this was the announcement. Like this, if there's any big piece of news that came out from presentations

23:02 and talks and announcements, like this is the one. So PyScript, people can guess, but what is it?

23:07 Tell us about this. So PyScript is a framework that allows users to basically use HTML tags to define,

23:16 to run Python code and define different components. Those can be related to executing code, but also

23:24 providing, defining your environments, what packages you want to install, et cetera, as well as some UI

23:31 components that make things easier for users that are not familiar with HTML and CSS and all the styling

23:39 of things. It's based on a Python runtime, which is Pyodide that allows Python execution on the browser.

23:48 And it has interoperability capabilities with JavaScript as well. So you can use both Python libraries as well

23:56 as JavaScript libraries in your code.

23:59 Yeah. This is really great. And if people go to PyScript.net and scroll down and what is PyScript,

24:03 it really calls all these out. Like if you're trying to present this to your boss or your team,

24:08 you're like, this is something cool we should check out. Like they should definitely go to that list

24:11 right there. Yeah.

24:12 Yes. Yeah. That is, you know, the most immediate list of things. You know, there's a lot that we're

24:18 working on and trying to provide as a tooling, but it's very, very new and very, you know, green,

24:25 if I must say. So yeah.

24:27 So maybe don't totally release a product on it just yet.

24:30 Yes. Definitely. Very bad idea to release a product. This, you know, expect APIs, code and features to change.

24:38 Actually, it's one of the things that we intentionally talked about before Python was, you know, should we have a versioning in place or something like this so that, you know, you would expect any project to go that goes out there to have versions and everything.

24:54 Yeah. Yeah. So we intentionally said, no, let's wait because it is, or let's put a version like do not use in production dot zero dot one.

25:03 Zero dot zero dot zero dot negative one.

25:05 Yes. Mostly because, you know, with this, we want, we wanted to have something that is working, that is useful, that it can be used by and hacked on by users that they want, but also give the vision that we have in mind and for people to see the possibilities.

25:24 And that was the main focus for the project until Python.

25:28 Right.

25:28 Now, a lot of the following things are just the things that we want to achieve in order to enable a community.

25:36 And this is an open source project.

25:38 It's not an, it started at Anaconda, but it's an open source project.

25:42 We want to have a strong community, have contributors beyond the Anaconda team and build it together.

25:50 Yeah. That was one of my questions I wanted to ask you about is it sounds like you all have a very strong vision of what this should be and where you want it to go.

25:58 Yes.

25:59 But from what you just said, it's, I was wondering, does that mean it's more source open than open source?

26:03 And like, we're driving this way and we'll take PRs as long as it's on our, our roadmap or how open are you to people just jumping in and giving ideas and trying to build it up?

26:12 Oh, yeah. Great question. We are very open. So it's worth also saying that right now we are at the stage where I don't think we've made it that easy for people to onboard and understand the vision, understand the project, and actually be able to contribute.

26:31 We're missing a lot of documentation. So one of the biggest pushes that we we've been having after PyCon is to actually build up the documentation around those things so that anyone contributing have a easier time onboarding, understand the visions, and can give feedback based on those things.

26:49 So as soon as we are also growing the team behind it that so there's a lot of small things that we are preparing for the being a community that is on itself or self organized and everything.

27:02 So overall, I think that this is really a community project.

27:07 Sure. Speaking of community, let me just pull up the GitHub page. So you're just shy of 10,000 stars.

27:12 Yeah, crazy.

27:13 That's, I don't know how old it is, but it's how long is this repo been public? Not that long, right?

27:18 We actually made it public 10 minutes in during Peter's talk.

27:22 Okay. So you're like half of Flask almost or half of closing in on FastAPI levels of numbers of stars. There's a lot of interest in this.

27:31 Yes, which is really exciting, but also is somehow overwhelming, right? Like I'll be very honest.

27:37 There's a lot of expectations as well, right?

27:40 Yes. Yes. And so we are aware of all of that. I think the main thing really for us is to, you know,

27:48 we want to make sure that our users have patience because we're trying to get to a stable state or at least, you know.

27:57 It's less than two weeks old. Come on.

27:58 Exactly. Yes.

27:59 It's a baby.

28:01 Yeah. I could talk about this for hours. But at the same time, we want to make sure that it's usable and we want to collect users' feedback to make it better.

28:10 Actually, one thing that is very important is that it got a lot of interest and a lot of excitement from the Python community and some of the web community as well.

28:21 But I really want to make sure that everyone understands the picture. The full picture is what Peter said, like programming for the 99%.

28:30 So beyond developers, how can we have a tool that students can learn very fast, get to learning coding very fast or even non-developers?

28:42 I would love my mom to write her recipe book with PyScrime, right? Because it's that easy.

28:47 Yeah.

28:47 And thinking about the possibility of shipping that in your phone or your mobile users in developing countries that do not have access to computers and things like this, but they have a phone.

28:58 What we also hope is that the social impact of a tool like this could be very big. One can dream.

29:05 Yeah. Yeah. One can dream for sure. So something maybe you could take inspiration from is the Swift Playgrounds, right? It seems like you can model that pretty well.

29:14 And I feel like Swift was largely borrowing from Python in a lot of its ways. So it's time to borrow a little back from Swift.

29:20 Yes.

29:21 For people who don't know, Swift Playgrounds is like a little bit like a REPL, a little bit like Jupyter.

29:26 But then on the right, you get kind of more iOS outputs, like little widgets and graphs and animations and whatever.

29:34 But it seems like that could be a similar way that's sort of like Jupyter, but also a little more web playful.

29:41 Right. Yes. And I would say we have no shame into like borrowing from others, right?

29:47 I think that actually is how you can grow well.

29:51 Like take what's successful from this community or this language, et cetera, and try to use that to make a better tool.

29:58 Yeah. Because it's so early, because it's so fresh.

30:00 Like one of the drawbacks, call it a drawback, one of the temporary limitations is people can't just jump in and build the next version of Gmail or whatever with it right now.

30:10 But a benefit is so many people want to contribute to open source and they're like, I love Django.

30:15 I'm going to contribute to that. Or I love Jupyter. I want to contribute to that.

30:18 And then it's such a complex, highly leveraged, very polished system that like, well, contributing to that means you have like an insane level of understanding to make this little change that won't break everything else.

30:31 Whereas this is pretty fresh, right? So if somebody wants to come along and build something like a Swift Playground equivalent, the door is open for, and I'm not sure how much you want to accept that, but like the door is open for people to be, to grab ideas that are lower hanging fruit at the moment.

30:46 Yeah. The idea is also to allow users to extend the tool itself and without having to change the tool, like with extensions and things like this.

30:57 Like in my mind, I see that as a sort of Minecraft for programmers, right? Like you can view your own blocks and then share with others and then they can share, they can.

31:08 Right. I can check out my mod pack for this thing or whatever.

31:11 Yeah. Yeah. Yeah. And yeah, the idea is to make it well, powerful, but also fun and hackable.

31:17 Yeah. Very cool. All right. Now let's talk about, I know we talked to some of these things here, but let me just dive in a little bit on the bullet points to kind of do a wrap up summary before we move into the coding.

31:27 So Python in the browser, this means it runs 100% in the browser through primarily WebAssembly, which is leveraging the Pyodide project. Yeah.

31:37 Right. That's right. Okay. And the WebAssembly stuff runs, I think, even better than the JavaScript.

31:43 The C code compiled to JavaScript because this is still more of a binary form and whatnot.

31:50 That's pretty excellent. One of the things that really inspires me here, you spoke about this will allow us to do things on our phones and on lower end computers and do other things like that.

32:01 where like now we have this possibility just if you have a browser, you can kind of do it.

32:04 I totally agree and that's great.

32:06 But what really gets me excited about where this could go is progressive web apps

32:11 or something even like Electron.js, right?

32:15 Where I build like a true desktop application like VS Code or Slack or whatever,

32:21 but instead of having to write everything in JavaScript, you know, write it in Python, right?

32:25 And just got to include the 2 meg or 3 meg WASM file with your, what is already a massive Chrome distribution.

32:32 So no one would know anyway.

32:33 Right.

32:33 Anyways, all right.

32:34 So yeah, the estimation.

32:36 Think about this, like there's a way to sort of, this is what I was hinting at at the beginning as well.

32:40 Like, oh my gosh, we can have things in our doc that are like modern looking,

32:44 that are based on Python easily.

32:46 Very exciting.

32:47 Yes.

32:47 Or Taskbar if you're a Windows person.

32:49 Right.

32:50 The whole story about the native apps and mobile and whatnot.

32:55 Russell Keith McGee, maintainer of beware, is he just joined Anaconda a few months ago.

33:00 Oh, he did?

33:01 Okay.

33:01 I didn't know that.

33:02 Excellent.

33:02 Yes.

33:03 And he's been sort of looking at the project, collaborating, contributing with some stuff.

33:07 He actually made an example.

33:09 One of the examples is written in Toga, which is the beware toolkit for UI design

33:15 and stuff like this.

33:16 And it's built in Toga, but has a PyScript backend so that it can render to PyScript directly.

33:24 Pretty much like it can build for iOS or Android or Mac.

33:28 But another interesting story is the opposite, right?

33:32 Like, can we have an app, a PyScript app that then Toga can transform into an electron-like app

33:38 that you can just run on your mobile?

33:40 Lots of possibilities.

33:41 Please do it.

33:42 Do it.

33:42 Do it.

33:43 So many people would be happy, yeah.

33:45 Yeah.

33:45 If you're listening, that's for you.

33:47 Yes.

33:48 Oh, my goodness.

33:49 Look, I think there are plenty of negatives about electron apps.

33:53 Like, why does my password manager need 400 megs of RAM to run?

33:58 But we have such a limited set of options for desktop and mobile apps and Python

34:06 that for now, that would be massively welcome to do something like this.

34:10 And then there's always possibilities of, well, do you actually have to ship Chrome

34:13 in some like massive runtime or could there be a smaller host, right?

34:16 Like there's layers of improvement.

34:18 All right, next one, Python ecosystem.

34:19 When you think about the history, this is not the first or the second time

34:23 that someone has done Python in the browser.

34:25 Like if you're familiar with, are you familiar with Anvil?

34:27 Yes.

34:28 I had Meredith on from Anvil to talk about both Anvil one time and then I think it was Sculpt,

34:35 which is what they use.

34:37 And Anvil has both a back end and front end that's all Python.

34:40 A really interesting project.

34:42 And they were using a JavaScript variant called Sculpt.

34:47 And there's, I think, Brython is another one that you could choose.

34:50 But one of the challenges of that is it's Python-like, right?

34:54 It's not really the Python runtime.

34:56 Do you maybe want to talk about like how that differs from the Python ecosystem,

35:01 Python runtime that you all have?

35:02 Right.

35:02 That's exactly the difference, right?

35:04 And probably the Pyodide folks would have a lot more to say.

35:08 But the big difference is what you said.

35:10 Like it's Python-like.

35:11 For example, numerically, like JavaScript doesn't have integers.

35:14 So your Python has to somehow fake integers if you're going to do things like that, right?

35:19 Right.

35:20 It's mimicking what you would expect with Python, but with the JavaScript.

35:24 And it's not really a full-blown Python interpreter that you can also install your packages.

35:30 The whole Python ecosystem is not supported.

35:33 And I think that's the big difference that was the differentiator for Pyodide.

35:38 And now that, you know, CPython actually compiles to Asm through M-Scripten,

35:43 it's very exciting that we can...

35:45 Is running the same VM or the same runtime that we get with CPython on our desktops,

35:51 more or less, like a cut-down limited version, but it's not like a weird transpile to JavaScript

35:55 and then run it.

35:56 Yes, correct.

35:57 With a few caveats, right?

36:00 That's one of the things that I think is worth mentioning.

36:03 It's the same CPython code, and it's the same thing you get in your local installation.

36:10 A few things are different just because the browser as a VM, they work differently, right?

36:15 Like file system is different on the browser.

36:18 Sockets are different.

36:20 Threading, probably.

36:20 Threading, multiprocessing, pipes, and things like this, right?

36:24 There are solutions for some of these that will require work and probably upstream

36:31 with some of the parts of the standard libraries or the third-party packages,

36:37 but they are just different.

36:39 So we need to account for that.

36:40 Sure.

36:41 All right.

36:41 So you can use, it says, many popular Python packages and stuff in the scientific data stack.

36:47 Question from the audience, from Christopher Tyler says, my very limited understanding,

36:52 since you're using PyDyde, is that there's a limitation on the libraries you can use,

36:56 meaning can you import your own custom libraries?

36:59 Generally, it's yes, right?

37:00 But not universally, isn't it?

37:02 Right.

37:02 That's a great question.

37:03 Let's talk first about the standard libraries and the third-party libraries

37:07 that you have on PyPI, et cetera.

37:08 So PyDyde ships with the standard library plus a set of packages that they ported.

37:15 Most of these are, they use C extensions and things like that.

37:20 So they need to be compiled.

37:21 And so the PyDyde team took that work and took care of it.

37:26 They're included in the distribution.

37:28 There is a way for you to also build packages that depend on C extensions.

37:34 They have a nice guide in their website that you can follow, and they will help with that.

37:39 In general, you should expect your Python packages to work if you hip install them, right?

37:46 Yeah.

37:46 The caveat there is, do they have other dependencies that are C, depend on C extensions,

37:52 and that will cascade in what work?

37:56 Or do they rely on some of the things that I mentioned before, like multi-threat,

38:00 multi-processing, and sockets and stuff?

38:03 So in that case, the package may install, but it will raise an error because multi-processing is not supported

38:11 or other things like this.

38:12 What about simple stuff like async and await?

38:14 Great question.

38:15 It's not from a, like, what it expects of the operating system is pretty low,

38:19 but it's also pretty advanced.

38:21 Right.

38:21 That is more of, I think it's less of the packaging problem and more of a philosophical problem

38:28 in terms of how you compare Python to JavaScript, for instance, right?

38:32 JavaScript, even if it's synchronous as a language, it has built the idioms over time

38:39 to always try to be asynchronous because for obvious reasons, you don't want to,

38:45 you don't want to block your browser or, you know, if you're doing something in your page

38:49 and you block your Chrome on your phone.

38:51 And that way, it seems like it should be a fantastic match for async and await.

38:54 Yes.

38:55 The waiting on I.O., yeah.

38:56 Yes.

38:56 It is a fantastic match and almost everything that you do that would be blocking in JavaScript,

39:02 you would async await.

39:03 In Python, we are used to do everything blocking and then when we want to do explicitly,

39:09 we just, we use async.io or something different.

39:13 So I think on that side of things, it's more of a, how you develop your Python code

39:20 rather than the language and the package.

39:22 You might have to have a mental model that matches closer to like what JavaScript traditionally has.

39:26 Yes.

39:27 Yeah.

39:27 But, you know, you can use async await anywhere in your code in Pyodide and PyScript.

39:32 Oh, sweet.

39:34 Okay.

39:35 I should have started on this list here 40 minutes ago.

39:38 But next question from Roller is, how would I pip install something into PyScript?

39:43 Which is, you know, a follow-up from what Chris asked in this like Python ecosystem integration.

39:47 Clearly, pip install a thing is like got to be at least 30% why Python is so popular.

39:53 Right.

39:53 Yeah.

39:54 Not commenting on the packaging for Python or JavaScript.

39:57 And they all, we all know that most people don't have problems with them.

40:02 They all have idiosyncrasies, let's say.

40:04 They all got their weirdnesses.

40:05 Right.

40:05 So Pyodide itself allows you to use MicroPip, which is, we will pip install

40:11 your dependencies.

40:12 Is it like an NPM-like thing where it creates like, instead of a node module,

40:16 it creates something else?

40:17 Yeah.

40:17 It's like NPM, or it's more like pip really for Python.

40:21 And it will go, and if it's a package provided by Pyodide itself, we will load that package

40:27 for you.

40:28 If it's a package that is not available there, it will check on IPI.

40:33 And you can also specify the location of the package itself.

40:36 So if you have your own repository, but you have your URL that points to a wheel file

40:42 or a zip file, it will install from there.

40:44 Yeah.

40:44 And that wheel can be remote, just like you might have a CDN-pointed thing

40:48 for JavaScript.

40:49 Yes.

40:49 Like, here's my wheel.

40:50 Okay.

40:50 Yeah.

40:51 If it's pure Python, right?

40:52 If it's C, then all bets are off.

40:53 If it's C, you should have done your duty and ported it to WebAssembly.

40:59 But the PyScript provides a layer on top of that where you can specify a tag called PyEnv

41:07 and it accepts CMO format and you can specify your dependencies there and both for packages

41:14 and also has an extra key called paths where you can actually provide the link to your modules,

41:20 custom modules that you want to...

41:22 effectively like the working directory of your Python.

41:25 So when you type import filename or directory slash filename, it kind of mirrors that

41:30 to the browser, right?

41:31 Yes, exactly that.

41:32 If you know how Python works, it's basically adding those files to your syspath.

41:37 So it finds them.

41:39 Interesting.

41:39 Yeah.

41:40 Cool, cool.

41:41 All right.

41:41 Another one that's really important here is Python with JavaScript.

41:44 So it's not like you're locked into this PyScript little box, right?

41:49 What I think this is another thing that makes me very optimistic for the future is

41:53 you can communicate back to other JavaScript, to JavaScript events, button clicks to the DOM.

41:59 So if here's another dream that I have is something like a Vue.js wrapper

42:05 type of thing that I could do in Python and then do sort of model binding

42:10 or attribute binding to the DOM and have that sort of stuff happening.

42:14 And this is really important to make it a first class citizen that can work with

42:18 all the stuff on the page.

42:19 not like a canvas that was given or something.

42:21 Yeah.

42:22 Yeah.

42:22 So before I go into this, I want to plus one on what you said around reactive

42:27 sort of programming and components where they can be attributes that auto notify

42:33 others' elements.

42:34 That is definitely something that we would love to explore more.

42:38 And there's a lot of interest.

42:39 And on the Python with JavaScript side of things, I, after the keynote at PyCon,

42:45 I saw a lot of videos coming up with like, oh, is JavaScript that now that Python

42:50 can run on the browser and things like this.

42:53 I think that narrative kind of looks at one side versus the other where we,

43:00 what we really want to encourage is actually the two together.

43:04 There is a ton of really great libraries in JavaScript.

43:08 And there is a level of maturity in JavaScript on things on the browser or UI creation

43:14 or, you know, drawing on Canvas or on the page that we are nowhere close

43:22 to the 1% in Python.

43:23 And all of a sudden, you can use those tools in Python and vice versa.

43:28 All of a sudden, JavaScript users could use NumPy or SciPy and other things

43:33 to power their applications, right?

43:34 Wow, that's interesting.

43:35 I hadn't really thought about the benefit others like outside of Python people may be receiving.

43:40 But yeah, now Python becomes a thing so they could leverage.

43:43 Yeah, exactly.

43:44 I think if we start looking at this that way, then you can see how PyScript is a glue

43:49 for building reacher applications, depending, like independently if you're a JavaScript developer

43:54 or a Python developer.

43:56 And we are starting with Python.

43:58 It makes a lot of sense.

43:59 But if there is a Rust implementation on WASM or an R, I'm sure that the Python

44:06 scientific community would love to use R tools in the page with Python stuff

44:11 and maybe JavaScript as well, right?

44:14 Yeah.

44:14 I think it's building together kind of movement that we want to push forward.

44:18 Yeah.

44:19 If I can look out and imagine a future, I don't know that there's a chance

44:24 how much it would exist, but a really great future of like, well, we have WebAssembly.

44:28 What if we really made WebAssembly more of a first-class citizen from a browser maker

44:34 perspective?

44:35 one thing I think would be fantastic is if instead of getting to the DOM

44:39 through JavaScript and through the events through JavaScript is if all of the

44:43 browser makers said, here's a WebAssembly native thing that you can use to bind to the DOM

44:49 and to the events and basically control it, you know, you could have Rust in the browser,

44:54 Python in the browser, C# in the browser, and they could all have this common API

44:58 defined in maybe even an adapter type thing like, well, in C# it's classes

45:03 and in Python it's, you know, Lambdas, I don't know, whatever, right?

45:06 Like some variation that's more native to your world, but if there was some kind of interaction

45:11 that we could build on, that would be even better, but we don't have that,

45:14 so this integration with JavaScript and all of its modern features is fantastic.

45:19 You still would want that, but it would be nice if there was a way, just put Python aside,

45:23 like if I'm doing WebAssembly stuff that I could stay in WebAssembly, stay native

45:27 to interact more with the browser.

45:29 Yeah, and honestly, the interaction between the WebAssembly part of it and JavaScript,

45:34 it's very fast.

45:35 You know, I want to highlight one thing that you said.

45:37 A lot of the future and how can this improve is on the, you know, browser folks to...

45:44 It's on the vendors, yeah, it's on the shoulders to do it.

45:46 Yes, because like the huge bottleneck that we have right now is that you still,

45:52 like when you load your things, you still need to compile them and run them

45:56 in WebAssembly.

45:57 So there's a loading time right now is very high and we're working on optimizing things

46:02 and there's a lot of great work from the CPython folks and the Pyodide folks

46:07 to reduce the size of things that you're shipping by default.

46:11 But ultimately, if you have a large scientific application, you still want to install

46:16 NumPy and Vokey and other stuff like this and you will have a loading time.

46:20 There is a loading time and, you know, I think that might mean it doesn't make sense

46:24 for the homepage of Reddit or like your marketing page that needs to load

46:30 super fast to have to be implemented in this.

46:33 But if you're writing something like Google Maps, Gmail, like I go to those sites

46:39 and then they spin and spin and spin for three seconds already, you know,

46:42 like the first time you hit that, it does that.

46:44 The second time it would just be cached.

46:46 Right?

46:46 All the stuff is off.

46:47 The WebAssembly stuff is just off disk and if your expectation is this page

46:51 might take two seconds to load sometimes, you're good, I think, honestly.

46:55 Yeah.

46:55 All that to say like this is the current state, right?

46:58 I think there's a huge margin for improvement in the future and a lot of really great

47:03 people are looking at it.

47:04 Yeah.

47:04 Okay.

47:05 I agree and I think the momentum is just building.

47:08 So let's look at some code and some examples so we can make this concrete

47:11 for people over audio, which is tricky, but let's do it anyway.

47:14 So you've got the GitHub page which has a bunch of examples and so what I want to do

47:20 is kind of just pull up some of the examples here and let me remind myself

47:25 what they are called.

47:26 Let's do this one first, actually.

47:28 I want to look at anti-gravity.

47:30 So we all know the xkcd and if you go to the REPL and Python you type import anti-gravity,

47:36 amazing stuff happens.

47:38 And so here we have that equivalent in PyScript, but there's a couple of things

47:43 that are really interesting about this.

47:44 So let's pull this up.

47:45 It says based on this thing and you give it a second and it says, the xkcd is,

47:50 how are you flying?

47:51 There's someone up there flying.

47:52 They're like, Python, I just imported anti-gravity, right?

47:54 It's great.

47:55 But this is a variation.

47:56 Maybe describe what just happened on the screen here.

47:59 People can go to the demo and watch it, of course.

48:02 This is, yeah.

48:03 If they just check out the repo.

48:04 This is a great, great example done by Philip Rudiger, his core contributor

48:10 to PyScript but also contributor to Panel, the Holovie, he's done a lot of great stuff.

48:16 And what's happening here is we're loading the SVG first and then there's

48:23 another Python function that basically takes that statement and makes it float

48:27 but basically changing coordinates.

48:29 literally animates and flies up into the sky.

48:32 Like it really takes off not just it's up there, right?

48:34 Yes, yes.

48:35 And for anyone wanting to check them out, the examples are also available

48:40 on pyScript.net slash examples and you can run them.

48:44 They are, okay.

48:44 Directly there.

48:45 Interesting.

48:46 We'll link to that as well.

48:47 So I said this is interesting.

48:49 It's interesting for several reasons.

48:51 One, if I go and look at my task manager in Vivaldi, this is doing like 30% CPU

48:57 constantly refreshing.

48:59 I don't know what the frame rate is but it seems certainly passable in terms of

49:03 there's cool animations going on on this rendering this canvas and it looks good, right?

49:09 It doesn't seem like oh, this just isn't going to work.

49:11 It's like the person doesn't like glitch.

49:13 Right, right.

49:14 You know what I mean?

49:15 Yeah.

49:15 The other one is it highlights many of the things that I think are pretty interesting here.

49:19 Let me pull up the code for the example and this maybe will give us a chance

49:24 to talk through the programming model.

49:25 So first of all, the first thing that's interesting is it has this pyenv section

49:30 and you have people maybe have seen examples and if you go to the home screen

49:34 you can actually the pyscript.net it says there's new tag done through web components

49:41 called py-script instead of just script and you can just write Python code

49:44 directly in the browser but you only want to do that for so long until you want to

49:50 read it across a couple pages or whatever.

49:52 So what's really cool here is the implementation of this is actually a custom

49:56 Python file on the server, right?

49:58 Yeah, exactly.

49:59 We've been working on that for some time the design of this because as you said

50:05 there's a tension between allowing people to just drop things in the page

50:10 and then have your Python code there and it just works to also suggesting

50:15 better patterns to do this.

50:19 Like you definitely don't from a quality point of view it's really hard to test anything

50:23 that you just drop on the page you know a readability point of view or refactor it

50:27 or anything, right?

50:28 Right, right.

50:28 But at the same time we really want this to be something that people can play with

50:33 and hack with and then don't have too much to think to think about oh I need a file

50:38 I need to name it Python you know all of that.

50:40 If there was a npm install step and then there was a compile step and then a pack step

50:46 like you would shave off like 75% of the people who just wanted to check it out.

50:50 Right.

50:50 So we allowed this pattern but you could also say like the same code could be

50:55 the same thing in PyPI and then in PyScript you could also have PyScript source equals

51:00 in a Python file so you can run that from files as well.

51:04 Right, yeah.

51:05 So just like with the regular script tag you say source and it can do a thing

51:09 on startup you know like jQuery did it $document.ready hook right at the top

51:15 all the time like you could do the equivalent of something like that.

51:18 Okay, this is cool but this is only part of it let me open up the other file

51:22 the antigravity.py and this is the one this is the one that made me really happy

51:25 because when I look at this it's you know how is that animation happening right?

51:30 What you do is you set a timer do a callback you know where you are in JavaScript

51:33 and it goes click, click, click, click, click let's see how often are you doing this?

51:38 Do you remember what the target frame rate was here?

51:41 I don't remember.

51:42 Yeah, anyway there's some sort of time where you say run it this frequently

51:45 and basically what you do is you go over here and you say this is Python

51:51 you say document get element by ID alright first of all awesome with a ternary expression

51:56 and then you go and add through the DOM parser you add the SVG in there that's amazing

52:04 you do a replace child with some HTML stuff and then you go and you hook

52:09 the set interval so set interval is the way to say set a callback on a timer

52:13 in JavaScript and then you just call the Python function self.move right?

52:18 So there's a really cool interaction between JavaScript that's happening

52:22 at a high frequency that shows do some stuff in Python go over to JavaScript

52:28 go through the DOM and then call back into Python when things that are interesting happen

52:32 here is an interval but it could be a button click or a drop down select

52:36 or whatever right?

52:36 Right right and we're doing some work right now at providing a higher level

52:42 interface that would be more Pythonic to those JavaScript you know the usual

52:48 things that you would always do in JavaScript like selecting an element by ID

52:52 or class or things like this like a CSS selector sort of right model or something

52:57 yeah yeah exactly so I think the goal is to provide the simplest and more

53:02 expressive or Pythonic interface that we could to hide some of that complexity

53:07 because at the end a lot of Python users or new users will have to end up

53:12 learning about JavaScript itself right I didn't want to learn JavaScript

53:16 and here I am learning JavaScript I think what you're learning though is not

53:19 you're not learning JavaScript what you're learning is the DOM API the APIs

53:23 that JavaScript often consumes right correct right you have to learn that

53:26 the DOM has a get element by tag name rather than I have to say I can't say var

53:33 anymore var char they have to say let or else that'll complain you know what I mean

53:37 like you're not learning the language nuances but you are learning the APIs

53:41 that JavaScript people are very common familiar with and it's a great point

53:45 like another thing for instance the set interval could be replaced with full

53:49 Python and just say like from asyncio important sleep you know time sleep

53:53 and then while just do a loop just do a loop and asyncio wait interesting

53:59 no kidding okay like a while true exactly await sleep then move okay yeah this is

54:05 really really neat I think this example is so simple it's playful and it's not

54:09 just we put a graph on the page not to say that that's not important but it's

54:14 different than what we've seen before often yeah honestly I really props to

54:18 to fill it like in I don't know what 50 lines of code or 40 lines of code

54:23 yeah like yeah 45 for the entire implementation of a flying anti-gravity

54:28 right SKCV pretty neat pretty neat yeah and in Python those are not 45 lines

54:33 of JavaScript right cool okay audience question Marcel says would it accept

54:38 loading data from a file for processing like you know we're pulling in modules

54:42 but like what's the data story that's a really really great question I think the

54:47 data story is yet to be told we're dedicating a lot of effort to that right now

54:52 you can you can load data using fetch basically and you can fetch data and then read

54:58 just like normal files PyDite provides a PyFetch wrapper around the JavaScript

55:03 fetch but there is a lot that can be done and we are working on it to have

55:08 better support and just how does the story for larger files look like can I do

55:13 a panda read CSV and give it a URL or something like that that's a great question

55:17 I'm not sure I don't know yeah I don't know I have no idea I really just wondering

55:21 yeah yeah but yeah that's one of the stories that I think is needs more development

55:25 right now you can pull files and read them with that method but there's more

55:30 work to be done there yeah okay let's look at another demo here let's see

55:35 give me so good okay this one's interesting too this panel I think it's panel stream

55:40 is the one and this is one of those that is gonna take some time to load

55:45 because under the hood it's installing panel and installing bokeh I think and

55:50 other visualization libraries that are heavier right right right so well let's try it a

55:55 second time right so what do you guess seven or eight seconds maybe it took

56:00 that first time but if I hit it again it says it downloaded 3.6 megs yeah

56:05 tick tock you should have cached most of the things that you compiled but also if

56:10 you have if you set your browser to not cache it will not change anything

56:15 yeah well I think the the challenge is that I'm using just python-m HTTP server

56:20 so I'm not really using a proper server for this yeah so that's not helping

56:25 I'm gonna let that one load up while we're I'm pulling up another one here

56:29 that I want to talk about yeah is there one that you think we should highlight in

56:32 particular I mean we've got the matplotlib one which is pretty interesting

56:35 over here that shows this the d3 one is pretty interesting as well the d3 one

56:42 you said right okay d3 has been a library that python folks have always wanting

56:48 to be using that one was super fast that one was two or three seconds right

56:53 maybe less than two seconds yeah yeah and that should have basically the

56:57 same loading time as javascript because we're not really importing much or installing

57:01 new libraries and once I hit your your example server then it's cached it

57:05 right yeah yeah the second time you do yes so yeah another one the webgl

57:11 right down this one this also should load pretty fast and shows wrapping webgl

57:17 oh yeah directly this one this one shows an example of codecahedrons or something

57:23 a bunch sort of rotating spinning around it's a little bit like a 3d asteroid game

57:27 with no spaceships something like that I guess maybe is a way to think of it

57:33 and if I go to oh and also as I move my mouse it reacts to I didn't I hadn't moved

57:37 my mouse so that's pretty cool I open up my little task manager thing I don't know

57:42 if it shares but it says basically it shows you how hard it's working and it's

57:47 20% CPU for this 3d rendering interaction thing that's if you probably try to do this

57:53 in pure Python and like Pygame it might be more yeah I'm not sure about like

57:56 the performance and you know like resources but it should be pretty much

58:01 once you're using JavaScript things they should be pretty much the same as JavaScript

58:06 pure JavaScript much like Python often just sort of orchestrates C code once you've loaded

58:11 something into the C layer and you're kind of just instructing it through simple

58:14 commands it's probably not very different here exactly yes all right cool

58:18 all right so I strongly encourage people to go check out the demo code it's just under

58:23 the example folders in the GitHub repo which we'll link to Fabio we're running

58:27 low on time here there's so much so much more I want to talk to you about

58:30 you drive yeah let me just see a couple of example or a couple of areas I want to

58:34 talk about here I just want to quickly touch on security I think the security

58:38 story is pretty simple but I do have one question so to some degree people might

58:43 go oh my gosh it's compiled C and JavaScript in the browser like you know

58:49 what madness are people going to unleash on the world right this is like

58:53 ActiveX or some dreaded com thing all over again and really WebAssembly also has

58:59 the same sandbox security as JavaScript right right actually a lot of the issues

59:03 that we've been getting around security boils down to that people like not being

59:09 used you know to seeing the browser as a VM so oh if I type OS list there and

59:16 stuff like this I can I have access to the file system well you're having access

59:20 to an ephemera file system in the browser here and not your local file system

59:26 that is a very important aspect one thing that would make me super happy

59:30 is if we had some beautiful Python API to the local data side of things so inside

59:37 the browser in JavaScript you get access to what's it called local DB and there's

59:41 like a there's different levels there's like a file sort of per site file storage

59:47 thing that's tied to your user and then there's like an embedded SQLite like thing

59:51 I mean if you had something like SQL model or some other proper ORM that would

59:57 let you connect to query that I suspect that could probably be built pretty

01:00:02 easily with a interoperability layer to figure out just how to translate that

01:00:07 over to JavaScript but is it what do you think you know more than I do there are

01:00:11 lots of possibilities and scenarios of you know using what the browser provides you

01:00:16 like local storage or small instances of databases and stuff like that so that is

01:00:22 almost shipped and default with all the browsers there are interesting projects

01:00:27 well at least one that I've seen like Google project where from Google from the

01:00:33 Chrome team that is experimenting with scenarios where you can actually allow apps

01:00:39 to access your file system or other resources native resources right like and

01:00:44 it's it goes through a process of approval but you can mount directories

01:00:49 and use them from your browser as a local mount those are also very interesting

01:00:55 scenarios that could open up a lot of different ways of interacting with

01:00:59 PyScript maybe it would mean you can actually develop your PyScript app directly

01:01:04 from your local machine and then serve it on the browser real time or your

01:01:09 app could write files or do your models or computation of the browser and

01:01:13 then write results your local files there's a lot that can be explored my

01:01:19 security question outside of the sandbox let's not stress about it we already

01:01:23 have had WebAssembly for a long time is this py env section here where you

01:01:28 can say go find this file right and I'm thinking of my website which has

01:01:32 a static files folder section where I might put this because that needs to

01:01:37 be served up as effectively a static file to the front end but I've got my

01:01:41 app py my various views and settings dot json and like if I put too many

01:01:47 dot dot slashes there am I going to be able to get to other stuff or is it

01:01:50 okay suppose this folder this file lives in static slash antigravity dot

01:01:56 html but the rest of my app is like one directory up from that could I say

01:02:03 my path to my module is dot dot dot slash app dot pi and then maybe read

01:02:07 like some right source code with like a token that I put in there that I

01:02:11 shouldn't have put in there but then now it's public yeah relative paths

01:02:14 should work just fine there's also I think with PyScript the distinction

01:02:20 between development time and deployment time or bundling time is a little

01:02:25 more highlighted like as a developer I'd love to have those relative paths

01:02:31 and explore and have full access to a lot of libraries but when I deploy

01:02:38 I bundle my application one of the things that we are very interested in

01:02:42 developing more is we should bundle that as one thing and paths should be

01:02:48 absolute so there is no issues with what you're saying we could bundle the

01:02:53 interpreter and your dependencies so that we can optimize size remove dependencies

01:02:59 that you're not using so the loading time is smaller basically three shake

01:03:04 like a lot of JavaScript libraries do so there are definitely patterns to

01:03:08 explore in that scenario soon yeah okay yeah you definitely don't want to

01:03:12 go dot dot slash app because somebody could then inject that but yeah it's

01:03:17 interesting I'll be cool to see what you'll do there but definitely that's

01:03:20 the only thing that's coming to mind like hmm I wonder what's gonna happen

01:03:23 there oh so but if you do dot dot app you're still like it's basically on you

01:03:28 to define what you're actually serving as your static file server if it's

01:03:33 not accessible as a static file already this will just 404 yeah okay then

01:03:38 right yeah then then flask pyramid friends have it covered yeah yeah exactly

01:03:42 now it's just you're like it's not our responsibility but you shouldn't be

01:03:46 allowing you know slash static slash dot slash app dot pi being served anyway

01:03:51 right right okay cool the other thing is one of the things that Steve Dower

01:03:56 talked about recently is that they started enable the real the full c python

01:04:03 to being built within mscripten WebAssembly targets is this of interest

01:04:09 to you all does this supersede Pyiodide's version in some way is what Pyiodide's

01:04:16 version actually is the Pyodide team and the c python team are collaborating

01:04:22 on making the two making Pyodide basically use that as a baseline python

01:04:28 that actually would be very helpful to the Pyodide team as well they would

01:04:33 have way less things to maintain they can just delegate to improvements and

01:04:38 optimizations that the c python core team is they're doing and can focus

01:04:43 on the additional features of Pyodide so that actually we had a few they're

01:04:49 building in the WebAssembly version because it didn't exist that's probably

01:04:52 not what they want to do right exactly yes yes yeah yeah okay their real

01:04:56 innovation I think in addition to just getting the WebAssembly thing working

01:04:59 is like how do you bring these important C mixed C libraries in like numpy

01:05:06 and such to the browser that otherwise wouldn't just drop in as you know

01:05:11 python stuff running on top of the interpreter right that seems to be the

01:05:15 most important thing that they brought to the table right not discounting

01:05:20 that there was not a WebAssembly version and they made that also happen

01:05:24 right like that's also super important but well yeah I guess what makes them more

01:05:28 distinct of all the other attempts is that they are really focused on making

01:05:31 sure that data science libraries work in this situation yes I think that

01:05:35 is one of the main things that made high dive successful because a lot of

01:05:41 times you would support just the language itself and then when you want to

01:05:45 support more complex use cases like C dependencies you are too far in the

01:05:50 process of your implementation and then you are like oh now we have to rewrite

01:05:54 half of the code to refactor to account for a lot of the complexities yeah

01:05:58 we got to backfill it so we have support for all these things how are we

01:06:02 going to write our own numpy now or something right yeah and C extensions

01:06:05 are always the place where most projects have a hard time right like historically

01:06:10 the different implementations of python and .NET or pipi or others C extensions

01:06:17 has always been like the trouble kid it definitely is it's also tricky for

01:06:22 thinking about reference counting versus other collection cleanup tie yeah

01:06:27 it's an important boundary to be aware of but it's also really been a lot

01:06:31 all right final final thing let's just wrap this up with what's next where

01:06:35 you going so I think I hinted at a lot of those I think the main thing for

01:06:41 us in the immediate future is really to work with the community and build up

01:06:46 more of that side of things and then also work on documentation to put out

01:06:52 the vision and what's next there are a bunch of things that are really interesting

01:06:57 that we will be looking at a reactive layer or components to interact with

01:07:03 each other and notify each other the story around data and how does working

01:07:09 with data look like in PyScript a lot of development around the possibilities

01:07:14 of using PyScript in a peer-to-peer or web three sort of scenario right what

01:07:21 can we make to support applications talking to each other directly or you

01:07:27 know using a mode where you work offline and online and you can you know

01:07:31 make the experience better right like a little bit of a progressive web type

01:07:35 of thing yeah yeah yeah I'd be super excited to see that come along yeah

01:07:39 honestly one of the difficulties with this project is that it breaks so many

01:07:45 patterns that we are used to you know both like oh I'm running my thing on

01:07:49 my machine or in a server or I'm doing a web it means okay it means that I always

01:07:54 have a server and a client side they have the network in between now we're

01:08:00 shifting the paradigms and a lot of things are new so we can explore right

01:08:05 the other thing that we're looking at well better support for the optimization

01:08:11 loading times all of those things how can you can you hold state of your

01:08:16 application so basically as it's it's it's running etc or if you just have

01:08:21 a notebook like sort of workflow how can you save the state of your PyScript

01:08:26 app and share with others and they can start from the same point you were

01:08:31 okay those are all great things to be working towards is this tying in any way

01:08:36 to Jupyter Lite and it's got similar goals I'm not sure if it has any similar

01:08:41 foundations or anything maybe I'm very familiar with the Jupyter folks I work

01:08:47 together with many of the core developers and historically Jupyter Lite is a

01:08:52 great project that basically implements the Jupyter notebooks using Pyodide

01:08:58 as a runtime or a shell yeah so it's not that far out of being maybe in a

01:09:04 similar space but right yeah it's similar in that sense that it ties right into

01:09:11 the Jupyter experience so it has it's locked into the notebook flow and altering

01:09:17 notebooks and stuff like that where PyScript is more has a larger scope and it's

01:09:24 really to author applications sure a little different okay very interesting

01:09:28 all right well congratulations this seems like a pretty promising project

01:09:32 and I know there's a lot of interest in it let me close it out with a comment from the

01:09:35 audience Andre Muller said I tried Jinja the Jinja wheel just straight up

01:09:42 with PyScript and it works straight away like no changes so that's kind

01:09:47 of meta actually that's Jinja within PyScript within HTML love it yeah awesome

01:09:52 all right well let me ask you the final two questions before we get out of here

01:09:56 if you're gonna write some Python code what editor are you doing using these

01:10:00 days I'm usually a mix between VS Code or PyCharm all right cool yeah both good

01:10:06 and notable PyPI package or you know some other kind of maybe it doesn't come

01:10:11 quite off PyPI maybe it comes off a CDN these days PyScript obviously what do you

01:10:16 want to give a shout out to gave a lot of shout outs to Pyodide once again

01:10:20 it's a great project I think I use notebooks and the whole Jupyter ecosystem

01:10:27 a lot as well the whole scientific stack and a lot of the things that are

01:10:31 around you know the many interesting projects like you know NumPy Pandas

01:10:37 Dask the Bokeh Numba a lot of that ecosystem is really in my day-to-day kind of

01:10:44 workflow yeah fantastic yeah well cool all right well once again congratulations

01:10:49 on all the interest and excitement it's it's really taken off the last couple

01:10:54 weeks so thanks for coming on the show and talking about it thank you so much

01:10:57 for the opportunity I had a great time chatting about it yeah you bet and

01:11:01 final call action people want to get started what do they do great question

01:11:04 go to pyscript.net check the website we have links to the repo and to the

01:11:09 you have very interesting install steps here right and it says no you don't

01:11:15 install yes we hope people would click and actually see the easter egg which was

01:11:20 good and yeah you know we want to really want to be inclusive community so if you have

01:11:25 questions or have you want to report bugs or just ask where you can help

01:11:30 just reach out either on on twitter or reach out on the repo open bugs there

01:11:35 we are in the next you should expect more documentation on community engagement

01:11:41 having a discussions group where people can actually ask questions more easily

01:11:46 we're evaluating starting bi-weekly or something like that community call

01:11:50 where we just are there for the community to ask questions live on a zoom

01:11:54 or something like this so be patient we're getting there to support our community

01:11:59 and allow people to actually contribute back well very exciting thanks for

01:12:04 doing it thanks for being here thank you this has been another episode of

01:12:09 talk python to me thank you to our sponsors be sure to check out what they're

01:12:13 offering it really helps support the show starting a business is hard Microsoft for

01:12:18 startups founders hub provides all founders at any stage with free resources

01:12:23 and connections to solve startup challenges apply for free today at talk python.fm

01:12:29 slash founders hub want to level up your python we have one of the largest

01:12:33 catalogs of python video courses over at talk python our content ranges from

01:12:38 true beginners to deeply advanced topics like memory and async and best of

01:12:42 all there's not a subscription in sight check it out for yourself at training.talkpython.fm

01:12:47 be sure to subscribe to the show open your favorite podcast app and search

01:12:51 for python we should be right at the top you can also find the iTunes feed

01:12:55 at /itunes the Google Play feed at /play and the direct RSS feed at

01:13:00 /rss on talkpython.fm we're live streaming most of our recordings these days

01:13:06 if you want to be part of the show and have your comments featured on the air

01:13:09 be sure to subscribe to our YouTube channel at talkpython.fm/youtube

01:13:13 this is your host Michael Kennedy thanks so much for listening I really appreciate it

01:13:18 now get out there and write and write some Python code and write some and write some

01:13:21 things like that.

01:13:22 and write some and write some and write some things like that.

01:13:26 And I'll see you next time.

01:13:27 I'll see you next time.

01:13:28 Bye.

01:13:28 Bye.

01:13:28 Bye.

01:13:29 Bye.

01:13:29 Bye.

01:13:30 Bye.

01:13:30 Bye.

01:13:31 Bye.

01:13:31 Bye.

01:13:32 Bye.

01:13:32 Bye.

01:13:33 Bye.

01:13:33 Bye.

01:13:33 Bye.

01:13:33 Bye.

01:13:33 Bye.

01:13:33 Bye.

01:13:34 Bye.

01:13:34 Bye.

01:13:35 Bye.

01:13:35 Bye.

01:13:36 Bye.

01:13:36 you you Thank you.

01:13:39 Thank you.

Back to show page
Talk Python's Mastodon Michael Kennedy's Mastodon