Latest / Talk Python To Me / #212: Python in Web Assembly with Pyodide
Transcript
- 0:00It's been said that JavaScript is the assembly language of the web,
- 0:03but should you be required to write an assembly language or even JavaScript if you don't want to?
- 0:08Most platforms have a dizzying array of options for programming them.
- 0:12Not the front-end web world, but that tide may be turning,
- 0:15and WebAssembly could be the key to making it happen.
- 0:17With WebAssembly, we have a new compilation target for web browsers,
- 0:21and Michael Dropboom from Mozilla and his team have decided to help bring
- 0:25the Python scientific stack to the front-end world with Pyodide.
- 0:29Dive into Pyodide on this episode, 212, of Talk Python To Me, recorded April 23, 2019.
- 0:36Welcome to Talk Python To Me, a weekly podcast on Python,
- 0:52the language, the libraries, the ecosystem, and the personalities.
- 0:55This is your host, Michael Kennedy.
- 0:58Follow me on Twitter, where I'm @mkennedy.
- 1:00Keep up with the show and listen to past episodes at talkpython.fm,
- 1:03and follow the show on Twitter via at Talk Python.
- 1:06This episode is brought to you by Microsoft.
- 1:08Be sure to check out what they're offering during their segments.
- 1:11It really helps support the show.
- 1:13Michael, welcome to Talk Python.
- 1:16Thanks. It's good to be here. Thanks for inviting me.
- 1:18Oh, you have such an interesting topic and thing that you've been working on.
- 1:21I was really excited when I heard about Pyodide a little bit, I don't know, maybe six months ago
- 1:26or when I first heard about it and stuff.
- 1:28And I was like, oh, this has some real possibilities.
- 1:30So I'm really excited to have you here to dig into that.
- 1:33Cool.
- 1:33Yeah.
- 1:33Now, before we do get into that, let's start at the beginning.
- 1:36Let's start with your story.
- 1:37How did you get into programming in Python?
- 1:39So I've been programming almost as long as I can remember.
- 1:42I think my parents brought home like an IBM XT sometime in the mid-80s.
- 1:47And I learned, you know, basic on that as one does.
- 1:50And just have been programming ever since.
- 1:53I found Python, I think, in 1996 while I was at university.
- 1:56And I sort of used it secretly in the background to like prototype my assignments that I had to
- 2:02write in other languages.
- 2:03I would kind of write these quick little hacks as I'm learning to program in Python because it
- 2:07was a lot easier for me.
- 2:09And then once I had figured out the problem, I'll convert it to LIS.
- 2:13I can now solve the syntax problem to make this happen over here, right?
- 2:16Exactly.
- 2:17Yeah.
- 2:17What languages were you using?
- 2:18There was a lot of LIS where I went to school and as well as Java and ML was a big thing then,
- 2:25which, you know, sort of grew into Hamill and that family of languages.
- 2:28Yeah.
- 2:29My first CS language that I only took a couple of CS classes as a minor type of thing,
- 2:34but my first one was in Scheme, which is a derivative of LISP, right?
- 2:39And I felt that it was both very mind shifting and very interesting and also super not useful.
- 2:46Like what was your feeling of studying LISP early on?
- 2:49Like I can't go build anything with this.
- 2:51What is this crazy language?
- 2:53Yeah, it definitely is kind of mind bending.
- 2:56And, you know, I think it enforces a lot of good habits, like functional programming ideas
- 3:01that you can bring into any language that are probably good habits to have.
- 3:04But yeah, like you say, it's not always the most practical.
- 3:08I know this is a question that usually is at the end of your show, but I use Emacs.
- 3:13And so occasionally to write Emacs extensions, I'll bring out LISP.
- 3:17And what's fascinating about it is Emacs is basically built by monkey patching everything else.
- 3:24That's Emacs extensions, basically monkey patching is the functional thing that you do,
- 3:30which I find interesting.
- 3:31That is interesting.
- 3:32Wow.
- 3:32I guess tends to happen in LISP a lot.
- 3:35Well, that's the only big LISP code I'm really familiar with.
- 3:38Yeah, Emacs is definitely one of the bigger projects.
- 3:40Quite, quite interesting.
- 3:41Cool.
- 3:42Okay, so you sort of used it.
- 3:44You got into it pretty early, right?
- 3:45Like, what is that?
- 3:46Four or five years into the existence of Python, which for Python, you know, it grew grassroots.
- 3:53It wasn't like busted on the scene by Microsoft or Apple or whoever, right?
- 3:57That's pretty early.
- 3:57Yeah, I went to my first Python conference in 2001.
- 4:00And at that point, I don't remember the exact number, but I would guess it was maybe around
- 4:05200 people, not much larger than that.
- 4:07It was one track.
- 4:08Everybody could fit in one room.
- 4:10It was small enough that as a grad student, I was able to just walk up to Guido and have
- 4:15a talk with him because there wasn't that many people demanding his attention.
- 4:19And of course, now you go to PyCon and, you know, forget anything like that happening.
- 4:23There's just thousands of people.
- 4:24And yeah, it's completely crazy.
- 4:25Yeah.
- 4:26I mean, it's really fun to see how big the community has grown.
- 4:29On the other hand, I do miss the days of the sort of smaller conferences where you feel
- 4:32like you got a hold of it and you feel like you got a sense of seeing a lot of the stuff.
- 4:36But yeah, these are good problems to have, I guess.
- 4:38I guess they are.
- 4:39How does it feel to do Python now versus then?
- 4:43It's got to be kind of different with pip install, anti-gravity and all that.
- 4:47Yeah, I think definitely having good package management means you're no longer compelled
- 4:54to like bring everything into your projects in the same way.
- 4:57So I used to be the developer on Matplotlib.
- 5:00And one of its sort of, I guess, technical debt, for lack of a better word, is the fact
- 5:05that for the longest time it was if someone had a great idea for a new plot type, we'd just
- 5:09say, yeah, let's include it in Matplotlib.
- 5:11Because the alternative was forcing all the users to install a bunch of packages, which
- 5:16was really hard at the time.
- 5:17So we would make this one really big package.
- 5:20And, you know, in hindsight, that's not the greatest thing.
- 5:23It means a lot of code for the core developers of that project to maintain.
- 5:27So it is nice that we live in this world now where we can have lots of little packages that
- 5:31interact.
- 5:31And that's not a huge burden on the user as it once was.
- 5:35Yeah, that's pretty interesting.
- 5:36I mean, maybe it would have been better to have a bunch of little Matplotlib dash extensions
- 5:41that you include in your requirements files if you want to do these kind of graphs and stuff.
- 5:45And you could have kept it a little more distributed in terms of support.
- 5:48But yeah, it's the right architecture and patterns for the right time, right?
- 5:53And that's what you needed, yeah?
- 5:54Yeah.
- 5:54Cool.
- 5:54So you both work at a cool web company and do data science.
- 5:58So you kind of do both of the things that Python is really good at simultaneously, right?
- 6:03Tell us about that.
- 6:04Yeah, so I'm a data engineer at Mozilla.
- 6:06I've been there about a year and a half.
- 6:07And I work on the team that manages the telemetry that comes from our products.
- 6:12So from Firefox on desktop and on Android and iOS and all these things.
- 6:17You know, and the telemetry goes into improving the product.
- 6:20It helps us discover when things are going wrong, whether things are getting better with changes
- 6:24or worse with changes and things like that.
- 6:26And so there's a whole team that manages collecting that data, ingesting that data, and then providing
- 6:31ways for people to analyze it at the end of the day.
- 6:34And what's really exciting about how they do that at Mozilla is we have this document called
- 6:39our Lean Data Practices, where we try really hard to not collect anything that we don't
- 6:44need to collect, not collect anything that will invade people's privacy.
- 6:48We really are just collecting what we need in order to improve the product.
- 6:52And so it's really nice to come at it from that point of view, not just to sort of snarf
- 6:55it all up and see what we can do later, but to really think upfront, do we need to do this
- 7:00and do we need to collect this?
- 7:01Yeah, that's super cool.
- 7:02Like maybe you had for a while, Firefox had the address bar and then like a search box,
- 7:07right?
- 7:08Most of the browsers have given up on this idea.
- 7:10But you could tell that from telemetry, right?
- 7:12How people are using each part and so on, yeah?
- 7:14Exactly.
- 7:15Yeah.
- 7:15We're able to sort of see how the search bar is getting used even now that it's a unified
- 7:19thing.
- 7:19It's a really fun place to work.
- 7:21The engineering talent there is just beyond anything I've ever had the privilege of working
- 7:26with.
- 7:27So I can imagine that it's super awesome.
- 7:28I'm personally a big fan of Firefox.
- 7:30I generally just use Firefox if at all possible.
- 7:33And it frustrates me to no end where I go to places and they're like, this page is only
- 7:38available on Chrome or this site only streams this video on Safari.
- 7:43And you know there's no good reason for it other than they're just lazy to do like the
- 7:48tiny bit of effort to make it work, right?
- 7:50Yeah.
- 7:51It's unfortunate.
- 7:52You know, I think one of Firefox's biggest challenges is that unfortunately there's like
- 7:58a network or a snowball effect, right?
- 8:00It's that the more websites that don't work on Firefox, the fewer people are going to use
- 8:04it.
- 8:05And therefore, the fewer websites are going to work on Firefox.
- 8:07And so trying to break out of that cycle is sort of a constant battle for us that we're
- 8:13tackling on a number of fronts.
- 8:14Props to you guys.
- 8:15You're doing great stuff, keeping the web open.
- 8:17I really am a big fan of Mozilla.
- 8:19And I guess our topic today is just one more reason why.
- 8:23Cool.
- 8:23Yeah, absolutely.
- 8:23So we're going to talk about WebAssembly and Pyodide.
- 8:27But I think it maybe makes sense to just sort of lay out a little bit of the history of like
- 8:34what even led to WebAs, not necessarily what led to WebAssembly, but like what preceded WebAssembly,
- 8:40you know?
- 8:40Sure.
- 8:41Maybe I'll take it up to WebAssembly and you can take it from there.
- 8:43So we have way back in, I don't know, 1995, browsers were things that looked at documents
- 8:49and people imagine like what if they could do more than just show documents, right?
- 8:53So Netscape, that company that used to exist, I also was a fan of them.
- 8:59Guys at Netscape came up with JavaScript and it was named JavaScript not because it had anything
- 9:03to do Java, but because Java was cool and hot.
- 9:05So this is the scripty cool language.
- 9:07In 10 days, like it was created in 10 days, start to finish and shipped in Netscape Navigator,
- 9:13like three months later or something.
- 9:15And boom, it oddly becomes the most popular language in the world and sort of becomes like
- 9:20this assembly language of the internet or maybe C, I don't know how you think about it, like
- 9:25just the base language of the internet, right?
- 9:29And then some other projects came along, ASM, ASM, ASM.JS, and some other ones show that you
- 9:35can take C code, compile it down to JavaScript and do incredible stuff.
- 9:40Like there's a super, super funny video by Gary Barnhart called The Birth and Death of JavaScript.
- 9:46Have you seen this video?
- 9:47Yeah, it's fantastic.
- 9:48It's like 15 minutes of beautiful history, but humor all mixed together.
- 9:53It's really, really insightful.
- 9:55And basically in there, he shows things like, I don't remember the exact one, like Chrome
- 10:00running in JavaScript inside of Firefox or the other way around, just like really interesting
- 10:04stuff like C games in the browser and all that stuff is amazing.
- 10:08So it really like showed the possibility of, you know, like the web really can be, and JavaScript
- 10:15can be the foundation of not just jQuery and Angular, but Doom or Quake or Firefox, right?
- 10:24Like incredible power.
- 10:26But it doesn't make a lot of sense to compile stuff to JavaScript, to ship it down, to then
- 10:31reinterpret it, to like then compile it and JIT it and run it.
- 10:34Like, wouldn't it be better if there was a binary way to like compile for the web, right?
- 10:40And so that's my, I guess my introduction to this idea of WebAssembly, right?
- 10:45Yeah, that's a great little history.
- 10:47I mean, most of that predates my coming to WebAssembly.
- 10:50I've only been using WebAssembly for about a year and a half when this whole project started.
- 10:54So fortunately, Mozilla has a lot of people who do work on WebAssembly and have web data from the
- 10:59beginning.
- 10:59So it's really nice.
- 11:00Did it originate with Mozilla?
- 11:01It did.
- 11:02Yeah.
- 11:03I felt like Rust and WebAssembly and all that stuff kind of came from you guys.
- 11:07Exactly.
- 11:07Yeah.
- 11:08It originated at Mozilla, but it is definitely an open standard that all the browsers are supporting
- 11:13and all that stuff.
- 11:13Yeah.
- 11:14Super cool.
- 11:14So, I mean, maybe give the elevator pitch of like, what is WebAssembly for folks who don't
- 11:20necessarily know?
- 11:21Yeah.
- 11:21So it's basically a binary format.
- 11:23It's designed to be something that your compiler writes to.
- 11:28It's not something you would ever write by hand or people do.
- 11:31It's a target for something like a C compiler or a Fortran compiler or a Rust compiler, right?
- 11:36Any of these compiled languages.
- 11:38And when that gets shipped to your browser, the browser then converts that into native machine
- 11:44code that runs on your machine.
- 11:45But it's also running inside of the same browser sandbox that runs your JavaScript.
- 11:49So it has the same sort of security space and constraints as JavaScript.
- 11:54Right.
- 11:55One of the concerns people have is like, well, JavaScript is safe because it's this sandbox
- 11:58thing and it only has so much in the language.
- 12:00If you start running arbitrary binary code, all bets are off.
- 12:04But it's not just like, here's some machine instructions.
- 12:06It's, oh, here's a binary thing that runs in the WebAssembly world, right?
- 12:10Yeah.
- 12:11Yeah.
- 12:12So these are details I don't know too much about.
- 12:14But they definitely is making all these assurances that the sort of typical things you can do
- 12:21in C that become security flaws, you cannot do in WebAssembly.
- 12:24Or if you do them, you don't break out of the browser, right?
- 12:28Right.
- 12:28You just get an exception or something, right?
- 12:30Exactly.
- 12:30Yeah.
- 12:30Cool.
- 12:31Dan Callahan, another Mozilla person, gave a pretty interesting call to action around WebAssembly
- 12:38last year in one of the PyCon keynotes at US PyCon.
- 12:41Were you there for that?
- 12:43I wasn't there.
- 12:44And actually, what's interesting about that is I had already been working on PyDyde for
- 12:48a few months when he gave that talk.
- 12:50And he and I were not aware of each other at all.
- 12:52It just sort of explains how big a place Mozilla is.
- 12:54Yeah, yeah, yeah.
- 12:55For sure.
- 12:55You know, nobody's fault at either end at all.
- 12:58And you guys also have like PyPyJS, which I don't think is active anymore.
- 13:02But there's like a lot of these little flowers blooming in that world, right?
- 13:05Exactly.
- 13:06Exactly.
- 13:07And so it was really cool to see his talk and sort of realize we were thinking along the
- 13:11same lines.
- 13:12And we sort of check in with each other periodically on what's going on there, which is great.
- 13:16That's cool.
- 13:17So I guess the quick summary of that, I'll link to the whole half hour presentation.
- 13:21But it was like, Python is amazing.
- 13:22We love Python.
- 13:23But the web is one of the most important places where code runs right now.
- 13:28And running in the browser, Python is sadly absent for the most part.
- 13:33I mean, we have Sculpt and a few of those other things like PyPyJS.
- 13:36But they're always in some kind of like seven caveats and some little sliver of use case, right?
- 13:41What I was hoping for when I watched this was like, okay, this is the buildup.
- 13:45Please let this be an announcement.
- 13:47Like, please let this be an announcement involving WebAssembly.
- 13:49And it just turned out to be a community.
- 13:51We need to work on this.
- 13:52And I thought it was really awesome when I saw Pyodide come out.
- 13:54I'm like, oh my gosh, they actually were working on something.
- 13:56But I guess since you didn't know about each other, you couldn't really.
- 13:59It's not like you could do the big reveal of like, and Pyodide's a good start or something, right?
- 14:03Yeah, yeah.
- 14:04It would have been a little bit of a different talk, I guess.
- 14:07Yeah.
- 14:07But still, I mean, the points he makes are great points in terms of, I think, you know,
- 14:12the web is where so much computing happens these days that if you aren't playing in that space,
- 14:17you know, you are becoming limited.
- 14:19And yeah, and like you say, there's been a bunch of other projects to bring Python to the web browser.
- 14:24Yeah.
- 14:24The thing that makes Pyodide a little unique is that it tries to be as close to upstream as possible.
- 14:30So it's using upstream CPython, the upstream versions of NumPy and SciPy and all these things,
- 14:35and tries to change them as little as possible so that the effort on those projects contributes
- 14:40into our effort directly rather than reinventing and then constantly having to keep up with that,
- 14:47right?
- 14:47Right.
- 14:47Yeah.
- 14:47Like we spoke earlier, there's so much benefit to having all these packages.
- 14:51And every day there's just more to grow upon.
- 14:54But if your job is like, we have to have our own copy and implementation of Matplotlib in JavaScript,
- 14:59like nobody wants to do that job, right?
- 15:03Yeah.
- 15:03That's just so many years of effort that I think, you know, it would always be a poor imitation of the real thing, right?
- 15:09So it's...
- 15:09Yeah, it'd also be behind as well.
- 15:11Like TensorFlow came out, but we haven't written the JavaScript TensorFlow yet, so forget that or whatever, you know?
- 15:16Something like that.
- 15:17Right.
- 15:18And you see this a little bit even with like PyPy.
- 15:20I mean, PyPy is incredibly impressive.
- 15:22Really cool project.
- 15:23But they're still at the 3.6 level of syntax because they're just always sort of following.
- 15:29It's just sort of in the nature of what they're doing.
- 15:31And I don't mean that as criticism.
- 15:32But if you aren't tracking the leader, you're always going to be a little bit behind, right?
- 15:37Right.
- 15:37Right.
- 15:37Right.
- 15:38So I guess before we move off of just WebAssembly on its own, I can dig into Pyodide.
- 15:43How well supported is it?
- 15:45Like WebAssembly sounds like new and futuristic.
- 15:47How well supported is this?
- 15:49It's in all the major browsers, in the stable versions of all the major browsers right now.
- 15:54So it's pretty easy to rely on it.
- 15:57It's at what they're calling sort of this MVP level of WebAssembly.
- 16:00They sort of decided which features were the most critical, and that's everywhere.
- 16:05Then there's a bunch of ways in which WebAssembly is already planning to be improved that will eventually trickle down to browsers.
- 16:13So things like threading are newer features that are coming down.
- 16:17And garbage collection is going to be added.
- 16:19So there's a bunch of things that are coming that you can't rely on yet.
- 16:23But for the core stuff, and actually for most of the stuff we needed for Pyodide, it's already there.
- 16:29This portion of Talk Python is sponsored by Microsoft and Visual Studio Code.
- 16:33Visual Studio Code is a free, open-source, and lightweight code editor that runs on Mac, Linux, and Windows with rich Python support.
- 16:40Download Visual Studio Code and install the Python extension to get coding with support for tools you love like Jupyter, Black Formatting, Pilot, pytest, and more.
- 16:48And just announced this month, you can now work with remote Python code bases using the new Visual Studio Code remote extensions.
- 16:55Use the full power of Visual Studio Code when coding in containers, in Windows subsystem for Linux, and over SSH connections.
- 17:03Yep, that's right.
- 17:04Autocompletions, debugging, the terminal, source control, your favorite extensions.
- 17:08Everything works just right in the remote environment.
- 17:10Get started with Visual Studio Code now at talkpython.fm/Microsoft.
- 17:17So it looks like I opened up Can I Use, and I'll put a link to the WebAssembly report for Can I Use, which talks about what browser support what.
- 17:25So it looks like Edge, Firefox, Chrome, Safari, Opera, all those desktops just supported.
- 17:30iOS on Safari supports it, and Android, Chrome, and Firefox there supported.
- 17:36That kind of sounds like 99%, right?
- 17:39Yeah, yeah.
- 17:39I'm excited to see things like threading and stuff coming as well.
- 17:42There's a possibility for more interesting stuff to come along.
- 17:46Yeah.
- 17:46Cool.
- 17:47All right.
- 17:47So that brings us to Pyodide.
- 17:49Now, there's a couple of interesting projects that are saying WebAssembly plus other language plus interesting runtime means something in the browser.
- 17:58What did it mean for you guys?
- 18:00The reason Pyodide started is when I arrived at Mozilla, Hamilton, Ulmer, and Brendan Collar, and also William LaChanze and Tian Brooks were working on this sort of internal skunkworks project for data science at Mozilla.
- 18:13The idea was data scientists at Mozilla were using a lot of things like Jupyter Notebooks, or there's a tool called Databricks that's very similar.
- 18:23And the problem with these tools was that sharing them is harder than maybe it needs to be because you have a front end on the web, but your actual computation is happening somewhere else.
- 18:35It might be on the same machine, but often it's a remote kernel somewhere else.
- 18:39Right.
- 18:39So you need maybe access to that compute cluster, or if you want to run it locally, you've got to pip install a bunch of stuff, right?
- 18:46You're like, oh, you can run this.
- 18:47It's easy to run, except for you have to now set up a virtual environment.
- 18:50You probably should use Minicon.
- 18:52And here's your stuff.
- 18:53You're like, whoa, whoa, whoa.
- 18:53I just want to look at the report.
- 18:55What is this, right?
- 18:55Like, for a lot of folks, that's super overwhelming.
- 18:57Yeah, your choices are generally, you either require people to install, which, like you say, it's very difficult, or you have to sort of pay for some cloud computing resources somehow.
- 19:08And so if you were to put that on, say, a public website to share your data science, you might end up with an unexpectedly huge bill, perhaps, right?
- 19:17Right.
- 19:17The worst case thing happens, exactly what you want, is a lot of people get interested in it.
- 19:21Exactly.
- 19:22Exactly.
- 19:22And so the idea with iodide was, let's move all the computation into the browser, and then the computation's all happening at the edges in people's clients, right?
- 19:30Right.
- 19:31And to be clear for people, it's iodide, not pyodide, right?
- 19:34Exactly.
- 19:34This is another project.
- 19:36Yeah, okay.
- 19:36Yeah.
- 19:37Yeah.
- 19:37So that's iodide.
- 19:39It's sort of this data science user interface front end, right?
- 19:42And the first iteration of that, of course, was using JavaScript to do the data science.
- 19:49And you start to realize, well, JavaScript's not a great language for that.
- 19:53There's not this sort of mature ecosystem of libraries and tools you can just pull off the shelf like there is in Python or R or Julia, right?
- 20:01And then there's even some kind of really nice to have language features that JavaScript doesn't have.
- 20:07Like it doesn't have operator overloading, which is really handy when you're doing a lot of numerical computation.
- 20:12Right.
- 20:12And numbers are weird, right?
- 20:14Like you can't have true integers, for example, and other stuff.
- 20:17Yeah.
- 20:17Exactly.
- 20:18And there's a lot of movement in that space trying to make that all better.
- 20:22But that's kind of a big lift.
- 20:24And definitely the iodide project wants to encourage that.
- 20:26And we're working on that kind of in one thread.
- 20:29But in the meantime, we thought, why don't we try and come to data scientists where they are, which is in Python, and somehow bring Python to the browser.
- 20:38And this seemed like a very crazy idea to me when it was first raised.
- 20:42But fortunately, like I said, at Mozilla, we have a bunch of WebAssembly experts who got on a meeting with us and said, it can't be that hard.
- 20:50Other people have done things much more difficult than that.
- 20:53So why don't you just try it?
- 20:54So I went off and found this project by a GitHub user named DGM called cPython Emscripten, which had done a lot of the initial footwork on this.
- 21:06And starting with that, was able to get something going in probably a couple weeks.
- 21:11That's kind of like that 80% in 20 weeks.
- 21:13And then the remaining 20% is, sorry, in two weeks.
- 21:17And then the remaining 20% takes forever.
- 21:18But certainly getting to the proof of concept was pretty quick.
- 21:22And realizing, hey, you can actually compile the real cPython interpreter and get that to run and then have the real NumPy loading in.
- 21:29And all those things actually do kind of work.
- 21:31It was pretty exciting.
- 21:32Yeah, that's pretty amazing.
- 21:34And how much of the cPython, like how big is the cPython.wasm or whatever it's called?
- 21:41Like the core runtime bits you got to take down before you can start doing stuff, just roughly.
- 21:46Yeah, roughly.
- 21:47So I'm actually pulling up those numbers because they change all the time.
- 21:50It's about 20 megabytes for Python core.
- 21:53And then, of course, the libraries you're going to pull in will add to that.
- 21:57So NumPy is around 8 megabytes.
- 21:59It goes from there.
- 22:01But one of the things that PyDyde does is it only downloads the libraries you actually import.
- 22:06I see.
- 22:06If you don't import Matplotlib or NumPy, like those are not things it has to go hit, right?
- 22:11Exactly.
- 22:11And also your browser will cache those things.
- 22:15So the first time you'll pay the network penalty.
- 22:18But once it's been done once, it's on your machine.
- 22:20And it will actually recompile the WebAssembly each time, but it doesn't actually have to download it again.
- 22:25Cool.
- 22:26So that seems like a really good opportunity for a CDN.
- 22:29And the fewer CDNs that host this, the better, right?
- 22:32Like the more it is shared, the better, honestly.
- 22:36You know, when I think about these types of things, one thing when I speak to folks like you, because you actually are within a sphere of influence that could possibly have some kind of difference.
- 22:45It's cool that you can put that on a CDN and you can download it and make it go.
- 22:49But, you know, what if like JavaScript is baked into Firefox?
- 22:55What if CPython in WebAssembly was part of Firefox?
- 23:01Like when I update Firefox, I get that latest runtime and I don't have to download it ever.
- 23:06I don't know if it's a silly idea or not.
- 23:08I mean, I remember from, you know, probably at least 20 years ago, people have talked about JavaScript's not a great language.
- 23:15Let's put a better language in the browser instead, right?
- 23:17That's been a theme for a very long time.
- 23:20And what's interesting is now that we have WebAssembly, we sort of no longer have to pick one.
- 23:25Which is a nice situation to be in.
- 23:27We can get any of them in there.
- 23:29Are there ways that it could be done like more efficiently or more conveniently?
- 23:33Certainly.
- 23:33Like I think, you know, maybe there'll be some like web extension you download that gives you languages so that it just kind of will always update those in the background and you don't have to worry about this kind of stuff.
- 23:44There's ways that you could make it almost like a browser just with a little bit of extra added to make.
- 23:49Yeah, I'm not nearly proposing Python in Firefox.
- 23:52I'm proposing Firefox come with these preloaded or like you say in the background, like preload the latest one or something.
- 23:58And then you could have Python.
- 24:00You could have C#.
- 24:01You could have all the languages that are like building these runtimes in WebAssembly and make them available.
- 24:07And just I think that would be super cool, actually.
- 24:10Yeah, it definitely would open up the possibility for, say, writing web applications using this technology.
- 24:17So one of the things I do warn people about Pyodide is the thing that's cool about Pyodide is you can actually see the Python in your web browser and run it there, which is great for the data science use case.
- 24:28Right.
- 24:29But if you don't have a use case where you need to show people the code, this is probably not how you want to write your web app.
- 24:36Yeah, for sure.
- 24:37You probably want to stay in a JavaScript world, which is a lot more efficient and a lot faster and all these things, right?
- 24:42Yeah, so Pyodide is very much focused on basically what you do with Jupyter notebooks, but make that execution happen on the client side in the browser, not connected back to a Docker thing or some kernel elsewhere, right?
- 24:56Like that is the use case and that's what it's built for and optimized.
- 25:00Exactly.
- 25:00That's the original use case that came out of Pyodide.
- 25:03What's interesting is since then, we've been talking with the WebAssembly folks again who are really pushing the idea of WebAssembly as a containerization technology.
- 25:15So WebAssembly that doesn't actually run in a browser but would run on cloud computers, right?
- 25:22Yes.
- 25:22Because it provides a really nice sandboxed way of running arbitrary code, but it does it in a way that's actually a lot lighter weight than Docker, right?
- 25:31So like Docker is maybe the industry standard for this right now, but Docker essentially you're taking a whole Linux distribution and a whole OS and shoving that in a container and passing that around.
- 25:41Right.
- 25:41And you require the kernels to match of the host and the container, right?
- 25:46Whereas WebAssembly doesn't care.
- 25:48You know, there are projects like Wasmr that are bringing this to Python already, so it's not a far-fetched idea.
- 25:54No, it's not.
- 25:55I think it has a lot of promise, and for our own little data science community, what excites us about it is we can use the browser as like a prototyping tool where the computation is happening locally and it's really fast, maybe while you're working on a small part of your data.
- 26:11But then to be able to very smoothly say, I'm now going to run that on a cluster without having to change anything and having it still be built on the same technologies could be a really powerful thing.
- 26:22This is all kind of in the pie-in-the-sky streaming of its stage for us.
- 26:26Yeah, but it's a sweet pie.
- 26:28It looks really nice.
- 26:29Yeah.
- 26:29Exactly.
- 26:29You could bring in things like Dask as well to help you do distributed computation without people really even knowing or caring that that's happening.
- 26:38So there's a lot of stuff that could like expand, expand to the servers, expand to clusters, and so on.
- 26:42Exactly.
- 26:43Yeah.
- 26:43Cool.
- 26:44So I've seen some cool examples of this already working.
- 26:47Like I pulled up the, was it LA data or some kind of like city map, the one that came from your article that you recently published, but there's a live example and a link to that.
- 26:55It's pretty interesting.
- 26:56It's doing real data science.
- 26:58It's doing real computation.
- 26:59So it takes like 15 seconds to load, right?
- 27:02Yeah.
- 27:03Even if you've already cached the download, it's like computing for 15 seconds.
- 27:06So you got to be patient.
- 27:07But then it comes up and it's got a really wonderful graph and visualizations.
- 27:11Like how do you do the visualizations?
- 27:14There's probably a lot of JavaScript and other tie-ins there, right?
- 27:17Yeah.
- 27:17So it actually depends.
- 27:19There's a lot of different ways you can do it.
- 27:22But that example you're talking about with the map and the call data, there we're using a JavaScript library called Regal, which is sort of a WebGL front end to do that 3D plotting.
- 27:33And it's nice because it uses the hardware to do the 3D acceleration and works really well.
- 27:37But you can just as easily use Matplotlib and exact like the full Python Matplotlib and do your plotting there.
- 27:45And that all works.
- 27:46There's only very maybe 300 lines of code that kind of glue Matplotlib to a Web Canvas that had to be written to make that work.
- 27:54But otherwise, that's pure Python doing your plotting.
- 27:57But then we've also played around with tools like Plotly, which is a JavaScript plotting library.
- 28:03One of the things that PyDyde does really well is it can share your data between Python and JavaScript without copying it.
- 28:09So it's really fast to share the data back and forth.
- 28:12So you can do like all your heavy lifting computation in Pandas in Python and then just ship that over the JavaScript side for plotting and kind of mix and match.
- 28:23So it's kind of exciting that like you no longer have to say, well, I'm working in Python.
- 28:27So my choices for plotting are Matplotlib and maybe Boca and whatever the Python ones are.
- 28:31You can choose from both Python and JavaScript ecosystems.
- 28:35Maybe in this crazy future, you could also import some other WebAssembly based visualization thing that you don't even know what it's written in, right?
- 28:43Like who knows?
- 28:43Maybe it's in Swift or something crazy, right?
- 28:45But yeah, interesting.
- 28:46Yep.
- 28:46Okay.
- 28:47One thing I want to ask you is like if I'm a data scientist and I'm listening to this and I'm like super excited, should I be excited today or should I be excited in like a year and a half?
- 28:55Is this something I can reasonably use now or is that a cool proof of concept or like what's the status?
- 29:00I would say you have to have a little bit of patience still.
- 29:03Okay.
- 29:04You know, we certainly encourage people to come up and try to do the kind of things they're doing in Jupyter now in iodide and pyodide and sort of see where some of the rough edges are.
- 29:14We do actually have it.
- 29:16It is being used for real work within Mozilla for data science and people are using the Python parts of it and stuff.
- 29:22So if you sort of know where the boundaries are and what you can get away with, it's already working.
- 29:27It's sharp and jagged over there.
- 29:29Don't go over there.
- 29:30Exactly.
- 29:30Yeah, yeah, yeah.
- 29:31Right.
- 29:32But I would be being disingenuous if I said it was ready for everything that people might want to do.
- 29:36Sure.
- 29:37I guess the way you find out and the way you get it ready is people try to use it and you're like, wait, everyone's trying to do this and it doesn't do that.
- 29:42Well, maybe that's something it gets.
- 29:44Exactly.
- 29:44No, it's really helpful for us, actually, because we've been getting some really great bug reports.
- 29:49We had a blog post last week that kind of brought a lot more traffic to the site and that turned into a lot of really great bug reports of things that seem obvious in hindsight, but we had never thought to check, is that going to work?
- 30:00Yeah.
- 30:01That's really helpful.
- 30:02And also, it helps us prioritize what features need to be added.
- 30:07If 10 out of the 20 people that show up all have problems with the same thing, well, that's a pretty good sign that that's where we should focus effort.
- 30:13Yeah, that makes total sense.
- 30:15Are there full-time employees working on it at Mozilla?
- 30:18What is its status as a project for you all?
- 30:21So there's probably a total of about three FTEs working on it divided among five people within Mozilla, and it's still primarily sort of an internally devoted project in that our internal users are kind of helping us prioritize what gets worked on and move forward.
- 30:39We do, of course, have the public-facing website at iodide.io where anybody can come up and create notebooks, and we do look at that, too.
- 30:47And it's all open source.
- 30:48Yeah.
- 30:49And we're just sort of hoping that if we can bootstrap it enough internally and prove it as a useful tool, then we can get, hopefully, some more resourcing to kind of make it something that will serve a broader community.
- 31:00Yeah, that's super cool.
- 31:01So if I am a person who maintains or is somehow in charge of a data science package that is not available in there, I'm guessing there are some that are not available.
- 31:11Is that right?
- 31:12Yeah.
- 31:12Yeah.
- 31:13Yeah.
- 31:13So if I am, how do I get mine?
- 31:15Like, I run, you know, whatever.
- 31:17And I really want that available alongside NumPy.
- 31:20How do I make that happen?
- 31:21So right now, all our package building is built as part of kind of this monolithic tree of make files.
- 31:28So to add a new package, you basically add it to the Plyodide source code, and then that causes it to automatically get built and then eventually distributed.
- 31:37Where I'd really like to move is to something that works more like CondoForge where, and maybe even literally to use CondoForge if we can make that work so that anybody could just walk up and contribute a package sort of in their own repo and that would automatically get picked up and then distributed.
- 31:53So it would be a more like distributed build system than what it is now.
- 31:57Oh, yeah.
- 31:58That's pretty interesting.
- 31:59Yeah.
- 31:59That's a cool idea.
- 32:00Yeah.
- 32:00To just basically have approved sources for packages and you guys just continually pull them kind of like, like you said, like a CI system almost.
- 32:08Exactly.
- 32:08Yeah.
- 32:09Yeah.
- 32:09So you'd have individual package maintainers who could maintain their own package, but the sort of infrastructure that makes that all work would be centralized.
- 32:18That's the idea.
- 32:19Yeah.
- 32:19Right.
- 32:19Is it hard?
- 32:20If I have something that has like some C section and some Python section, what's the overhead to get it working in this?
- 32:28It varies.
- 32:29So like NumPy that has C, but it's fairly straightforward.
- 32:33C is not too bad.
- 32:36One of the things we've really struggled with is SciPy because SciPy actually has a fair bit of Fortran.
- 32:42And so Fortran is its whole other set of problems for WebAssembly.
- 32:47There's basically there's not a good compiling option for anything that's not Fortran 77 right now.
- 32:54So we have to kind of push that forward somehow.
- 32:56So there's kind of this range of easy to hard and it's hard to know maybe up front how hard something's going to be.
- 33:02Pure Python stuff is very easy.
- 33:04Pure Python.
- 33:05There's actually even a little helper script where if you run this little helper script with the name of the package on PyPy and it will automatically generate the make file needed to build it as part of PyDy and it automatically goes in.
- 33:17You know, you submit that as a PR and you're good to go.
- 33:20That's pretty cool.
- 33:21So when say my Python, suppose I have a pure Python package on PyPI and I want to have it in there.
- 33:27Does it get somehow compiled to WebAssembly?
- 33:31Does WebAssembly itself just like become an interpreter and just use Python bytecode?
- 33:36Like what do you know what the process there is?
- 33:38Yeah.
- 33:39So PyDyde is literally running the Python interpreter inside your browser.
- 33:44So if you have a pure Python package, it's actually just shipping Python to that interpreter running in the browser.
- 33:51And that's how it runs.
- 33:52So it basically just works off PYC bytecode.
- 33:55Exactly.
- 33:56And just feeds it off to the interpreter just happens to be executing not on C but in WebAssembly.
- 34:00Exactly.
- 34:01That was my first guess.
- 34:03But I thought maybe there's some other magic like, oh, we had to add a JIT compiler to this or, you know, some weird thing.
- 34:08No.
- 34:09And so for that reason, what you're getting is something that performs pretty similar to CPython, right?
- 34:16Something like PyPy.js has, of course, opportunities to JIT the Python itself and potentially get a lot more performance.
- 34:23So we're not doing anything sophisticated like that in PyDyde at this point.
- 34:27Yeah.
- 34:28Yeah.
- 34:28So because we have a really nice JIT sitting there in the browser, it's certainly there and could be on some point.
- 34:34It's certainly possible.
- 34:35I know Brett Cannon worked on Pigeon, I think is what it was called.
- 34:39Yeah.
- 34:39Which was looking at some of the JavaScript JIT stuff and seeing how that could be applied back into the CPython runtime.
- 34:47I don't know.
- 34:48Maybe there's some synergy there.
- 34:49Who knows?
- 34:49Because it sounds like they're all kind of swimming in the same soup of ingredients or whatever.
- 34:54Absolutely.
- 34:55Yeah.
- 34:55What does the performance of WebAssembly relative to JavaScript look like?
- 35:00So if I had like my Quake example and I ran Quake over Asm.js and I ran it in WebAssembly, what would I get?
- 35:08I don't actually know those numbers.
- 35:10I'm sure that WebAssembly at this point is quite a bit better than Assembly.js.
- 35:14The numbers I do have is what happens to Python.
- 35:17So like comparing Python running natively on a machine versus inside the browser.
- 35:23And you generally get anywhere between like the same speed and 12 to 20 times slower.
- 35:30Okay.
- 35:30And what seems to matter.
- 35:32So if your Python application is mainly just calling NumPy operations, which are at the bottom sort of C tight inner loops.
- 35:40Yeah.
- 35:40That stuff tends to be pretty much the same speed.
- 35:44Right.
- 35:45Those tight C loops tend to be pretty much the same in WebAssembly as out of WebAssembly.
- 35:49If you're doing a lot of looping in Python or calling a lot of Python functions, those things tend to get quite a bit slower.
- 35:55And the reason is that the Python interpreter is basically calling a lot of C function pointers all the time.
- 36:04That's sort of kind of how it works.
- 36:05It's calling other C code through C function pointers.
- 36:09Py, object, star, all over the place.
- 36:10Yeah.
- 36:11Exactly.
- 36:11Yeah.
- 36:12And calling a C function pointer in WebAssembly is quite a bit slower than it is on native.
- 36:17Okay.
- 36:18For reasons that I don't know if I could fully articulate, but probably partly related to the security model.
- 36:24Like there's just ways in which that's a lot slower.
- 36:27And unfortunately, the way the Python interpreter is designed is making lots of C function pointer calls all over the place.
- 36:33Right.
- 36:33But it might not matter.
- 36:34It depends.
- 36:35Right.
- 36:35Exactly.
- 36:36So it's five times slower might make it go from half a millisecond to, I don't know, 2.5 milliseconds.
- 36:43And like the user doesn't perceive these or care about them.
- 36:46Right.
- 36:46But now all of a sudden you have this great new deployment story and this execution engine.
- 36:49And like what it opens up is way more valuable than that amount of slowness potentially.
- 36:53Exactly.
- 36:54It's certainly within the realm of like I can live with that.
- 36:57You know, it's not hundreds of times slower.
- 36:59Right.
- 36:59Yeah.
- 37:00Yeah.
- 37:00Interesting.
- 37:01Cython.
- 37:01Can I do some, like I've got some doubly nested loop and I know that that's the problem.
- 37:08Can I Cythonize that puppy and then WebAssembly the result or something?
- 37:13Yeah.
- 37:13Yeah.
- 37:14So Cython works just fine.
- 37:16And in fact, like Pandas is largely written in Cython.
- 37:20So in order to get that to work, that needed to work.
- 37:22But all of that compilation happens ahead of time on the native machine before shipping it
- 37:29to the browser.
- 37:30We don't actually have the ability to compile Cython code inside of the browser.
- 37:34Right.
- 37:34But as a package developer, maybe I could leverage that to avoid the, like the really, so where
- 37:40there's a penalty in Python versus C now, the penalty may be worse.
- 37:43It's in WebAssembly, but maybe the answer is Cython still.
- 37:46Absolutely.
- 37:47Yeah.
- 37:48Okay.
- 37:48Yeah.
- 37:48Totally.
- 37:49And then of course, people have gotten the Clang compiler to run in WebAssembly.
- 37:54So theoretically, we could get, we could put that there as well.
- 37:59And then we could send it Cython code and get something back and maybe run that right away.
- 38:04Like that's a little bit getting into crazy territory maybe, but who knows?
- 38:09Yeah.
- 38:09Well, it's turtles all the way down or WebAssembly is all the way down or something like that.
- 38:12Right.
- 38:13Right.
- 38:13Yeah.
- 38:13Interesting.
- 38:14Both having all of this experience and expertise in Rust and Rust being so built for WebAssembly
- 38:23or being so well paired with WebAssembly.
- 38:25And then also some projects trying to do, say, CPython's runtime in Rust.
- 38:32I guess the question is rambling around is to say, if I take Rust and like rethink CPython,
- 38:39what do you think the possibilities are there in this context?
- 38:43Yeah.
- 38:43I mean, I think what's exciting about Rust is because it's a newer technology, unlike C, like,
- 38:49it's a lot easier to get into WebAssembly because they just, there's just not as much baggage.
- 38:56And that's kind of Rust's advantage on WebAssembly.
- 38:58Plus, there's the fact that I think Rust and WebAssembly both coming out of Mozilla with a lot of people overlapping between those two communities has really helped that make that story much smoother.
- 39:10You know, for example, if I was going to write something from scratch that I wanted to run in WebAssembly, I would absolutely reach for Rust and not C in this day and age.
- 39:17It just is going to be an easier experience.
- 39:19So, like you say, there's a project, maybe more than one, I don't know, that to rewrite the C and the Python interpreter in Rust, right?
- 39:28So then that would help us build something like Pyodide a lot easier because it's in Rust.
- 39:33We don't have to deal with a lot of the sort of niggly details we've had to deal with C.
- 39:37My worry there is historically, whenever people write an alternative Python interpreter, it's really hard for it to catch on because there's so much catch up to do.
- 39:48You know, if they can, I think the sort of uphill battle for that project, and I think I've read about the project and the author is like clearly doing it for fun.
- 39:57Right, exactly.
- 39:58You don't have to have a better reason than for fun, and I'm not trying to say that that's not a valid reason.
- 40:03But, like, I think for that to kind of take over from the CPython interpreter, which I know is not a goal, it would have to, like, convince that community that's currently maintaining the CPython interpreter that Rust is going to be a better way forward.
- 40:16If they can do that and sort of replace it and become the leader, that would be an amazing outcome.
- 40:22But I think that's a real uphill struggle.
- 40:25It would be an interesting outcome, but certainly with Rust being so new and C being so, such a stalwart, right?
- 40:31Like, it's the foundation of so many things.
- 40:34It would be an interesting conversation for sure.
- 40:39This portion of Talk Python To Me is brought to you by Microsoft and Azure Pipelines.
- 40:43Azure Pipelines is a CI-CD service that supports Windows, Linux, and Mac.
- 40:47It lets you run automatic builds and tests of your Python code on each commit or pull request.
- 40:53It is fully integrated with GitHub, and it lets you define your continuous integration and delivery pipelines with a simple YAML file.
- 40:58Azure Pipelines is free for individuals and small teams.
- 41:01If you're maintaining an open source project, you'll even get unlimited build minutes and 10 concurrent pipelines.
- 41:07Many Python projects are already using Azure Pipelines.
- 41:10So get started for free at talkpython.fm/Microsoft.
- 41:16I guess what I'm thinking also is, like, it's interesting that people have these, hey, I want to learn Rust, and let me do that by trying to rewrite CPython and Rust.
- 41:26These are interesting and, like you say, super good goals, and people, I'm sure, are getting a lot out of it.
- 41:30But I'm more thinking of, like, what if you rethought what it meant to be the runtime for Python specifically optimized for WebAssembly?
- 41:42You know what I mean?
- 41:42You try to make it, like, 99% compatible, and so you can bring in C libraries and stuff like you can through WebAssembly.
- 41:50But is there an opportunity to, like, truly rethink CPython, not just rewrite it with the different syntax and compilers?
- 41:57Yeah, that's a really good question.
- 41:58I think...
- 41:59I don't know the answer.
- 42:00Yeah.
- 42:01Just interesting to think about.
- 42:02Yeah.
- 42:03I think one of the things that a lot of various projects have kind of worked on rethinking the Python interpreter has sort of been, what if we can assume that there's a really good JIT around, right?
- 42:15That's kind of what PyPy is, and, like, IronPython, when they built it on top of the .NET CLR and those sorts of things, they sort of go, if we have a really good JIT around, what can we do?
- 42:26I think a lot of times they run up against the sort of really dynamic corner cases of the Python language that are really hard to deal with there.
- 42:34Yeah.
- 42:34And you end up with something that's slightly different from Python.
- 42:38That, to me, always feels like where it gets a little stuck.
- 42:40Right.
- 42:41And if there's a way of unsticking that, like, unfortunately, the community has gone through this big transition from Python 2 to 3 already, and I don't know if there's a lot of appetite for another Python that would be slightly incompatible.
- 42:54Exactly.
- 42:54If you could live with something that's slightly incompatible, I think there's a lot of ways you could make it more performant with some of these newer technologies.
- 43:01Yeah.
- 43:02I mean, maybe there's an opportunity to do that.
- 43:05And maybe PyOidide's not the right answer for that because you're not looking at, I don't know, like, so much of what happens there happens in C anyway.
- 43:13Like, that's where the data science action really is, and Python is kind of the orchestration layer.
- 43:18Maybe it's something like, what if I could write the equivalent of AngularJS or React with an Electron app with a nice UI, but I only touch Python?
- 43:26You might be willing, like, in that context to say, well, I'd rather have a 99% compatible Python with packages than just switch 100% to JavaScript as a Python enthusiast, right?
- 43:37Like, that might be a cell you would buy.
- 43:39Yeah.
- 43:40Yeah, absolutely.
- 43:41Yeah.
- 43:41And the file size doesn't matter in these, like, offline Electron apps and stuff because you're already downloading, like, a 60-meg Chrome binary.
- 43:49Like, what's another 10 megs that's just zipped up in there anyway, right?
- 43:53Right, exactly.
- 43:54So who knows?
- 43:54Maybe that's an interesting corner to explore.
- 43:56Not necessarily for you, but for, like, anyone interested, right?
- 43:59Yeah, absolutely.
- 44:01Yeah, cool.
- 44:01So I guess maybe tell us a little bit about where things are going.
- 44:05Like, where are you and what's the future plans?
- 44:08There's a bunch of things that don't work that we'd like to work on.
- 44:11So, like, currently we don't support threading because when we started the project, WebAssembly didn't support threading.
- 44:17Now WebAssembly does, so it would be good to go back and kind of build on top of that.
- 44:22Is that true operating system threads or is that some kind of, like, preemptive threading?
- 44:27Like, what does threading in WebAssembly mean?
- 44:28It's based on the web worker technology in browsers.
- 44:34My understanding is they are sort of true separate operating system threads, and they're probably even more isolated than you would think of with threads.
- 44:41They're kind of their own little JavaScript interpreters.
- 44:44Right.
- 44:44They can kind of message passing, and that's all they get for data sharing and whatnot.
- 44:47Exactly.
- 44:48Exactly.
- 44:48So you can take advantage of that in WebAssembly now and pass things between web workers.
- 44:53And there should be a way to kind of hopefully build the Python threading API on top of that.
- 44:59It sounds almost like Python's multiprocessing more than Python's threading.
- 45:04That's probably accurate.
- 45:05Yeah, yeah, yeah.
- 45:06But it's still, like, it's cool that it would be some parallelism that you can do regardless of how that happens, right?
- 45:11Exactly.
- 45:12Exactly.
- 45:13Okay.
- 45:13Another big sticking point is networking is obviously very different for Pyodide than it is for native Python, largely because of the sandbox, right?
- 45:22You can't just open up a Unix socket and start writing things to it because that would be a big security hole.
- 45:28So what that means is a lot of the libraries that come in the Python data science community, like Pandas, they have ways of fetching things over the network, and those don't currently work because they try to open a socket and they fail.
- 45:41I see.
- 45:41So building some kind of abstraction layer, maybe on top of WebSockets or maybe something else that would at least let basic things work from Python would be really useful.
- 45:53Right now, generally, what you have to kind of do is do your networking in JavaScript using Fetch or whatever the tools are there, and then you can bring that into the Python side.
- 46:01Right.
- 46:01Axios or something nice, yeah.
- 46:03Yeah, exactly.
- 46:04Okay.
- 46:04Yeah, but so, like, if I installed imported requests and tried to use that, for example, that might not work?
- 46:11That's definitely not going to work.
- 46:13Yeah.
- 46:13Okay.
- 46:14Cool.
- 46:14All right.
- 46:15So what else?
- 46:16You talked about this, like, Honda Forge-like distributed build integration thing.
- 46:20That's pretty cool.
- 46:21What else?
- 46:21There's a whole area of research we're doing around the data sharing.
- 46:26So, like, I mentioned this before, like, you can have a NumPy array living in Python and pass that over to JavaScript without copying it, and that's pretty cool that that works.
- 46:35But when you bring it over to JavaScript, you don't get, like, how many dimensions it has or what the shape is.
- 46:41You just sort of get this one-dimensional thing because that's all that JavaScript really supports.
- 46:45So we'd like to build something that kind of makes that more transparent and smooth.
- 46:51Would that be like a JavaScript wrapper that kind of has an API like Pandas a little bit?
- 46:56Or what are you thinking there?
- 46:57Yeah, something like that, I think.
- 46:59There's a project called Apache Arrow, and its sort of purpose is to allow for sharing of these data structures in memory between different language runtimes.
- 47:10And they've primarily been looking at, like, native runtime space.
- 47:15But they have a JavaScript implementation.
- 47:17They have a Python implementation.
- 47:19It should be possible to kind of bring all that into the browser and use it there.
- 47:22And then, again, building on top of work already been done and not have to build it ourselves.
- 47:27But there's a lot of details there.
- 47:29The other thing that's sort of exciting for Arrow for us is the sort of industry standard way to bring data in for data science computation is still the comma-separated value format, right?
- 47:42They're not terribly efficient to read.
- 47:45They're not very space-efficient or memory-efficient.
- 47:48Whereas Apache Arrow provides this sort of nice, tight binary format that we could use.
- 47:52Yeah.
- 47:53And that would actually allow us to sort of shove more data into the browser, which is pretty memory-limited to begin with.
- 47:58So anything that will let us kind of get away from CSVs is also on our roadmap.
- 48:03Yeah, just parsing all those strings is going to be a slow thing wherever.
- 48:07Yeah.
- 48:08And most of the libraries that do it don't.
- 48:11They assume tons and tons of memory.
- 48:13So they don't necessarily do it in the most efficient way possible.
- 48:16They don't necessarily stream it.
- 48:17They might copy the whole thing.
- 48:18And then, you know, so.
- 48:20Right.
- 48:20Yeah.
- 48:21Okay.
- 48:21Yeah.
- 48:21That sounds pretty cool.
- 48:22And then I was looking around the site.
- 48:24I found like a pretty cool demo notebook that people can try out.
- 48:27I guess, you know, there's that.
- 48:29And I'll put a link to that.
- 48:30And what else do you recommend for people just trying to play around with it?
- 48:32There's a demo notebook that kind of goes through the language features that works also kind of as a tutorial for how to get started.
- 48:39But then also linked on the blog post from last week.
- 48:42And maybe we can link to that blog post.
- 48:44In there, there's a bunch of other demo notebooks that kind of do more real world cool things, putting stuff together.
- 48:49Like you say, the call data one is pretty fun.
- 48:52There's another one that I used at Mozilla internally for figuring out how to time things in Firefox.
- 48:58It's kind of fun.
- 48:59So if you go to iodide.io, then all the notebooks that anybody has created on that public website, they're all public.
- 49:07And so you can just kind of browse through there and see what interesting things other people are doing.
- 49:11Yeah.
- 49:11Cool.
- 49:11There's always interesting stuff happening in the data science space.
- 49:14Yeah.
- 49:14Cool.
- 49:14One thing that I just wanted to give a shout out to, I don't know if you've even looked at it or something.
- 49:19I became aware of it basically like a week ago is WASM.
- 49:23So W-A-S-M is often the extension for WebAssembly.
- 49:26So W-A-S-M is like WebAssembly or right?
- 49:28So are you familiar with this project?
- 49:30Yeah.
- 49:31Yeah, I am.
- 49:32To me, my first impression is it's kind of a little bit like what Node.js did to JavaScript.
- 49:36Like it used to be JavaScript ran in the browser and that was like its space.
- 49:39And I guess you could open the console and like type and play with it if you want.
- 49:42But then all of a sudden Node.js like sprung on the scene.
- 49:45It's like, wait, I can just take my JavaScript code and run it in like a server process or doing other interesting stuff just in an, like on its own.
- 49:52And WASM is kind of like that for Python.
- 49:55Like it will let you run any WebAssembly code regardless of whether it's this Python code or just like random WebAssembly code.
- 50:02And then directly import that into your Python code.
- 50:05So it's kind of more like Node enabling than it is what you're working on, which is move Python to the browser.
- 50:12It's like the opposite.
- 50:13Move WebAssembly to Python.
- 50:14Yeah, what excites me about it actually is it's going to make languages that aren't C a lot easier to integrate in Python.
- 50:21So like Rust, for example, there is a way to integrate Rust in Python that's actually pretty good and works really well.
- 50:26But if the story was compile whatever you have to WebAssembly and we can get to it from Python,
- 50:32I think that makes it a lot easier to have things written in whatever language is the most convenient or the most, you know, at hand.
- 50:39And what also is potentially exciting from the Pydyde point of view is if this causes there to be a big sort of community of WASM packages that work with Python, we can use those in Pydyde basically for free.
- 50:52Yeah, exactly.
- 50:53It just grows the pie for everyone.
- 50:55Yeah, exactly.
- 50:55Yeah.
- 50:56Yeah.
- 50:56So I mean, I don't have a whole lot more to say than just like, hey, people, if that sounds interesting to you, check it out.
- 51:01It looks like a really cool project.
- 51:02And it just it's just one more sign that there's like this excitement of WebAssembly integrating with these non JavaScript, non browser traditional languages and ecosystems.
- 51:13Yeah, absolutely.
- 51:14Yeah.
- 51:15I guess if I'm throwing out other stuff that just kind of randomly to do here, one more I'll throw out.
- 51:19That's it's really, really interesting.
- 51:21I don't know if you've heard of this one at all.
- 51:22Blazor.
- 51:23Have you heard of that?
- 51:24Yes, this is the C#.
- 51:26Yeah.
- 51:26Yeah.
- 51:27So they had a totally different take, but they have gotten the .NET runtime, the CLR, all that stuff running a WebAssembly.
- 51:33And now you can do C# in the browser.
- 51:35Their take was to build an AngularJS like framework that lets you write front end code in C# and then run it in the browser.
- 51:43I don't know if that's a good idea or not, but it's, you know, it's kind of the other half of the story, I think, for Python, right?
- 51:49Like right now we've got the data science, like with your work going really well.
- 51:52But there's no story around like, what would I use in Python instead of Vue or Angular?
- 51:59Not necessarily saying those are bad or you should, but like you could, you know, C# is showing the way like on that side of the story.
- 52:06Yeah, I think there's a real advantage to having your implementation and your back end and your front end be in the same language.
- 52:14I think that's kind of what Node has proven.
- 52:16Right.
- 52:16There's definitely an appeal there.
- 52:17Yeah.
- 52:18Yeah.
- 52:18And so I think for Blazor, it's the same thing.
- 52:21If you're a shop that's done your back end in C# for a long time, well, now you can have your front end in it too.
- 52:25That's really nice.
- 52:27One of the things that from talking to some Jupyter developers, one of the things they're really excited about with Pyodide is now they could potentially start to have some of their front end stuff written in Python as well as their back end that's currently in Python.
- 52:41So because right now the world they live in is there's sort of these arbitrary lines that get drawn between what you would write in one language versus another.
- 52:49And they're not always the right thing.
- 52:51And sometimes you have to write the same thing in two different languages just so that you can put it in both places.
- 52:57Right.
- 52:57Validation or something.
- 52:58Get rid of those.
- 52:59Yeah.
- 53:00Validation or even with Jupyter, it's certain kinds of computation that they need in the widget as well as in the back end and they need to match.
- 53:07But one's written in Python.
- 53:11It's not fun.
- 53:11And it's just sort of this arbitrary speed bump that gets created because of the world we live in.
- 53:16But if you imagine a world where all languages run everywhere, suddenly, hopefully, you're doing less work.
- 53:23Yeah.
- 53:23Yeah, absolutely.
- 53:24And you can reuse stuff in a context where you wouldn't.
- 53:27Like, until your work, it would have been kind of insane to say, well, let's reuse NumPy in the browser, right?
- 53:32Yeah.
- 53:33But now these doors are open.
- 53:35So it just creates more synergy, I think.
- 53:37It's pretty awesome.
- 53:38All right.
- 53:38Well, I think we're pretty much out of time there.
- 53:40Yeah.
- 53:40Definitely a fun conversation.
- 53:42I think the future is bright.
- 53:44What do you think?
- 53:44Yeah, absolutely.
- 53:45I'm really excited about all this stuff.
- 53:47Yeah.
- 53:47Same.
- 53:47All right.
- 53:48Now, before I let you out here, let me ask you the two final questions.
- 53:50I kind of think I can guess this first one because of the way you opened the whole show.
- 53:56But favorite editor for writing Python code?
- 53:58Yeah.
- 53:59Yeah.
- 53:59So I use Emacs, but I actually use SpaceMax.
- 54:01So it's kind of this like weird Emacs VI hybrid.
- 54:05But I find it works for me.
- 54:06Yeah.
- 54:07Right on.
- 54:07Very cool.
- 54:08And then notable PyPI package?
- 54:10Oh, gosh.
- 54:11I mean, the one I'm most familiar with is Matplotlib because I worked on it for years and years.
- 54:14And, you know, if you're not familiar with it, go check it out.
- 54:17It's the kitchen sink of plotting for Python.
- 54:21Yeah, it absolutely is.
- 54:22And, you know, it's something exciting and like both silly but also kind of real sense.
- 54:26As I saw, now XKCD style plots have come to Matplotlib.
- 54:30Did you see that?
- 54:31Oh, yeah.
- 54:31I implemented that actually.
- 54:33You did?
- 54:34How awesome.
- 54:36Yeah.
- 54:36Yeah.
- 54:36How hard was that?
- 54:38Not too bad.
- 54:39Strangely, the infrastructure that was already there kind of made it easier than it might have been.
- 54:45So.
- 54:45Yeah.
- 54:45I mean, it looks like the sort of cartoony hand-drawn like plots and stuff.
- 54:51But it actually looks really hard to do because it's imprecise and it has these imperfections, right?
- 54:57It seems like it would be hard to tell a computer to be imprecise in like a human way.
- 55:00But well done.
- 55:01And that looks great.
- 55:02So fun.
- 55:03Thanks.
- 55:03Yeah, absolutely.
- 55:04Awesome.
- 55:05All right.
- 55:05Final call to action.
- 55:06People are excited about iodide, pyodide.
- 55:08They want to check it out, maybe contribute.
- 55:09What do you got for them?
- 55:11Yeah.
- 55:12Check out iodide.io where you can check out all the notebooks that people have created.
- 55:16And then we have a GitHub site at github.com/iodide project.
- 55:20Nice.
- 55:21And I'll put those links in the show notes.
- 55:23Are you looking for contributors or people working on it any?
- 55:26Or is it kind of still an internal project at the moment?
- 55:29We're definitely looking for contributors.
- 55:30Find us on Gitter if you have any great ideas.
- 55:32We'd be glad to help you make them reality.
- 55:35Super cool.
- 55:36All right.
- 55:37Well, I am very thrilled to see you all working on getting this take on Python in the browser.
- 55:43I think the more attempts that we have here, the better.
- 55:46And it's an exciting time.
- 55:48And I think it'll take off.
- 55:49Thanks a lot.
- 55:50It was fun talking to you.
- 55:50Yeah, you as well.
- 55:51Thanks for being on the show.
- 55:52Bye.
- 55:52All right.
- 55:52Take care.
- 55:53Bye.
- 55:53This has been another episode of Talk Python To Me.
- 55:57Our guest on this episode was Michael Dropboom.
- 55:59And it's been brought to you by Microsoft.
- 56:01If you're a Python developer, Microsoft has you covered.
- 56:05From VS Code and their modern editor plugins, to Azure Pipelines for continuous integration,
- 56:10and serverless Python functions on Azure.
- 56:13Check them out at talkpython.fm/Microsoft.
- 56:17Want to level up your Python?
- 56:19If you're just getting started, try my Python Jumpstart by building 10 apps course.
- 56:23Or if you're looking for something more advanced, check out our new async course that digs into all the different types of async programming you can do in Python.
- 56:32And of course, if you're interested in more than one of these, be sure to check out our everything bundle.
- 56:36It's like a subscription that never expires.
- 56:39Be sure to subscribe to the show.
- 56:40Open your favorite podcatcher and search for Python.
- 56:43We should be right at the top.
- 56:44You can also find the iTunes feed at /itunes, the Google Play feed at /play, and the direct RSS feed at /rss on talkpython.fm.
- 56:53This is your host, Michael Kennedy.
- 56:55Thanks so much for listening.
- 56:57I really appreciate it.
- 56:58Now get out there and write some Python code.
- 56:59I really appreciate it.
- 57:20Thank you.