Latest / Talk Python To Me / #391: Pyscript powered by MicroPython
Transcript
- 0:00No Python announcement of 2022 was met with more fanfare than PyScript.
- 0:04This project, announced at PyCon, allows you to write Python files and run them in your browser
- 0:09in place of JavaScript or even with interactions between Python and JavaScript.
- 0:15There's just one catch. The runtime download was a 9 megabyte WebAssembly file.
- 0:20That made its use quite limited.
- 0:22On this episode, we dive into some news that might change that calculus.
- 0:27The MicroPython and PyScript folks have been teaming up to get PyScript running in the browser on MicroPython.
- 0:34Yes, that's the embedded chip Python that you may have heard of.
- 0:38And here's the good news.
- 0:39MicroPython's WebAssembly is just 300k to download and loads at under 100 milliseconds.
- 0:44Now that could unlock some real possibilities.
- 0:47We have Brett Cannon, Nicholas Toleve, and Fabio Plager on the show to discuss.
- 0:53This is Talk Python To Me, episode 391, recorded November 21st, 2022.
- 0:59Welcome to Talk Python To Me, a weekly podcast on Python.
- 1:15This is your host, Michael Kennedy.
- 1:17Follow me on Mastodon, where I'm @mkennedy, and follow the podcast using @talkpython,
- 1:22both on fosstodon.org.
- 1:24Be careful with impersonating accounts on other instances.
- 1:27There are many.
- 1:28Keep up with the show and listen to over seven years of past episodes at talkpython.fm.
- 1:34We've started streaming most of our episodes live on YouTube.
- 1:37Subscribe to our YouTube channel over at talkpython.fm/youtube to get notified about upcoming
- 1:43shows and be part of that episode.
- 1:45This episode is brought to you by the Local Maximum Podcast over at LocalMaxRadio.com
- 1:51and AWS Insiders Podcast.
- 1:53AWS is changing fast.
- 1:55Listen in to keep up over at talkpython.fm/AWS Insiders.
- 2:01Transcripts for this episode are sponsored by Assembly AI, the API platform for state-of-the-art
- 2:07AI models that automatically transcribe and understand audio data at a large scale.
- 2:12To learn more, visit talkpython.fm/assemblyai.
- 2:16Hey, guys.
- 2:16Welcome back to Talk Python To Me.
- 2:18Thanks, Michael.
- 2:18Hey.
- 2:19Thank you, Michael.
- 2:19Yeah.
- 2:19Fabio, Nicholas, Brett, it's really good to have you all here.
- 2:22And I know you are all very excited about this topic.
- 2:27Brett, I believe the last pre-COVID PyCon, we did a live on the Expo floor show about WebAssembly.
- 2:35We did.
- 2:36Yeah.
- 2:36Fabio, we recently talked about PyScript.
- 2:38And Nicholas, you're right in there as well, working on WebAssembly, PyDyde, PyScript stuff
- 2:43as well.
- 2:44So I know a lot of people know all of you, but maybe let's just kick it off with a quick
- 2:48round of introductions and background.
- 2:50Not too deep since we've all done it before.
- 2:52Brett, let's go with you first.
- 2:53Okay.
- 2:54Keep it short.
- 2:54I am the dev manager in charge of the Python experience in VS Code.
- 2:58Been a core developer for 19 years.
- 3:00Been on the Python steering council since Guido's retirement.
- 3:04And I'll stop there.
- 3:05Yeah.
- 3:06Fabio.
- 3:06So I'm creator of PyScript, current maintainer with Nicholas.
- 3:11I've been working with Franaconda for eight years now.
- 3:15Right now, I'm tech lead for PyScript and been doing a lot of community stuff around Python
- 3:21for a long time as well.
- 3:23Yeah.
- 3:23Fantastic.
- 3:24PyScript was the big news out of PyCon last year.
- 3:26That, I think, cut a lot of people by surprise and people were very excited about that, including
- 3:31myself.
- 3:32Yeah.
- 3:32I'm very excited.
- 3:33And yeah, got a lot of attention for good and bad.
- 3:36Right?
- 3:36Yeah.
- 3:37Yeah.
- 3:38Yeah.
- 3:38I was going to get some more attention today.
- 3:40Yeah.
- 3:42Hopefully.
- 3:42Indeed.
- 3:44Nicholas.
- 3:45Welcome.
- 3:45Hi.
- 3:46So, yep.
- 3:47I'm a colleague of Fabio's.
- 3:49I'm a principal engineer on the PyScript team.
- 3:51Prior to joining Anaconda in the summer, I'd been a Pythonista for far too many years and
- 3:56I care to remember.
- 3:57Before that, I was a teacher.
- 3:59And before that, I was a classically trained musician.
- 4:03And that probably explains my interest in Python in education and the activities that I still
- 4:09do in that sphere.
- 4:11So that's me.
- 4:12That's fantastic.
- 4:12You were involved with the BBC Microbit, right?
- 4:15Yes.
- 4:15I was involved with the BBC Microbit.
- 4:18It's fun.
- 4:19Yeah.
- 4:20Absolutely.
- 4:20Yeah.
- 4:21That's awesome.
- 4:21And we talked about that before.
- 4:22Okay.
- 4:23Yeah.
- 4:23Well, let's talk about running Python in the browser.
- 4:27There have been some attempts before and those attempts are still, you know, used in different
- 4:32places.
- 4:32I'm thinking of like Brython and Sculpt and those types of things.
- 4:37Anyone who has seen the birth and death of JavaScript, that famous 15-minute talk, which
- 4:42has got to be one of the most hilarious and yet insightful, like educational foundations
- 4:48of the web and JavaScript and, you know, what became WebAssembly talks of all time is really
- 4:55great.
- 4:55And I think those kind of land in that realm.
- 4:57But since then, as we started, like, you know, WebAssembly has allowed us to bring
- 5:02real runtimes, mostly things based on C or REST, but older things based on C, into the browser
- 5:08and run there.
- 5:09So who wants to sort of introduce this whole idea of WebAssembly quickly for those who don't
- 5:15necessarily know and sort of set the stage so people see where we're coming from?
- 5:18All right.
- 5:19I'll take it.
- 5:19So you can kind of think of WebAssembly as almost portable CPU.
- 5:24It's technically an instruction set that basically is almost like assembly designed to just run
- 5:30anywhere.
- 5:30It's all abstracted.
- 5:32It's technically stack-based, much like CPython's interpreter, for those of you who want to know
- 5:37insider baseball knowledge or insider football.
- 5:40But that's basically it.
- 5:42WebAssembly is really just portable target to compile stuff for that more or less you make
- 5:48a runtime work for that target and it gets to run everywhere.
- 5:52There's more details we can get into in terms of WASM versus WASE and platform-specific
- 5:57stuff.
- 5:58But at the core base low-level thing underpinning all of our discussion today is WebAssembly,
- 6:03which is basically just a portable CPU target.
- 6:05Yeah.
- 6:05Okay.
- 6:06Excellent.
- 6:06And CPython, I guess as the name would very strongly indicate, although people might not
- 6:11know, is largely C at its core.
- 6:14It's not Python code.
- 6:16Some of the standard library is, but not, you know, at the heart, there's an insane
- 6:21switch statement while loop that is written in C.
- 6:24And so that, if we can get that into WebAssembly, then we can get Python, the runtime, into the
- 6:29browser.
- 6:30Correct.
- 6:30Technically, as long as you can compile whatever language you want to WebAssembly, that's how
- 6:36we get it in.
- 6:36And traditionally, the tool chains that have supported compiling data WebAssembly, either
- 6:42statically compiled languages that use something like Clang as a build tool chain, or which
- 6:49typically has fallen under C and C++, Rust, because once again, Rust is based off of Clang
- 6:55for their compiler.
- 6:56As long as your language could use a tool chain that already had the support to compile
- 7:00down to WebAssembly as a CPU architecture or target, you were able to get some WebAssembly.
- 7:06So in CPython's case, because it's implemented, the key parts are in C.
- 7:10That was able to be compiled down such that I can run some WebAssembly.
- 7:14Nicholas's work with MicroPython the same.
- 7:16MicroPython's written mostly, I believe, in C as well.
- 7:19And so basically, that allowed both projects to basically just use a specific compiler with
- 7:25specific flags to just say, instead of writing out X64 assembly for my EMB or Intel chip or
- 7:31your ARM chip on your Mac, write me out some WebAssembly instead.
- 7:36People's first impression when they hear this is like, oh my gosh, binary code executing the
- 7:41browser, run for your life, right?
- 7:43But it's really no different than JavaScript.
- 7:44It has the same permissions and liabilities and benefits of JavaScript.
- 7:49It's just a different execution model.
- 7:50Yeah.
- 7:50The same sound bolts as I was.
- 7:51That's the core.
- 7:53There are a lot of nuances that comes with how it is.
- 7:57It's taught, right?
- 7:59One, it's still in a very young phase, despite all the usage and acceleration.
- 8:04Everybody's excited about it.
- 8:06But as Brett said, it's mainly a portable CPU.
- 8:10And it doesn't really come with the rest of what you would expect from an operating system,
- 8:16and especially file system and things like this.
- 8:19So there's a lot of extra work that the larger community is trying to add now to figure things
- 8:24out.
- 8:25Now, and the other small detail that I wanted to add is, yes, it's basically just like JavaScript
- 8:32on the browser, with the exception that some APIs are not available.
- 8:36For instance, access to DOM and other things like this.
- 8:39Yeah, I was going to say, it's worth pointing out that what Fabio is saying about, it's not
- 8:44like having an operating system.
- 8:45There are projects.
- 8:46You know, Brett mentioned Waze.
- 8:48There's also nscript as well, which gives you abstractions of a file system and so on and
- 8:52so forth.
- 8:52Such that you could, and it's always important to be aware when a developer uses the word
- 8:57just, but one could just compile CPython to WASM and it will just work in the browser.
- 9:04But of course, to get that to happen, it takes a rather a lot of work and browser-based expertise
- 9:13to actually get you to, for instance, the Python prompt in a REPL, as it were.
- 9:19Right.
- 9:19Which is why, you know, wouldn't it be fun if there was some sort of project that got
- 9:24you to Python in the browser without having to do all of that boilerplate stuff?
- 9:27Yeah, I wonder if we could find one of those.
- 9:30Yeah.
- 9:30One of the things we spoke about before, Brett, was so much of what comes with Python, the
- 9:36batteries included, the standard library, assumes a slightly larger execution environment
- 9:42than front-end browser code, right?
- 9:44Like it assumes a file system.
- 9:46It assumes that you can probably open a network socket.
- 9:48These types of things, right?
- 9:50And so one of the challenges here is, well, if you can compile it down, that doesn't mean
- 9:54it's going to be permitted to just take some code and jam it in a web page and run it, right?
- 9:59Yeah.
- 9:59I mean, taking the CPU analogy, the next step, right?
- 10:02Like when you compile something down to a CPU for like X64, that's great.
- 10:08But how are you going to read a file system?
- 10:10That doesn't exist to the concept of a CPU.
- 10:12How do you make things show up on the screen?
- 10:14How do you do lots of other things, right?
- 10:17Like that's all implemented by your operating system, right?
- 10:19It's the next layer above your CPU in terms of abstraction.
- 10:22And WebAssembly only has the start of this concept in one area, which is Wazzy.
- 10:28And in another area, it kind of just leans hard into the browser space.
- 10:32And that's kind of what we call MScripten, right?
- 10:34So generally the way all this plugs together is if you look at it from a browser perspective,
- 10:39there's a tool called MScripten, E-MScripten.
- 10:42And it's basically a kind of compiler front end that uses client to compile stuff to WebAssembly
- 10:48and then has a bunch of shims into the browser to implement stuff like file access, as Nicholas pointed out,
- 10:55and all these other things you can get in a rich web environment.
- 10:59But it's provided by this project called MScripten.
- 11:01And it's not quite an OS, but it's not nothing either.
- 11:06It's this interesting kind of middle ground.
- 11:08And it's project specific.
- 11:10But then on the other side of all this, there's a project called Wazzy.
- 11:14And this is what when you think of WebAssembly, you start hearing people talking about this compared to containers or edge compute
- 11:20and all this kind of server scenarios where Wazzy acts like POSIX, right?
- 11:26So it's not actually an implementation of an OS almost, kind of like what MScripten does,
- 11:30but instead it's an actual abstraction over what you might expect an OS to provide you.
- 11:36So in Wazzy's case, for instance, it is an implement file access.
- 11:40It implements the function to call from WebAssembly that gives you the file access.
- 11:45So in that case, what you have is you have a runtime.
- 11:47And that runtime is actually what provides that level of OS that you need.
- 11:52So if you've ever heard of things like WasmTime or WasmEdge or Wasmr,
- 11:57all of these are actually Wazzy runtimes that basically load up your WebAssembly,
- 12:01inject into that code the functions that Wazzy specifies on how to read files
- 12:07or how to print to standard out or read standard in,
- 12:11and then allow them to run in an abstracted fashion.
- 12:14So it's almost half between MScripten and kind of an OS, but above WebAssembly.
- 12:21But as you can notice, it's a weird little split here because there's the web part and the server part,
- 12:27and this is where this whole discussion gets really interesting, right?
- 12:29Because it's now we're starting to have discussions about abstraction layers
- 12:32and which abstraction layers are provided where.
- 12:35And this is kind of where WebAssembly's youth, to put it one way, really shines through in terms of showing that it's all still very much actively being developed,
- 12:45which I'm sure Fabio and Nicholas have some very fun stories to tell you about with PyScript and trying to get this all working today.
- 12:51But this is where this whole OS concept kind of ties in, right?
- 12:55Where Wazzy's POSIX, right?
- 12:56Just kind of abstractions that someone has to provide.
- 12:59And then you have tools like Inscripten that try to kind of, specifically in the browser,
- 13:03just go ahead and just lean hard in the browser specs that the W3C has given us and the browsers hopefully implement,
- 13:10and just use those to implement those things that you would expect from an OS.
- 13:14So it is, as you said, an interesting problem where from CPython's perspective and most Python implementations, right?
- 13:20Historically, we've had a full operating system.
- 13:22MicroPython's going to be the exception, which Nicholas, I'm sure we'll talk about.
- 13:25But from a CPython perspective, PyPy, whatever, we're used to running on Windows, Linux, Mac, right?
- 13:32Like full operating systems.
- 13:34Like it jammed down into a tiny Raspberry Pi.
- 13:36That doesn't happen anymore because you can't buy them.
- 13:38They're unobtainable.
- 13:39But yeah, but I mean, the key point is like a full OS, right?
- 13:44Where we didn't have to concern ourselves about what was or was not available.
- 13:48But in a WebAssembly case, right?
- 13:49Like in the browser, if you use Inscripten, you only have available what Inscripten gives you.
- 13:53In the Wazzy case, you only have what's been standardized by Wazzy and that the runtime you choose to use has actually implemented.
- 13:59So we're in this interesting new kind of world where what you might expect from the standard library, for instance, in Python,
- 14:05that's always been there, like threads aren't necessarily there.
- 14:09So it actually goes back to an interesting perspective of what's Python the language versus the runtime of Python that you're using and what is provided by that.
- 14:17We're kind of going back in time in a way of kind of this clear separation of language versus implementation.
- 14:23And kind of what does that mean to us as a community and what's possible in this new space that is WebAssembly.
- 14:31This portion of Talk Python To Me is brought to you by the AWS Insiders podcast.
- 14:36When was the last time you ordered a physical server to host your functions as a service, your latest API, or your most recent web app?
- 14:44I remember the last time I did.
- 14:45That was around the year 2001.
- 14:48And yes, it was quite the odyssey.
- 14:50Of course, we don't do that anymore.
- 14:52We run our code in the cloud with near instant provisioning and unparalleled data centers.
- 14:57And the most popular cloud provider is AWS.
- 15:01But for all the ways that AWS has made our lives easier, it has also opened a massive box of choices.
- 15:08Should you choose platform as a service?
- 15:10Or maybe it's still VMs with IaaS.
- 15:12What about your database?
- 15:13Maybe you should choose a managed service like RDS with Postgres.
- 15:17Or is DynamoDB better?
- 15:19Maybe Aurora?
- 15:20No, wait.
- 15:21I hear good things about Amazon DocumentDB too.
- 15:23And that's where the AWS Insider podcast comes in.
- 15:27This podcast helps technology leaders stay ahead of Amazon's constant pace of change and innovation.
- 15:32Some relevant recent episodes include Storage Wars Database Edition.
- 15:38Macro Services or Macro Disaster.
- 15:40And exploring computer vision at the edge with AWS Panorama.
- 15:44They bring on guests to debate the options and the episodes are vibrant and fun.
- 15:49So if you want to have fun and make sense of AWS, head on over to talkpython.fm/AWS Insiders.
- 15:56Yes, I know you probably already have a podcast player and you can just search for it there.
- 16:01But please use the link so that they know you came from us.
- 16:04Thank you to the AWS Insider podcast for keeping this podcast going strong.
- 16:09It's very exciting and very fresh.
- 16:15Meaning that in a good and bad way, right?
- 16:18It reminds me a little bit of what happened with Node.js, right?
- 16:22People are like, look, we're writing all this advanced code and the browsers are getting really fast at running JavaScript.
- 16:27Like, no, no, they're not.
- 16:29Similar to Apple Silicon.
- 16:31You're like, yeah, you can't take a phone and make that your fastest computer.
- 16:33No, no.
- 16:34And then somebody does.
- 16:35You're like, wait a minute.
- 16:36Look at this thing go.
- 16:37Wow, you could have a server-side JavaScript, which I don't necessarily want to go touch.
- 16:41But it's a similar transition that we could have Python in multiple places, right?
- 16:47And it theoretically could run the WebAssembly version on the server as well for parity.
- 16:51Or I don't know if that makes any sense.
- 16:53But it's a similar transition in ways.
- 16:56Maybe in the reverse direction than JavaScript.
- 16:59Yeah, it actually has.
- 17:01It's hard to predict as you are living through things, right?
- 17:04But thinking about how Python became popular as most popular language without actually having a solid story for the most popular hardware today, which is tablets or mobile, like basically mobile phones and stuff.
- 17:21And also not having a great story for the most popular virtualization software, which is the browser.
- 17:30You know, imagining how Python will change with the WASM stories.
- 17:34I find it very interesting because it basically introduces a series of concepts that we are not used to.
- 17:40It's not just like run your environment there.
- 17:44There's a whole packaging part of the process that we need to think about.
- 17:47And how do we distribute that code?
- 17:49And that opens up for things that we haven't been used to around optimizing space and building effective bundles of your environment where we can tree shake stuff and all of those funny things.
- 18:06So I think for Python, it can be a very revolutionary moment where in five years from now, we're looking at a different ecosystem, hopefully bigger and better.
- 18:17It did something on us to sort of adapt and change and make the most of the opportunities to the WASM presenters.
- 18:25But as Brett and Fabio have said, it's a strange world in that it's not like I've got a libc and I know I'm going to be able to get to the file system and things like that.
- 18:35There are these kind of shims and slightly different abstractions that may make Python feel like it's, I was going to say, a duck out of water.
- 18:45Snake out of water?
- 18:46I don't know.
- 18:46You know what I mean?
- 18:47It's not in its natural habitat.
- 18:48Water moccasin.
- 18:49But I think I'm pretty confident and bullish about the Python community and our ability collectively to find a way forward with this.
- 19:01You know, we've got a beautiful language.
- 19:03Let's bring it to WASM.
- 19:04We do.
- 19:04And many people love it.
- 19:07And, you know, when people say, I love Python, they might mean the language.
- 19:11But usually I think that's only a part of it.
- 19:13Right.
- 19:13Often that's the ecosystem and this whole broad.
- 19:16Right.
- 19:16All the packages and all the people on the projects.
- 19:18And in that sense, like Python is very much empowered to make some really cool transitions there.
- 19:23We don't have to always kick it back to the core devs for all the work.
- 19:26Although, Brett, congratulations, I guess, on 3.11.
- 19:30Right.
- 19:30I mean, you guys, that's a big deal.
- 19:32I only, I did a small amount, but I thank you.
- 19:36It seems to have been taken very well.
- 19:38The community seems to have picked it up faster than usual, which has been really fantastic.
- 19:43Dependencies seem to have been ready for this and got wheels out early, which was great.
- 19:48Because it made transitioning a lot easier.
- 19:49So kudos and thanks to the community for putting in that effort to get stuff ready to go as of October.
- 19:54So that when things launched and we were able to do that .0 release, people were able to just install it, download packages, and have the wheels ready to go.
- 20:02And it went pretty smoothly.
- 20:03Yeah, that's awesome.
- 20:04Either of you, other guys, have any contributions to 3.11?
- 20:07Yeah.
- 20:08No, we are happy consumers.
- 20:10Yes.
- 20:10Exactly.
- 20:11Exactly.
- 20:12All right.
- 20:13One other concept, which I really want to quickly throw out there and just get your thoughts on.
- 20:18Don't want to go deep on this.
- 20:19But one of the things that seems to me like an interesting benefit for WebAssembly is the interoperability with other languages.
- 20:27Like WebAssembly can call WebAssembly.
- 20:28So if somebody could compile their Rust or their C# or their, you name it, over to WebAssembly, you might be able to consume libraries in a broader way than you can now in Python.
- 20:40What do you think about this?
- 20:41Yes, or is this just Dreamit?
- 20:42I think the answer is you could.
- 20:43But I also refer the honoured gentleman to my esteemed colleague, Brett, to the earlier answer about this being relatively immature space as well.
- 20:51I mean, to be honest with you, I used to be a .NET developer before I came to Python.
- 20:55And the fact that .NET has this notion of the CLR, the common language runtime, to which C#, C++, Visual Basic, F Sharp, I and Python, I don't know, whatever compiles to.
- 21:06It feels like it's a very similar space as you're implying, Michael, as to what.
- 21:11Yeah, though the Blazor actually is like incredibly near with what they're doing, which is I haven't done anything with it, but it looks quite impressive.
- 21:20There's a piece of tech we can quickly touch here.
- 21:22Is there something, and I think it's actually on the page you're looking at right now if you're watching the live stream, it's right below the fold.
- 21:28The important note, Wazzy is in transition.
- 21:30The transition part is there is work towards something called the component model, specifically in Wazzy, which is defined more or less what you're talking about, Michael, which honestly feels like Korba for the new millennia.
- 21:43To date myself, or at least date my PhD supervisor who did his PhD relating to Korba.
- 21:49You said Korba, right?
- 21:50I've not thought about that since like the year 2000.
- 21:52But the thing here is the component model is a spec being worked on that's meant to be able for you to specify at the WebAssembly level kind of the API that your WebAssembly code exports, right?
- 22:05I mean, for the Python audience, you can think of it as almost the CPython API, right?
- 22:09It's kind of like what does CPython export out, and then what can you use from your extension modules?
- 22:14It's a similar thing, except it's done at the WebAssembly level.
- 22:16So you can just say like, okay, this function will return a string.
- 22:21And then there's a definition of what a string is for WebAssembly.
- 22:24So that when you say, oh, internally, I might use UTF-16, but a string in the WebAssembly component model context is UTF-8.
- 22:31So you have to encode out to UTF-8.
- 22:33And the other side, you go, oh, hey, I'm going to call this function.
- 22:35Oh, it gives me a string.
- 22:36I know that's going to come as UTF-8.
- 22:37If you can keep using it that way, great.
- 22:39If you have to change it to UTF-32 or something, you can.
- 22:41But it's defining the seam of your WebAssembly module and what it looks like in terms of what it exposes to other people.
- 22:49So that's that big dream you mentioned of people writing stuff in other languages that we can just consume directly from WebAssembly.
- 22:55But there's obviously, as Nicholas pointed out, immature stuff in this community where we have to figure out how do we even expose that from the Python side, right?
- 23:04Like, I don't even know technologically what we would do to make that work in terms of pulling another WebAssembly module.
- 23:10Because honestly, it's basically like linking.
- 23:12But we don't have that concept of linking in Python.
- 23:14You just run an import statement.
- 23:16There's no header, no definition of what's on the other side.
- 23:18Exactly, right?
- 23:19And that's exactly what the component model does, right?
- 23:21It's an interesting position.
- 23:23Actually, credit to Peter Wang, who you can save the love slash hate toots to later on this analogy.
- 23:29But up to this point, right, a lot of the WebAssembly world has been these languages that are compiled, right?
- 23:34Like the C and C++ and the Rust stuff, like where you just pull in all your code, you compile it, and it all just kind of works.
- 23:39And it's very much set up in these worlds where, oh, yeah, it's statically compiled, whatever.
- 23:44As you said, header files, it kind of comes together.
- 23:45But we come from this world where people have poured all this time and energy to wrap all of this esoteric C, C++, Fortran even code, and give us this nice API in Python.
- 23:58But once again, Python doesn't operate like C and C++ and Rust and all these other statically compiled languages where we have these concept of these interfaces, and they just load it, plug it right in.
- 24:07And it just works like, no, we're going to import some Python code, and it's going to execute as part of import, right?
- 24:13Like, I don't know how many people know that, but literally the way import works is it calls exec on your code, right?
- 24:19Extension modules use some really crazy chips from glibc to pull in that data off that module, which we don't have in WebAssembly and stuff.
- 24:27So there's a potential disconnect here at the moment.
- 24:30And hopefully, as Fabio said, in five years' time, we can kind of work together to kind of work with the WebAssembly community to make this solve the problem.
- 24:37But as of right now, that component model is not designed for us, the Python community.
- 24:42It's designed more for the C, C++, Rust world.
- 24:44And we're probably going to have to work with them to try to figure out how to make that work with us.
- 24:48Because to be frank, we're bleeding edge in terms of a dynamic programming language with an interpreter as we are coming into this and not being a compiled language.
- 24:56And I think we're going to be, I don't want to say bringing the WebAssembly world kicking and screaming.
- 25:00I think they're just, we haven't fully introduced ourselves yet.
- 25:03And I think they're going to come to get to know us, and we're going to start bringing in some new stuff.
- 25:07So I don't think we're quite ready for this whole magic bringing in other WebAssembly stuff.
- 25:11But hopefully, we can work with them to make that happen.
- 25:13Because as of right now, it's not in the cards.
- 25:15Yeah.
- 25:16I'd like to make a comment on this one.
- 25:18Because it actually is a topic of, we have the running joke inside the PyScript team where Antonio Cooney and I always argue about everything.
- 25:29Or argue, discuss.
- 25:31And this is a big topic of discussion.
- 25:34Because Antonio is more lower level.
- 25:37And very smart.
- 25:38And I look at things more on the higher level side.
- 25:41And I often tell, I really want to see Python working alongside with R or other languages for data science.
- 25:50Or just, I would love my kids to be using Python to drive a gaming library in JavaScript on the browser or something like this.
- 25:57And it's like, it's never going to work the way you want to.
- 26:00Because you don't know how types are going to be translated into WASM for different languages.
- 26:06And yada, yada, yada, yada.
- 26:08But one bridge that we have right now is JavaScript.
- 26:12And having proxy objects in JavaScript that relates to Python on the browser or Rust or things can be a possibility, too.
- 26:21But in general, I think what I always end up saying to Antonio is like, we're kind of in creative mode right now or experimentation mode where we can try stuff.
- 26:34And maybe it's not the right way.
- 26:35And maybe it's not the right way, but it may work 90% of the time, which gets a lot of work done for a lot of people.
- 26:42So in the meantime, we'll figure out the correct way and how different languages will actually talk to each other or what it means for WASM.
- 26:51Anyway, I think it's interesting.
- 26:53This is such an interesting conversation on so many levels because, you know, Brett mentioned Corbett, which is like this thing from way back when, before I was ever a software engineer.
- 27:03Okay.
- 27:04And Fabio is talking about how, you know, he has a high level view.
- 27:08Antonio, you know, from PyPy has a very different perspective on this.
- 27:12And I would say that, and also Fabio's pragmatism as well about what we need to get something to work because then we can do cool stuff with Python in the browser.
- 27:23And basically what I'm saying is that you need both of those attitudes, the Antonio and the Fabio and bring them together because that's when interesting things happen.
- 27:30And I'm not saying it's interesting watching these two have an interesting discussion in our morning standups or whatever.
- 27:35But what I'm talking about is that that's the intellectually stimulating thing because you have two different perspectives.
- 27:41And if like Fabio and Antonio are, they're excellent engineers and they can see and empathize with what the other person is talking about and adjust their position.
- 27:50And then eventually we kind of zone in on various potential solutions, which kind of goes back to the Corbett thing, which is why I brought it up, is that, you know,
- 27:59I remember meeting an old gray beard programmer when I was a young whippersnapper and he was, I can't remember, something had been announced and I was like, oh, this is amazing.
- 28:08It's going to change the world in that way.
- 28:10Young programmers.
- 28:10And he was like, oh yeah, we were doing this in the seventies with punch cards or something like that.
- 28:15And so once again, that sort of, we have this cyclical nature in the history of programming where, you know, we're, we're coming back to these kinds of archetypal solutions implemented in different ways.
- 28:27And you can actually see perhaps that the whole was and wassy thing as yet another iteration of this, because we're rethinking what a computing platform is.
- 28:36It's this virtualized thing and it's taken us maybe 20 or 30 years to get to that new space after lots of different experiments.
- 28:43Right.
- 28:43We're still going to be flapping around like headless chickens, trying to figure out how to make the damn thing work because all of this stuff keeps moving on.
- 28:50And that's called progress folks.
- 28:52But you know, this is why it's so interesting.
- 28:54This is why I'm a software engineer is because I get to work with clever people on interesting problems that if we get it right, a bunch of 11 year olds in the school down the road from me are going to be able to build Python applications on a little device like this using PyScript.
- 29:13And you know, that is something to work for.
- 29:16Yeah, that's fantastic.
- 29:17And if you don't like the tools.
- 29:19And just for the podcast, a little device was the phone.
- 29:22Yes.
- 29:22Sorry, Fred.
- 29:23By the way, we're not we're not paying Nicholas for every pitch on PyScript.
- 29:30It's out of his heart.
- 29:32He does an amazing job.
- 29:34Let's talk about a little bit about MicroPython.
- 29:38You know, MicroPython is amazing.
- 29:40I recently sitting around my desk stuck Velcro to one of the hosts of my desk is one of these ESP feather 32s.
- 29:5032 feathers.
- 29:51I don't know how other.
- 29:52Yes.
- 29:53Those words.
- 29:54Thank you.
- 29:56device running Python connected to my Wi-Fi, syncing a bunch of stuff on the cloud and just had a little thing.
- 30:01It blinks every now and then to tell me everything's cool.
- 30:03It's it's doing its job.
- 30:05And it just these are amazing.
- 30:06And yeah, I mean, I know circuit Python is not identical to MicroPython, but they're very near and they've been brought closer together as well, which is great.
- 30:14So if we download the entire CPython runtime over WebAssembly, it's not totally small, right?
- 30:20It's about 11 megs.
- 30:22Yeah.
- 30:22Which we have fast computers.
- 30:24But on the other hand, you wouldn't put it on like a public site that's there to load quick and be fast for SEO and all these things.
- 30:31Right.
- 30:32This portion of Talk Python To Me is brought to you by the Local Maximum Podcast.
- 30:39It's an interesting and technical podcast that dives into trends in technology, stats and more.
- 30:44But rather than tell you about it, let's hear from Max and Aaron about their show.
- 30:48We are now on with Talk Python To Me.
- 30:52Let's say hi to all the Python fans.
- 30:53Hi, Python fans.
- 30:54I'm Max Sklar.
- 30:56I have actually done a lot with Python myself, so I am a fan of Talk Python.
- 31:00Do you know Python, Aaron?
- 31:02I took a course years ago, but I am a little rusty.
- 31:04We are here today to talk about our podcast, The Local Maximum.
- 31:09We've been on a roll lately with a new episode every week,
- 31:12and I wanted to share with you what we've been up to.
- 31:14Here on The Local Maximum, we tackle subjects in software and technology,
- 31:18topics as diverse as the philosophy of probability to Elon Musk's next move.
- 31:24For Talk Python listeners, I want to highlight a couple of recent episodes of The Local Maximum.
- 31:28In 248, for example, I found out about an open source library that maps the world into hexagons.
- 31:35And some pentagons.
- 31:36I had a discussion with an author about games and puzzles and another on a novel approach to doing the job search well.
- 31:41We discussed the ramifications of AI-generated art.
- 31:44Have we reached peak creativity, or is this just another Local Maximum?
- 31:49So check out The Local Maximum podcast available on your podcast app.
- 31:55But you do have this project called MicroPython.
- 31:57Maybe tell us a bit about that.
- 31:58That's smaller, right?
- 31:59Okay.
- 31:59So MicroPython is the wonderful creation of Damian George.
- 32:05Damian is a physicist by training.
- 32:09He once told me what his PhD thesis title was, and it's something like 11-dimensional.
- 32:14And then he lost me.
- 32:15But he was at Cambridge, and one of his hobbies or part of his background in his studies was working with robotics.
- 32:24And he was part of the Australia team that entered the Robo World Cup for Americans.
- 32:30That's soccer, as it were.
- 32:32Which is rather appropriate, given the fact that the World Cup for Human Beings is happening right now.
- 32:38But what he wants to do is write a scripting language so that they could very quickly update what was going on in these robots.
- 32:44Okay.
- 32:44And he learned a lot by doing that and then realized, well, actually, perhaps if I take the things that I've learned building this stuff to a proper scripting language, then that'd be a cool project.
- 32:58And so he looked around thinking, well, what are cool scripting languages?
- 33:02And arrived at Python.
- 33:03Created an early version of MicroPython, put it on Kickstarter, thinking that he could sell a few boards, make a little bit of money, and, you know, MicroPython would be there.
- 33:14Well, I think $100,000 plus later, and, you know, lots and lots of forders for boards later, MicroPython was, you know, has become this amazing success.
- 33:25And the whole point of my...
- 33:26Oh, no, I caught the car moment, right?
- 33:28The dog that caught the car, like, here we go.
- 33:31Yeah.
- 33:31Yeah.
- 33:31Well, it rather surprised Damien, to say the least.
- 33:35But now MicroPython is designed to run in highly constrained environments.
- 33:40So, for instance, I believe it can work with only 16K of RAM, for instance.
- 33:47Clearly, when you're running it on your board, actual Python is running on the flash memory rather than the RAM, which is something different.
- 33:55And Damien pulls an awful lot of tricks to actually make it work really efficiently.
- 33:59But because he's a physicist, he knows how to do experiments.
- 34:03And so that's what he does, literally.
- 34:05He tries to work out, how can I get this big fat snake that's just eaten an elephant and squash it down into this small space so that we can still have a full re-implementation of Python 3 on something that maybe has 16K of RAM, like, I don't know, a microbit.
- 34:24Unsurprising, I have a box of microbits on my.
- 34:26Oh, yeah.
- 34:26Beautiful.
- 34:27And CircuitPython is a friendly fork of MicroPython by the wonderful folk at Adafruit.
- 34:32So, you know, it's, I think it creates an interesting dynamic because MicroPython is perhaps the industry version, whereas CircuitPython provides a consistent API for all the Adafruit boards.
- 34:44It's aimed at education.
- 34:46They've got a whole bunch of sort of tutorials and support for that sort of stuff.
- 34:50And they're forever bringing out incredible new devices, as I'm sure we've all picked up at PyCon, you know, the Circuit Playground Express.
- 34:56Yeah, exactly.
- 34:57Great conference band.
- 34:58So that's MicroPython in a nutshell.
- 35:00So what's it doing on Wazen?
- 35:02Well, it's because 16 megabytes is rather a lot to try and download even today over a 4G network.
- 35:09And these devices, subtitles here, this is a phone I'm holding up, are underpowered compared to the rather beefy MacBook sort of using to talk to you now.
- 35:18And so the, one of the first things I did when I joined Anaconda was just see, well, what happened if you run it on a mobile phone?
- 35:26And it took 16 seconds to get to Hello World, which is not an optimal kind of solution.
- 35:32So what would work?
- 35:34And very quickly, you know, I came to playing around with MicroPython and MicroPython is, you know, under 100 milliseconds to start up and get you to Hello World.
- 35:45It's fast enough.
- 35:45And you've got, so here's the interesting thing.
- 35:47I'm interested to hear what Brett says here.
- 35:50It's a full re-implementation of Python 3.
- 35:52However, there are differences.
- 35:54And so we get to Brett's rather interesting angle of, well, what is Python in the abstract and in the actual detail of implementation?
- 36:01And we've kind of got this platonic Python, this ideal Python that doesn't actually exist.
- 36:06And then you have all of these implementations of which, of course, the C, the CPython version is the, is the touchstone.
- 36:12But MicroPython doesn't have all the APIs.
- 36:15It doesn't have the full standard library.
- 36:17And depending on the size of the device, it might not even support floating point numbers, for instance.
- 36:22But it's Python.
- 36:23It's the Python that we love.
- 36:25You've still got indentation in the white space that annoys the C developers or whatever, you know, so it's good enough for me.
- 36:31So we can compile this much, much, much smaller, more lightweight version to WebAssembly and do similar things.
- 36:39But instead of downloading a whole huge thing, maybe it's a light little thing that still lets us write Python and do front end stuff in interesting ways.
- 36:47Yeah.
- 36:48All right.
- 36:48When I talked about speaking back in 2019, I guess it was in Cleveland, we did touch on, well, if you're not going to be able to do all the Python things, how do you define like a standard Python?
- 37:00There's, you know, and way back in Greek philosophy and the platonic Python, if you will.
- 37:06Platonic idealist language.
- 37:08The essence.
- 37:08Yeah.
- 37:09I mean, you're a philosopher, you know.
- 37:10Oh, yeah.
- 37:11The essence, like the core that, like, this is the little bit we circle and say, oh, Python does this.
- 37:17Like, what is your thought on this micro invasion of Python in the front end?
- 37:21Well, I have to be very clear on my bias here.
- 37:24I'm somewhat notorious as having written the PEP that causes all accelerator modules written in C for CPython to have to have a Python equivalent specifically so that projects like MicroPython and PyPy weren't left behind from the standard library so that they could just work and not have to re-implement the C API for key things like the date time module.
- 37:44So I have a massive bias in this statement, to be very clear.
- 37:47So I am not representing necessarily the entire Python core development team or the steering council on this.
- 37:53But for me, it has always been a separate concept of what the language is and what the reference implementation is, right?
- 37:59Like, we may do development of the language using the CPython reference implementation.
- 38:05And I am very specifically using the term reference implementation as a way to help make the language evolve.
- 38:12But for me personally, they are two separate concepts.
- 38:15These happen to be developed simultaneously and by the same group.
- 38:18And it's mainly for convenience and just be able to work faster.
- 38:22But I do view them as separate things.
- 38:25And it does make sense, right?
- 38:26Like, there are people on the Python core team who are way more into the esoteric bits of the language spec and how the language functions.
- 38:34And some people just care about the eval loop that makes CPython run, right?
- 38:39The big switch statement you mentioned earlier, Michael.
- 38:41So for me, this is totally great.
- 38:43Like, we have versions of the language specified in the language spec, which, to be fair, is not a spec from a, like, ECMA or ISO level standard.
- 38:55But hopefully good enough for people to be able to follow to implement the language.
- 38:59And to me, that is really what people are targeting.
- 39:02I honestly, once again, major bias showing here.
- 39:05I don't consider the Styron library part of the language.
- 39:07The Styron library is a very key piece of functionality and a key convenience and potential differentiator for Python in some people's eyes.
- 39:17But I do not consider it part of the language.
- 39:19It is just something that we have developed over the years that has helped accelerate Python's growth.
- 39:25Because back in the day, batteries had to be included because, guess what?
- 39:30We didn't have PyPI.
- 39:31Like, Vaults of Parnassus had little animated GIFs of a website where you downloaded zip files and you unzipped your stuff.
- 39:37Everyone vendored everything because there was no installer.
- 39:40There was no pip, right?
- 39:42Like, showing my age in the Python community, right?
- 39:44Like, we had to do the batteries included thing.
- 39:46Did you un-UU encode it off of Usenet to get your package?
- 39:52No, no.
- 39:53I was not that far back into programming that, I mean, I used Usenet, don't get me wrong, but I was not coding at the time when Usenet was the way to Netfeed.
- 40:02But, I mean, it was kind of just like, it's wherever it ends up.
- 40:05You grab it and you put it in your project and you run with it, right?
- 40:07There wasn't a central location for these things.
- 40:10And so, to me, there's a very clear separation here.
- 40:12And I personally view the Styron library as a thing that represents the time of when it was created.
- 40:18But, to me, it has never been the language.
- 40:21The language is what's in the language guide and more or less what's built in.
- 40:25And that's kind of it.
- 40:28The import statement brings all this wonderful stuff in for you, but that's not the import statement's part of the language.
- 40:33But what you can import into it, unless it's like Dunder future, right, which is baked into the language definition, I don't consider that part of the language.
- 40:41And I've said this controversially once on the former website that we all used to hang out on before Mastodon, where I actually said, like, the REPL, for instance, is not part of the language either, technically.
- 40:51If you think about it, it's a wonderful tool.
- 40:54And don't get me wrong, it definitely makes Python more useful.
- 40:56But for me, personally, the REPL is not part of the language either.
- 40:59It's just something we all ship because it's so useful to use and Python enables that kind of development process.
- 41:06But so MicroPython saying it targets Python, I believe, technically 3.4 with extras means it is an implementation of Python for Python 3.4.
- 41:16And that's great.
- 41:17And whether it comes with everything that the standard library that CPython had for 3.4 is a positive, is a plus what it has.
- 41:23But to me, that's not the language.
- 41:25And to me, they're very clearly separate concepts.
- 41:27It's just people get very spoiled when they just download CPython.
- 41:31Well, my code doesn't work over here.
- 41:32It's like, well, you can view CPython almost as a platform.
- 41:35And this platform just doesn't have the same platform.
- 41:37The same language, just different platform.
- 41:39And to me, that's fine.
- 41:41That just is what it is.
- 41:42So it sounds like you're okay with the micro invasion.
- 41:44Oh, yeah.
- 41:45I care about the language, right?
- 41:46If CPython is the way you get it, fantastic.
- 41:49If you get some other way, that's also fantastic.
- 41:51I personally care about the language.
- 41:52And I mean, we all know the community that comes with the language more than the implementation.
- 41:57And the fashion.
- 41:58Don't forget the fashion.
- 41:59And the fashion, yes.
- 42:00No, go ahead.
- 42:01I was going to say, before we pressed record, that was a running joke.
- 42:04But bring us back to the serious conversation, Nicholas.
- 42:06Brett Sandals.
- 42:07So the more serious point I was going to make is that what Brett just said is actually easy to miss, but of vital importance.
- 42:16Which is if you're coding with, say, for example, MicroPython, you can't expect your code to work with CPython and vice versa because of the differences in the platform, the wider platform ecosystem that you might have.
- 42:28Mostly the behavior is the same, although there are some very subtle differences.
- 42:33Yeah.
- 42:33It's mostly the experiments I've been doing where I've been using Pyodide as the sort of the reference and MicroPython as the sort of the thing to compare.
- 42:43I can just slot one in and slot the other out and PyScript sits on top of it.
- 42:48And I can make things work as I want to.
- 42:51When I'm testing Python things, there's a whole conversation, which I think I can see coming down the tube right now about how do you interact with the DOM and things like that.
- 42:59We'll get to that when we get to it.
- 43:01But it's mostly the same.
- 43:02But folks should know that they are different.
- 43:05And well, there you go.
- 43:07I'm just flagging that.
- 43:08I need to flag that.
- 43:09Yeah, absolutely.
- 43:10All right.
- 43:11Quick question from the audience here.
- 43:12Glenn says, do you think more stuff needs to be removed from CPython?
- 43:16I mean, I know actually that was one of the things that the 3.11 release addressed was a bunch of modules were either removed or deprecated.
- 43:24I think, Brett, we spoke about that a year ago or something, maybe, if I remember.
- 43:28Yeah.
- 43:29Christian and I came on maybe, yeah, almost a year ago.
- 43:33Not to the day, but maybe to the month or October last year.
- 43:36We came on here and talked about us removing modules from the standard library.
- 43:40Yeah.
- 43:41To directly talk about this, once again, personally, not speaking on behalf of any other group.
- 43:46I think we, I've actually put myself back up for the Python steering council.
- 43:52And one of the things I put in my self-nomination is I want to have a discussion about what the standard library is, which evolves around how do we want to evolve it, maintain it?
- 44:02What would go in there today if we were to have guidelines?
- 44:04Because we actually don't have guidelines on what should go in.
- 44:07Historically, it's just been a core dev has gone, I want this in.
- 44:09And people just kind of, in general consensus, go, okay.
- 44:12Or honestly, I'm going to add this.
- 44:14And they sometimes have added it because five or some odd core devs all agreed to it and just kind of goes in.
- 44:19And they just didn't think to have a wider discussion.
- 44:21Like, not going to go down details on that one.
- 44:23Anyway, point is, it's not had any guidance to it.
- 44:27And it's a discussion I want to have.
- 44:30And I don't know if it's going to lead to a shrinkage of the standard library just because, once again, from a CPython perspective, there's compatibility to consider.
- 44:37Right?
- 44:38And we don't want to just rip stuff out.
- 44:39But it is possible we might start deprecating more stuff, right, beyond what the dev batteries were.
- 44:44Because the dev battery list was very conservative.
- 44:46Basically, if almost anyone brought up any objection to something, we left it, whether we thought it was reasonable or not.
- 44:52So I can very much see a future where we maybe have a list of like, yeah, this stuff's here, but don't really rely on it.
- 44:59And obviously, MicroPython probably doesn't already ship that stuff now anyway.
- 45:02But yeah, personally, I would love to see the standard library a bit smaller, if for any other reason that it just makes it easier to maintain.
- 45:09Because there used to be, before the dev battery PEP, more modules than there are countries in the world.
- 45:14So like, I think, 198.
- 45:15So there's a lot of stuff in there.
- 45:18And we can probably stand to shrink it.
- 45:19And once again, it kind of makes it a little easier for other projects to not git pushback from people.
- 45:24And like, well, where is this module?
- 45:26It's in CPython.
- 45:27It's like, well, we don't have it.
- 45:29Well, why not?
- 45:30It's like, if it's not there to begin with, it makes their lives a little easier to not have to try to support it and push back to people.
- 45:35It's like, it just doesn't make sense for us as a platform.
- 45:38Right.
- 45:39And as we talked about before, some of these things being included came from a different time, for sure.
- 45:43All right.
- 45:44Well, I remember when I got one gopher lib.
- 45:47So it's also worth noting.
- 45:49But Archie, we're going to keep, we're sticking with Archie.
- 45:51Sorry, go ahead.
- 45:52No, no.
- 45:52I was saying, those batteries have a cost.
- 45:55And every time you have to run limited devices like MicroPython or the browser, like you realize that.
- 46:02And then the question becomes, well, is that user base significant to the Python project to make a change on those?
- 46:10Right.
- 46:10Like, and that comes with conversation and evolution.
- 46:13So I think probably.
- 46:15It's always a trade-off.
- 46:16You say, let's remove TKinter because it's a GUI from the mid-90s and nobody uses it.
- 46:22And then everybody points out that the Turtle module mostly uses TKinter and teachers all over the world will scream, you know, and you've got a big problem.
- 46:33So it's a Gordonian knot.
- 46:37Sure is.
- 46:38All right, let's bring in the third major project here, which we've touched on a few times.
- 46:43But Fabio, tell us about PyScript.
- 46:45What a cool project.
- 46:46Cool.
- 46:46Thank you.
- 46:47Yes.
- 46:47Where does it fit in this Pyodine, WebAssembly, MicroPython world?
- 46:52What's the angle here?
- 46:54I think it fits as a glue.
- 46:57Well, pretty much like Python was glue for a lot of things.
- 47:00Like the concept of PyScript was really, you know, realizing that a lot of, most of the technology for Python to run the browser is there.
- 47:08And it's been there for years now.
- 47:10And what we're missing is the easiness to just use it without being, you know, without having to spend hours or days looking for how to import things or, you know, the JavaScript side of it, what it means on the browser, as a web dev to start using Python.
- 47:29So the idea was really like, like, can we call it?
- 47:32Because it's one thing to have WebAssembly.
- 47:35Sorry, it's one thing to have WebAssembly see Python.
- 47:38It's another to build meaningful things in the browser with that as a piece.
- 47:42Right.
- 47:42And so PyScript kind of gives you a framework to write Python code in the browser based on this WebAssembly.
- 47:48Right.
- 47:49Correct.
- 47:49It's not a framework.
- 47:50It's a platform.
- 47:51And we fully expect people to write Pythonic frameworks on the platform that is PyScript to do whatever funky stuff they want to do in the browser, their business.
- 48:02And, you know, I know that I trust the Python community will come up with something that we can't even begin to imagine now.
- 48:09But the thing to do is remember that PyScript is that sort of platform layer rather than a framework.
- 48:16But in that platform, what we're looking at is perhaps pluggable runtimes and a bare minimum of APIs and heuristics and ways of working such that you can start to build your frameworks on top of this and make the funky stuff.
- 48:29Michael, like you said, that's useful for folks.
- 48:32Well, OK.
- 48:32Well, so we might have Pyodide, which is a more full featured version.
- 48:37Might we have MicroPython for a fast, speedy version?
- 48:40Yeah.
- 48:41And there are other projects as well that are coming up and or other languages, too.
- 48:48Right.
- 48:48So that's definitely in the.
- 48:51But that'd be interesting.
- 48:52Exactly.
- 48:53There was a big announcement that got thrown in here.
- 48:55We'll go this way.
- 48:56We'll go with Simon Willison, who was on the previous show about Mastodon, previous episode.
- 49:01And he has a toot, which, by the way, I don't know, Brett, you said toot as well earlier, but they just the button on there used to say toot until like last week.
- 49:10They just call it publish now.
- 49:11I think they're downplaying the toot, but it's going to live on.
- 49:13The toot said huge Python WebAssembly news tucked away in this post from Anaconda here.
- 49:18When you apply MicroPython to WASM in its default configuration, something new and exciting emerges.
- 49:23With a total size of 300 kilobytes, this new runtime builds instantly and starts executing MicroPython logic in less than 100 milliseconds.
- 49:32That means the cost of running MicroPython on the web is now equivalent to serving up a large hero image.
- 49:38This is awesome, you guys.
- 49:39Where are we going with this?
- 49:40Whenever you meet Damien, you buy him a beer is pretty much what I would suggest.
- 49:44Although not too many.
- 49:46Once in sober.
- 49:51Yeah, this is fantastic.
- 49:52Because if we do have a really small runtime, then all of a sudden you could.
- 49:56So when people saw PyScribe and Fabio, they're like, oh my gosh, could we replace JavaScript with Python?
- 50:01And the answer was sometimes, but not in general, right?
- 50:05Yeah.
- 50:05Yeah.
- 50:06Not practically.
- 50:06This is Paul Everitt, who's been around the Python ecosystem for a lifetime and is really great.
- 50:13And we were talking about that and Python for web during PyCon.
- 50:18And he often comes up with this distinction between the app web versus the content web, where in terms of content web, you need things to load immediately.
- 50:29And you're mostly wanting to show content rather than a full-blown application.
- 50:34And I think he still thinks Python is not going to be a reality for the content web.
- 50:40I think this brings it really, really, really close.
- 50:44And you can have basically Python running for content, but also the amount of possibilities around education, around exploration in real time and stuff like this is tremendous.
- 50:56And if we can actually, as a community, gather and understand how we want to build layers on top of other things, I think we can come up with really interesting solutions.
- 51:07And let me explain.
- 51:09MicroPython, for instance, doesn't have a JavaScript interface, right?
- 51:15So if we could have a module, maybe it's the Pyodide one that we strip out or we develop a new one where we can explore that Python to JavaScript interface and make it available for all the interpreters.
- 51:29And it's just like a package and you can install it.
- 51:32We open up a new channel or the whole packaging story for Python on the browser.
- 51:39And if we can figure that out in a way that, you know, we can just install packages and doesn't matter the interpreter because it all end up like being WASM, then I think we can build a very strong ecosystem where if you need more complicated things, you run with your full CPython and WASM interpreter.
- 51:58Otherwise, you can just use MicroPython.
- 52:01But I think right now is the time where we start doing those things.
- 52:06Coming from the Anaconda world, there's one view of like, what does Python computation mean, right?
- 52:12Often that means kind of notebooks and data science and like scientific computing.
- 52:17And there's a big desire to sort of move that to the front end and just say, let people run that on their computers and they can do kind of like notebook things on the front end.
- 52:27But there's a whole other side of the web that says, I want to build Gmail, but not in JavaScript on the front end.
- 52:34But I want that interactivity or I want maps or I want, you know, most modern highlight dynamic single page app type of web apps.
- 52:43But I want to write that in Python.
- 52:45That to me feels like that's almost the dividing point of like, well, we want the Pyodide runtime where it's rich and we can just straight grab Matplotlib and run with it or Pandas versus I'm willing to give up a lot to not write JavaScript.
- 53:00You know what I mean?
- 53:01If I've got to only use a few packages and I could still write Python end to end, that makes me super happy.
- 53:06As you said, like we can augment the things that Python can do.
- 53:10Like if we all of a sudden have access to the browser APIs for geolocation or other things, then you can write very interesting applications that is just Python or, you know, even a mobile and stuff like this because WebAssembly can run on mobile as well.
- 53:25So, yeah, the competition between all the arguments framing PyScript versus JavaScript, I think they really missed the point where it is augmenting both ecosystems.
- 53:37Like right now, we now can use D3 in Python and vice versa.
- 53:42JavaScript developers can use NumPy or Pandas.
- 53:45It's a win-win, to be honest.
- 53:46Yeah.
- 53:47One of the things I think maybe people when they hear this don't necessarily know, and I forget which is maybe the best one to look at.
- 53:54But not only can you run Python code in the browser with PyScript, but you can hook JavaScript events and then you can change DOM elements.
- 54:01This was the JavaScript DOM interaction layer you were talking about before, right?
- 54:05Yeah.
- 54:05Yes.
- 54:06And actually to what Nicholas was saying about the difference between that we want to really sell the point that PyScript is a platform.
- 54:16We're currently working on plugins where we want developers to actually write Python code to add custom elements to the DOM as well, right?
- 54:26And not use any JavaScript.
- 54:27I hope we can get it in this next release, but for sure before the end of the year, we are allowing that.
- 54:34And it's going to be a huge improvement in how what people can do with PyScript and actually how can people extend the platform creating new frameworks.
- 54:43So are you envisioning or are you at least aiming for, if not fully envisioning, something like PyView or PyReact or like some of these traditional front end frameworks, but a Python equivalent?
- 54:56Nicholas?
- 54:57That's a loaded question.
- 54:58I think.
- 54:59A Pyangular?
- 55:00No, just kidding.
- 55:01Pangular.
- 55:02I think that it makes a great story if you're a journalist that Python's going to come up and eat JavaScript's lunch in the browser.
- 55:12That's a false dichotomy.
- 55:13That's a great way of getting clickbait and things.
- 55:17If you want to write, you know, app, web-based app stuff, and you're familiar with JavaScript and React, you know, just use the tools that empower you to write the stuff that you want.
- 55:30But for the quartet of us in this conversation, we're all Pythonistas.
- 55:34We all appreciate the aesthetic of that language and the way it works.
- 55:40And so I would go back to the difference between a platform and a framework point from earlier on, which is it's going to be fun to trust the community, our remarkable community, and see what interesting things, what itches that they scratch.
- 55:55So that they create fun stuff and feedback to us, ways in which we can improve the PyScript offering, because this is a story that's going to keep going.
- 56:03You know, software is never finished.
- 56:06But I think that one thing I hope, and if I'm honest with you, this is really why I joined Anaconda, was to help think about these things.
- 56:16Exactly the question that you've just asked, Michael, you know, what about all of these kind of things of building apps with Python in the browser?
- 56:22Well, what I found is that I need to dig a bit lower to do some more cool PyScript-y things, and then dig a bit lower to look at perhaps what the runtimes are doing and blah, blah.
- 56:30And here I am messing around with, with MicroPython now, but hopefully I want to sort of surface, as it were, and get back to what I thought I was going to be doing, which is thinking about these sorts of things.
- 56:41And what I really hope to do, or what I really hope to see from the Python community as well, is engagement in frameworks that will empower people.
- 56:50And I'm thinking of the educational sphere as well here, because let's face it, I don't know if you've ever faced 30 teenagers on a Friday afternoon and somebody's introduced you as Nicholas, a coder who's going to teach you about Python.
- 57:03There's nothing more intimidating than that.
- 57:05And let me tell you, print hello world doesn't cut the mustard.
- 57:09Okay.
- 57:09This is not exciting for them.
- 57:11But if we can make something.
- 57:14I want to build this thing.
- 57:15I saw an Unreal Engine 5 in Python.
- 57:17Exactly.
- 57:18Exactly.
- 57:19Exactly.
- 57:19But if we could make it so that they can do the equivalent of, you know, the MySpace.
- 57:25Hi, hi, Nan.
- 57:26I'm on the internet.
- 57:27You know, within two minutes, you've got a website, you know, you've got a very quick way of getting onto a mobile phone or tablet, which let's face it, for today's teenagers, that's their primary computing device.
- 57:36Yeah.
- 57:37And I've been in classrooms where, you know, kids can't type.
- 57:39It's not because they don't know what a keyboard is.
- 57:41They use a keyboard every day, but they just use their thumbs like this with it.
- 57:44And when you give them an actual mechanical keyboard.
- 57:45We're really bad.
- 57:47We are dinosaurs using these keyboards now, right?
- 57:50Okay.
- 57:51We're going to evolve massive thumbs or something, but it's that sort of a situation.
- 57:55Okay.
- 57:56We've got to be aware of what these platforms are that folks are using that may be outside of our kind of age group and usage and help them both do things with Python.
- 58:05You're touching on a very important part of the PyScript vision.
- 58:08And it's really not about the current Python community user base.
- 58:15Like it actually is how can we democratize programming and Python and everything.
- 58:22And so we really want to be thinking about who's not thinking about coding at all.
- 58:27Like people that would love to use programming language as a tool for them to do things.
- 58:32And they can't either because, you know, time or because it's too complicated to get Python working or all of that.
- 58:39That's a pluggable.
- 58:41And I'm going to quote Peter again, because we are talking and welcome back, Nicholas.
- 58:46Peter at some point mentioned something like, you know, system design with plugins from the beginning is kind of indication of the developers not really knowing what they're doing or not really knowing what it should do, which, you know, sometimes is a negative connotation.
- 59:02But for PyScript is definitely intentional because we want to we want the community to be able to create their own things.
- 59:09And we don't it's really greenfield.
- 59:12So I don't know what they're going to be doing.
- 59:14I want to allow them to do crazy things and surprises.
- 59:17You know, like two months last DjangoCon, Patrick came up with this experiment of running Django on either PyScript or Pyodide.
- 59:28And I my first question was, why?
- 59:29Right.
- 59:30But then who cares?
- 59:32Like it's the web is inside the web inside the web.
- 59:35Exactly.
- 59:36Like inception all the way down.
- 59:38So that's the whole point.
- 59:41I can we want to make it funny, accessible and a hacker, a hacker space, a safe hacker space.
- 59:46Yeah, it's such awesome.
- 59:47Congratulations to you guys on this.
- 59:49When will we see something that we outside that don't want to grab onto an in-flight open source project,
- 59:56but like a release equivalent of this?
- 59:59Is there some time frame, some thought about when that's out?
- 1:00:03Because this is the right time to drop from the call.
- 1:00:06OK, so I can tell I can certainly tell you what the state of play is right now.
- 1:00:13And you can extrapolate when you may see sort of things like microprice.
- 1:00:17Because PyScript, proper PyScript is undergoing active development.
- 1:00:22I didn't want to try and plug in new runtimes, new interpreters, whilst the sand underneath me was shifting, as it were.
- 1:00:30So I created a very small and simple test harness version of PyScript that I've called, surprisingly enough, micro PyScript.
- 1:00:37That is going to be thrown away.
- 1:00:39Its sole purpose was to allow me to just poke these things with a stick and see what happens.
- 1:00:44And I'm still using that to, for instance, figure out how we can do MicroPython DOM connectivity and interactions as well.
- 1:00:51That's literally what I've been doing all day today is reading articles I needed to do to make that happen.
- 1:00:58So, yeah, that's going to unlock so much.
- 1:01:00Once the DOM is in play, then all of a sudden it's on.
- 1:01:03Yeah, everything else is.
- 1:01:04Yes, exactly.
- 1:01:05Exactly.
- 1:01:05Once that's in place, what I imagine will happen is Nicholas is going to be spending a lot of time with the main code base and pairing with people who know it a lot better than I currently do, because it's been maybe a couple of months since I've last looked at it.
- 1:01:21And it's changed a lot since then.
- 1:01:23And we'll integrate that work.
- 1:01:25So I expect, and this is a finger in the air, and remember, the right answer is when it's ready.
- 1:01:32But I imagine it's going to be kind of springtime.
- 1:01:35Springtime.
- 1:01:36First, third of next.
- 1:01:38Would you say maybe in April?
- 1:01:39Like April 19th, 20, 21st?
- 1:01:42I'm not going to mention any dates because you're just going to hold me to it, aren't you?
- 1:01:46I'm not going to mention any dates.
- 1:01:48I'm just teasing you.
- 1:01:49I'm not holding you to that.
- 1:01:50I hear that, you know, conference wear is very real.
- 1:01:55So we can promise for PyCon.
- 1:01:56No problem.
- 1:01:57Yeah, I hear a good place to announce new JavaScript packages is Salt Lake City in April.
- 1:02:03So Brett, I'm going to give you the final word here maybe to like put one more thought into this before we wrap up our show.
- 1:02:09Nicholas talked about, and Fabio also talked about like how do we, you know, this could be an empowering thing for other people, right?
- 1:02:15Like if for kids in education and whatnot, if you look at a lot of education is Chromebooks.
- 1:02:21You know what runs great on Chromebooks?
- 1:02:23The web.
- 1:02:23Also VS Code in the browser.
- 1:02:26Like there's, is there some thought of like interesting pure web development environments, runtime environments, like end-to-end things that could be done?
- 1:02:35We actually announced that for VS Code in our last release.
- 1:02:38If you go read our release notes, we actually have an extension that will load up into VS Code.dev, which is an actual website, not the name of a product.
- 1:02:45You literally go to VS Code.dev.
- 1:02:47It'll load up VS Code in the browser.
- 1:02:48And there's a Python extension by my teammate Dirk that uses Wazzy and the CPython build where you have a REPL.
- 1:02:55You can run code from your workspace wherever it's loaded, right?
- 1:03:00It doesn't have to be on disk.
- 1:03:01It can come from GitHub.
- 1:03:02Anywhere VS Code can read files from.
- 1:03:04It can load and be seen by Python interpreter itself.
- 1:03:08So that's all working.
- 1:03:09And just this past week, it's not out yet, to be very clear.
- 1:03:13Dirk got debugging working using Wazzy and a very cool trick that everyone can see.
- 1:03:18It's very Unix-y.
- 1:03:19I don't want to spoil it.
- 1:03:21It's going to be open source, so it's not a trade secret or anything.
- 1:03:23But it's way easier to read about it than trying to explain it on a podcast.
- 1:03:26But we got debugging working as well.
- 1:03:28So we are trying to work towards a complete development story such that, once again, for beginners, for learners, for the education market,
- 1:03:38to at least have a baseline Python experience where you can write code, read code, read files, debug.
- 1:03:46Like, what you would want to have when you're facing down that classroom of 30 kids that Nicholas has shown is very scary to at least have something you can have them all just pull up.
- 1:03:55I do want to add two other things to this, though, is actually kind of call to actions for the community around all this.
- 1:04:02One is I don't think we've all started to think about the opportunities here beyond what we've talked about, right?
- 1:04:08There's more to this than just what we have in the browser.
- 1:04:10And it's one of these rising tides lifts all shifts.
- 1:04:13So it's not that I want to take away from what Pryscript's done and all this wonderful stuff in the browser.
- 1:04:18But I think if we can get more WebAssembly stuff kind of going, it helps cause everyone to try to look into this more, which will lead to more Pryscript engagement.
- 1:04:24So I think there's some use cases we haven't really tackled yet in the community where if you just stop and look about where's things really oriented towards JavaScript as a platform and go like, oh, you know what?
- 1:04:35We might build these Python here now.
- 1:04:37For instance, you could probably, and I haven't had time to test this, but I see zero reason why this couldn't work.
- 1:04:42You could probably start writing GitHub Actions in Python now.
- 1:04:45Because guess what?
- 1:04:46It runs on Node.
- 1:04:46And Node can run WebAssembly.
- 1:04:48So we could totally take either Nicholas's MicroPython build or we could take the CPython build and totally just have as part of a GitHub Action as the first step in the JavaScript, load Python.
- 1:04:59And then suddenly just say, call this function.
- 1:05:01And suddenly all your stuff's going through Python.
- 1:05:04Because guess what?
- 1:05:05At that point, GitHub Actions is all totally driven via standard out and some special formatting in it.
- 1:05:09So you could totally just do that.
- 1:05:11And I think Nicholas wants to interject with something.
- 1:05:13Yeah.
- 1:05:13It's worth pointing out that Damien, who has done a lot of work on getting MicroPython to work with WASN, clearly he knows the code base and things like that.
- 1:05:21MicroPython, if you look very carefully at the WebAssembly port, you'll notice that there are conditionals that check whether it's running in Node or in a browser.
- 1:05:30So go knock yourself out.
- 1:05:32Try that.
- 1:05:32I've not tried it.
- 1:05:33I've clearly been busy doing other things.
- 1:05:35But folks might want to have a go at using.
- 1:05:38I mean, I feel like we should award a prize or something.
- 1:05:41You win a thumbs up or something like that if you can get a GitHub Action running MicroPython.
- 1:05:46Yeah.
- 1:05:46I mean, that's fantastic, right?
- 1:05:48Like, I think there's opportunities here we just haven't even touched yet that the community can totally just lean into that we haven't had opportunity to be able to do before.
- 1:05:55The other thing I want to lean into here that we've talked about languages versus platforms and all this, the one key thing across all of this story is Python the language.
- 1:06:04So this is going to sound a little weird, but I want to push people to write more Python code.
- 1:06:08And the reason I phrase it this way is we've historically as a community done great about this, but we will reach for that Rust code or that C code or whatever to write that little bit a little faster.
- 1:06:18But when you do that, well, right now, Fabio and Nicholas shed a tear because that makes it that much harder to make that run in PyScript, right?
- 1:06:25And same for anyone else who wants to do this WebAssembly thing, right?
- 1:06:28Anytime you write anything in something other than Python, it's harder to get running, right?
- 1:06:32Somewhere else.
- 1:06:33Now, you mentioned the 3.11 release, Michael.
- 1:06:36My hope here is now that we've got that nice little performance boost there, that's going to motivate people who are primarily targeting CPython at the moment to write more code in Python and reach for the C code and the Rust code less.
- 1:06:48Because, once again, that stuff can get brought over today.
- 1:06:51There is nothing you have to do to make this work, right?
- 1:06:54Like, you can load pure Python wheels in PyScript.
- 1:06:57You can do that on WebAssembly, right?
- 1:06:59It just runs.
- 1:07:00So if we can kind of nudge the community back towards running more Python and leaning less on the accelerator code that we have historically written for these kind of platforms, or do both, right?
- 1:07:11Like, if you can at least prototype in Python and keep that running, and then write the accelerator code behind the scenes, right?
- 1:07:16Like, you can have multiple wheels, including a pure Python wheel, right?
- 1:07:19Like, coverage.py, we all know, does this exact thing so that it works no matter where you are.
- 1:07:23Same thing for this case, right?
- 1:07:26Like, if you can get the pure Python wheel out there, then it's going to be usable everywhere.
- 1:07:29And so that's kind of a baseline target I hope the community kind of leans into more than we have in the last few years, where, yeah, write your Python code even more than you may have before, because it's usable in more places.
- 1:07:43That's really great advice.
- 1:07:44And it's not done getting faster, right?
- 1:07:46The faster CPython team is still making a bunch of steps.
- 1:07:49So it's much faster now, but there's still, there's 3.11, 3.13, or 3.12, 3.13, the one that's going to be.
- 1:07:55Yeah, exactly.
- 1:07:56Like, it's going to keep going.
- 1:07:57I don't know how much faster 3.12 may or may not be.
- 1:08:00I think there's some plans for 3.12 that are really foundational.
- 1:08:04So the bump might not be quite as big as 3.11, but 3.13, if the foundation lays in 3.12, we'll hopefully get the bump.
- 1:08:11So, yeah, hopefully you'll keep getting those wins going forward, right?
- 1:08:15And I know Damien's still working on MicroPython to make it faster and smaller and better and all that stuff.
- 1:08:20So it's not just a CPython thing out of there.
- 1:08:21Like, the whole, everyone's always trying to make Python run better on all these platforms.
- 1:08:25So key thing, though, is the common bottom layer of all these platforms is actually Python itself.
- 1:08:31So if we can target that more as a community, we'll actually be able to get more use out of the code and for what people have produced in more places.
- 1:08:38And once again, help Nicholas when he faces down that class of 30.
- 1:08:41Yes, you can.
- 1:08:44You can create Call of Duty.
- 1:08:46Okay.
- 1:08:46Thank you, Brett.
- 1:08:47That's great thoughts.
- 1:08:48And it also points out I should pay more attention to those release notes when they come up in my VS Code.
- 1:08:52I'm like, oh, new one, out of the way.
- 1:08:54Maybe I'll read them.
- 1:08:54All right.
- 1:08:56You guys, thank you so much for all the work on this.
- 1:08:59This is super exciting.
- 1:09:01And yeah, I'm looking forward to hearing about it in spring or whenever it's ready.
- 1:09:06Brett, Fabio, Nicholas, thanks for being here.
- 1:09:07It's been great.
- 1:09:08Thanks, Michael.
- 1:09:09Thank you, Michael.
- 1:09:09That was great.
- 1:09:10Thank you, Michael.
- 1:09:13This has been another episode of Talk Python To Me.
- 1:09:16Thank you to our sponsors.
- 1:09:17Be sure to check out what they're offering.
- 1:09:19It really helps support the show.
- 1:09:20AWS is the lead cloud for developers.
- 1:09:23But with over 250 services, it's an overwhelming set of choices.
- 1:09:29That's where the AWS Insiders podcast comes in.
- 1:09:32Their job is to help you make sense of all those AWS options.
- 1:09:35Listen to an episode at talkpython.fm/AWS Insiders.
- 1:09:40Listen to the Local Maximum podcast.
- 1:09:42Learn about topics as diverse as the philosophy of probability and Elon Musk's next move.
- 1:09:49Just search for Local Maximum in your favorite podcast player.
- 1:09:52Want to level up your Python?
- 1:09:54We have one of the largest catalogs of Python video courses over at Talk Python.
- 1:09:59Our content ranges from true beginners to deeply advanced topics like memory and async.
- 1:10:03And best of all, there's not a subscription in sight.
- 1:10:06Check it out for yourself at training.talkpython.fm.
- 1:10:09Be sure to subscribe to the show.
- 1:10:11Open your favorite podcast app and search for Python.
- 1:10:14We should be right at the top.
- 1:10:15You can also find the iTunes feed at /itunes, the Google Play feed at /play,
- 1:10:20and the direct RSS feed at /rss on talkpython.fm.
- 1:10:24We're live streaming most of our recordings these days.
- 1:10:28If you want to be part of the show and have your comments featured on the air,
- 1:10:31be sure to subscribe to our YouTube channel at talkpython.fm/youtube.
- 1:10:35This is your host, Michael Kennedy.
- 1:10:37Thanks so much for listening.
- 1:10:39I really appreciate it.
- 1:10:40Now get out there and write some Python code.
- 1:10:42Thank you.
- 1:10:43Thank you.