Latest / Talk Python To Me / #469: PuePy: Reactive frontend framework in Python
Transcript
- 0:00Python is one of the most popular languages of the current era.
- 0:03It dominates data science.
- 0:05It's an incredible choice for web development,
- 0:08and it's many people's first language.
- 0:10But it's not super great for front-end programming, is it?
- 0:14Frameworks like React, Vue, and other JavaScript frameworks rule the browsers,
- 0:19and few other languages even get a chance to play there.
- 0:22But with PyScript, which I've covered a couple times on this show,
- 0:26we have the possibility of Python on the front-end.
- 0:30Yet PyScript is not really a front-end framework.
- 0:32It's just a runtime in the browser.
- 0:34That's why I'm excited to have Ken Kinder on the podcast
- 0:38to talk about his project, PewPy, a reactive front-end framework in Python.
- 0:43This is Talk Python To Me, episode 469, recorded June 20th, 2024.
- 0:50Are you ready for your host, please?
- 0:53You're listening to Michael Kennedy on Talk Python To Me.
- 0:56Live from Portland, Oregon, and this segment
- 0:59was made with Python.
- 1:00Welcome to Talk Python To Me, a weekly podcast on Python.
- 1:07This is your host, Michael Kennedy.
- 1:08Follow me on Mastodon, where I'm @mkennedy,
- 1:11and follow the podcast using @talkpython,
- 1:13both on fosstodon.org.
- 1:16Keep up with the show and listen to over seven years of past episodes
- 1:19at talkpython.fm.
- 1:21We've started streaming most of our episodes live on YouTube.
- 1:25Subscribe to our YouTube channel over at talkpython.fm/youtube
- 1:28to get notified about upcoming shows and be part of that episode.
- 1:33This episode is brought to you by Sentry.
- 1:35Don't let those errors go unnoticed.
- 1:37Use Sentry like we do here at Talk Python.
- 1:38Sign up at talkpython.fm/sentry.
- 1:42And it's brought to you by Code Comments, an original podcast from Red Hat.
- 1:46This podcast covers stories from technologists who've been through tough tech transitions
- 1:51and share how their teams survived the journey.
- 1:54Episodes are available everywhere you listen to your podcasts
- 1:58and at talkpython.fm/code dash comments.
- 2:01Hey, before we talk about PewPy, I have an announcement.
- 2:04I'm sure that you know I have many online courses that you could take at Talk Python.
- 2:09But before I went down this online courses path,
- 2:12I did years of in-person courses for software developers.
- 2:16So it's back to these routes for my next event, but with a truly adventurous twist.
- 2:21I'll be doing a six half day course on all sorts of modern Python topics
- 2:26like FastAPI for building web apps and APIs.
- 2:30And the amazing part is that the course will be held in a castle in Tuscany, Italy.
- 2:35That's right.
- 2:36It's code in a castle.
- 2:37One half developer course and one half dream vacation.
- 2:41We'll spend the mornings learning Python and the afternoon on excursions to amazing venues
- 2:46and vineyards.
- 2:47Places are super limited and I'd love to have you join me.
- 2:50So check out talkpython.fm/castle and see what it's all about.
- 2:54I hope you can join me for an adventure in Italy this fall.
- 2:58Ken, welcome to Talk Python To Me.
- 3:00Right.
- 3:01Good to be here.
- 3:01Excellent to have you here.
- 3:03It's a topic that's near and dear to my heart.
- 3:06And I know for many people as well, building cool websites, but more Python, less JavaScript.
- 3:12Not hating on JavaScript, but why do we need to learn a sixth language to work on websites?
- 3:16There's already so many HTML, CSS, et cetera, et cetera.
- 3:19In the world, we should be able to pick the language we like and build websites with it.
- 3:23But somehow it's gotten itself into a place where you pick part of the language you like
- 3:27and then the rest you do in JavaScript.
- 3:29But we'll see how long that lasts.
- 3:30Yeah.
- 3:31Running Python in the browser has always kind of been a little dream of mine ever since
- 3:35I first, well, ever since I first started programming in JavaScript.
- 3:38But yeah, that's awesome.
- 3:39We had traditionally things like mscripten and some of those transpilers, right?
- 3:45Like Sculpt and others.
- 3:47Sculpt, transcript, Brython.
- 3:49Not Brython.
- 3:51Not transpiler, but transpiler.
- 3:53Brython.
- 3:54And it does the same thing as PyScript.
- 3:56It just runs the whole CPython in JavaScript, which is wild.
- 4:01Yeah, it's super wild.
- 4:03And I guess there's a requisite shout out to the birth and death of JavaScript talk, which
- 4:08gives you a really good insight.
- 4:10It seems like you've seen that talk as well.
- 4:12No, but I have heard about it.
- 4:14It's worth the 15 minutes.
- 4:15It's both funny, but also very insightful.
- 4:17All right.
- 4:18So we're going to talk about a front-end framework that you've built that is Vue.js-like, but
- 4:26runs on top of Python in the browser, which is awesome.
- 4:28On the client side.
- 4:29On the client side.
- 4:30Which is awesome.
- 4:30On the client side.
- 4:31Very important.
- 4:32Very, that's the big thing.
- 4:34Before we get to that, though, you know, just tell people a bit about yourself.
- 4:36Who's Ken?
- 4:38Yeah, my name's Ken Kender.
- 4:39I've been developing Python software for 24, 2025 years, something like that.
- 4:45Ever since Red Hat's installer crashed and I saw the stack trace and opened up a file and
- 4:51I could just read the code.
- 4:52That was my introduction to Python and I never looked back.
- 4:55Mostly I've been writing kind of line of business, software as a service kind of code, and I've
- 5:01always wanted to kind of short circuit and bring it to the browser.
- 5:05Yeah.
- 5:05What are you using now for the line of business stuff?
- 5:08Is that like Flask on the back end or is it Node on the back end or what are we talking
- 5:13here?
- 5:13At RealJob, it's all Python on the back end and then our front end is actually a Vue.js app
- 5:19that I wrote originally and then some professional front end developers kind of took it over and
- 5:25we wrote it.
- 5:27Yeah.
- 5:27Yeah, cool.
- 5:28Now it has eight compilation steps.
- 5:29Yes.
- 5:30To prepare itself.
- 5:32But I mean, it compiles into like semi-native apps for mobile and there's like a Chrome
- 5:39extension involved.
- 5:40So.
- 5:40Okay.
- 5:41You're doing a good job with it.
- 5:42Yeah, that's awesome.
- 5:43Look, there's a ton of websites built primarily with JavaScript and many of them are good,
- 5:48some are more bad, but there's also plenty of bad websites written in Python.
- 5:52But like I said, not hating on JavaScript so much as just saying, why does every programmer
- 5:57in language have to reduce to JavaScript?
- 6:00That seems like a weird situation.
- 6:01There's other frameworks that are making progress here.
- 6:04For example, Blazor in the .NET C# space is actually, I haven't done anything with it,
- 6:09but it's a super interesting idea and it's not that different.
- 6:12Yeah.
- 6:12Not the only crazy person.
- 6:13Blazor uses WebAssembly just like PyScript, which is what I built my stuff on top of.
- 6:19And WebAssembly is about what it sounds like.
- 6:22It's mature enough now that it's supported by all major modern browsers.
- 6:27And since there is no JavaScript layer, really, I mean, there's some kind of JavaScript shims
- 6:34involved.
- 6:34You want to think of it that way.
- 6:36But it's not like your Python code is being transpiled to JavaScript.
- 6:39It's actual Python.
- 6:41Right, right, right.
- 6:42And we're going to talk about that.
- 6:43It's super interesting.
- 6:43There's interop in the sense that there's kind of like there's C interop in Python now back
- 6:50into the JavaScript layer that you can have.
- 6:52But that's not the same as this other language is interpreting.
- 6:55It's running the interpreter, right?
- 6:57So it's kind of natively as much as you get in the front end, natively there.
- 7:00I kind of want to walk people through some of the technologies to get us started here.
- 7:05So you've already given a shout out to PyScript.
- 7:08We talked about Vue.
- 7:09I think PyScript is the foundation.
- 7:11Vue is maybe the motivation.
- 7:13Let's start with PyScript.
- 7:14Got their website pull up here.
- 7:16And what I'm learning is that I can have a REPL on my homepage.
- 7:20Actually, I know I can do more than that.
- 7:22But that's sort of what they're demonstrating right now.
- 7:24Yeah, you can do a lot more than that.
- 7:25You have kind of two choices with PyScript.
- 7:27You can run Pyodide, which is lower level, if you want to think of it that way, Python in the browser project.
- 7:35And that is basically full CPython with some minor changes necessary.
- 7:42But you get basically the whole standard library.
- 7:45You can install packages from PyPy or PyPI, however you pronounce it.
- 7:51And those download just as you download the website.
- 7:54That's probably your best bet if you just want it through Python experience.
- 8:00PyScript, though, also includes a MicroPython version.
- 8:04And the MicroPython, if you're not familiar with it, it's mostly designed for microcontrollers or Raspberry Pi kind of environments where you have very limited resources.
- 8:15Because it is so truncated relative to real Python, it downloads very nicely in the browser.
- 8:22It's actually it plus PyScript ends up being smaller than a lot of JavaScript front-end frameworks.
- 8:29Yeah, which is incredible.
- 8:30And this is a huge thing that is unlocked, honestly, kind of the stuff that you're pursuing a much bigger scale, I think.
- 8:38MicroPython is the name suggests.
- 8:40And I've had Damien and others on to talk about MicroPython.
- 8:43It's real micro.
- 8:45Like this, I'll hold up a little device here, like this thing in my hand.
- 8:48This little chip that is probably about the size of my thumb costs like 20 bucks.
- 8:53And this runs full MicroPython, manages the DNS of my network and stuff like that,
- 8:59like ad blockers and that little tiny thing.
- 9:02But the restriction is, you know, how much storage does it have?
- 9:05A couple of megs.
- 9:06How much RAM does it have?
- 9:08Probably similar.
- 9:09I don't know.
- 9:09The goal was to be a very small kernel of Python with MicroPython, not let you do Tkinter, pandas, etc., etc., etc.
- 9:20And so PyScript choosing to support both of these means you can kind of take Pyodide and get full Python, in a sense, as much as you can.
- 9:28Or you can do MicroPython and restrict yourself to a smaller set, but you get a much lighter weight experience, right?
- 9:35Yeah.
- 9:35If you've ever used transpiling, MicroPython is still a real big upgrade over that because you are getting almost all the Python syntax and most of the libraries that you're likely to use just rendering a website.
- 9:49Right.
- 9:50Okay.
- 9:50So a lot of the standard library is still there, but maybe things like networking or whatever that don't make sense.
- 9:56I wouldn't say a lot of it is.
- 9:57Like, a good example is the regular expression module is there.
- 10:01But when I first wrote the router for PewPy, the regular expressions that I was using weren't supported in the MicroPython version of that module.
- 10:09And there's a limited, a limited regular expression.
- 10:12You went too big on your regular expressions.
- 10:14I did, yeah.
- 10:14I see.
- 10:15Okay.
- 10:15Interesting.
- 10:16Yeah, we'll talk about routing.
- 10:17That'll be fun.
- 10:18Okay.
- 10:18So if somebody were to, which is why we're on the topic of these two, like if someone were to think about building a website, maybe internally for their company, would you suggest that they use Pyodide as the foundation or MicroPython?
- 10:31Because you can pick when you run PyScript.
- 10:33If it's for your company and it's an internal tool, probably most users downloading it are going to have plenty of bandwidth and normal machines.
- 10:42So there's really no reason not to use Pyodide.
- 10:45Yeah, sure.
- 10:45You get better errors with it.
- 10:48There's little things that'll just, you're used to coding, like data classes are missing from MicroPython, but you could use either.
- 10:54Okay.
- 10:55Yeah.
- 10:55Let's see if it, if it'll show us how big is this thing.
- 10:58It doesn't want to, I could just get this.
- 11:00It's a jQuery terminal.
- 11:02How about that?
- 11:02If I click on the link in Pyodide, very cool.
- 11:05But yeah, how big is maybe 10 megs?
- 11:08Is that, would you say that's right?
- 11:09Like I made a little example app for our purposes and I used Pyodide.
- 11:14Now I am pulling in SQLite, which is part of it.
- 11:18That adds some space.
- 11:19One of the benefits though of using Pyodide is you can just grab a lot of the libraries and they'll work, right?
- 11:25Yeah.
- 11:26I don't know if it's PyScript doing it or Pyodide upstream, but they do make you say that you need certain libraries.
- 11:33Sure.
- 11:34And then they're available for import after you kind of declare them.
- 11:37Right.
- 11:37And when you initially set up the PyScript environment, there's a way where you kind of set the environment as it loads, right?
- 11:43Yeah.
- 11:44Yeah.
- 11:44Okay.
- 11:44You can do it at runtime too.
- 11:45All right, cool.
- 11:46So we've got PyScript, which lets us do Python in the browser, which is awesome.
- 11:52And we've got these two foundations.
- 11:54We've got Pyodide, which is great for its compatibility, I guess.
- 11:59But PyScript, which if I was going to build a SaaS product where lots and lots of people were visiting kind of interactive bits, maybe you consider writing that in MicroPython because it's just less overhead for the world.
- 12:12I don't know.
- 12:12Depends.
- 12:13I would especially consider MicroPython for a page that loads as a normal web page.
- 12:18Yeah.
- 12:19If it loads.
- 12:20Yeah.
- 12:20If it's a landing page sort of thing.
- 12:22Yeah, absolutely.
- 12:23Or even just if it's like one of the CRUD pages, like let's say that you have a traditional sort of Django app or whatever, where you've done server side routing and you only want interactivity on the edit page.
- 12:36And for the view and the list, you're fine with normal templates.
- 12:39You could just use MicroPython where you need it then.
- 12:42But if you're building a single page app and you want everything downloaded up front, maybe that 10 megs is worth it.
- 12:49Yeah.
- 12:50Yeah.
- 12:50Perhaps because you can put aggressive caching on it, put it over a CDN.
- 12:54A lot of times when you pull it up, it'll say, you know, loaded from cache, things like that.
- 12:59Right.
- 12:59Yeah.
- 12:59Let's see if I can, on PyScript, let's see what happens here.
- 13:03If we go to the network and pull this in.
- 13:05Oh, look at that.
- 13:05They're using MicroPython there.
- 13:07But yeah, all this stuff is coming out of disk cache.
- 13:09Disk cache.
- 13:11Seven milliseconds to pull that up.
- 13:13Right.
- 13:13So another thing I just saw looking at the PyScript source there is that it had a service worker.
- 13:17And service workers kind of indicate maybe progressive web app, right?
- 13:21See if I click on this.
- 13:23But partially a progressive web app on PyScript.net.
- 13:26I know you're a fan of these and it might be an interesting way to deploy.
- 13:29You know, you talked about the internal apps, right?
- 13:32Instead of just putting links, maybe you install it as a progressive web app, right?
- 13:35Yeah.
- 13:35I haven't made a progressive web app in PyScript yet, but there's others who have done it.
- 13:41Yeah, I've done it.
- 13:42And I have an example up where I don't think it runs anymore because PyScript's changed so much.
- 13:47But I even got it to install as an app on the home screen of my iPad.
- 13:52You click it, it launches.
- 13:54It looks like a full-blown app.
- 13:56Nobody would know the difference, but it's PyScript based.
- 13:59Yeah.
- 14:00I'll try to link the video about that in the show notes.
- 14:03Yeah.
- 14:03If you're running a SaaS, that's a really compelling option because then you also skip out on the
- 14:08App Store review process.
- 14:10Oh my gosh.
- 14:11Forking over some of your brain.
- 14:12If people see, you got to carve off a piece of your soul to get through App Store review.
- 14:16It's not a fun, it's not a fun experience.
- 14:19Let me tell you, I've been through the ringer four or five times, mostly in the Apple App Store,
- 14:24but also in the Google App Store with our courses app and not fun.
- 14:28So progressive web app, letting you skip that, 100% behind that idea.
- 14:33This portion of Talk Python To Me is brought to you by Sentry.
- 14:37Code breaks.
- 14:38It's a fact of life.
- 14:39With Sentry, you can fix it faster.
- 14:41As I've told you all before, we use Sentry on many of our apps and APIs here at Talk Python.
- 14:47I recently used Sentry to help me track down one of the weirdest bugs I've run into in a long
- 14:52time.
- 14:53Here's what happened.
- 14:54When signing up for our mailing list, it would crash under a non-common execution pass, like
- 15:00situations where someone was already subscribed or entered an invalid email address or something
- 15:05like this.
- 15:05The bizarre part was that our logging of that unusual condition itself was crashing.
- 15:11How is it possible for our log to crash?
- 15:15It's basically a glorified print statement.
- 15:17Well, Sentry to the rescue.
- 15:19I'm looking at the crash report right now, and I see way more information than you'd expect
- 15:24to find in any log statement.
- 15:25And because it's production, debuggers are out of the question.
- 15:29I see the traceback, of course, but also the browser version, client OS, server OS, server
- 15:35OS version, whether it's production or Q&A, the email and name of the person signing up.
- 15:40That's the person who actually experienced the crash.
- 15:42Dictionaries of data on the call stack and so much more.
- 15:45What was the problem?
- 15:46I initialized the logger with the string info for the level rather than the enumeration dot
- 15:53info, which was an integer-based enum.
- 15:56So the logging statement would crash, saying that I could not use less than or equal to
- 16:01between strings and ints.
- 16:02Crazy town.
- 16:04But with Sentry, I captured it, fixed it, and I even helped the user who experienced that
- 16:10crash.
- 16:10Don't fly blind.
- 16:11Fix code faster with Sentry.
- 16:13Create your Sentry account now at talkpython.fm/sentry.
- 16:17And if you sign up with the code TALKPYTHON, all capital, no spaces, it's good for two free
- 16:24months of Sentry's business plan, which will give you up to 20 times as many monthly events
- 16:28as well as other features.
- 16:29That's PyScript, which is super awesome.
- 16:33But let me just make a comment here to get your thoughts about this.
- 16:36When I go to PyScript.net, I'm a big fan of this project, the people behind it.
- 16:40But when I get here, what it shows me and what it encourages, what it basically communicates
- 16:46to me, at least, is you, dear visitor, can have Python in your browser.
- 16:52And so, for example, here's your REPL.
- 16:55You know, you just type Python in the terminal, that thing that comes up, that redeveloped print
- 17:00loop.
- 17:00You just get the REPL.
- 17:01And now I can type, like I could do X equals seven, Y equals two, X plus Y is nine.
- 17:07Right?
- 17:08That's interesting.
- 17:09And it shows the power.
- 17:10But as a web developer, I don't want to develop a REPL.
- 17:14I want to develop web applications like input boxes and images and grids.
- 17:19And if I interact with this, it changes that.
- 17:21And so on.
- 17:22Right?
- 17:22Like I want a front-end UI experience with my Python in the browser, not just the equivalent
- 17:29of the console in JavaScript, you know?
- 17:31That's my desire, too.
- 17:33Something I really like about Vue, React does this, but I don't have as much React experience,
- 17:38is reactivity, where if the state of your page or your component changes, it redraws the UI
- 17:48and patches the DOM, the elements in the browser, in real time, where you don't need to think
- 17:55about, oh, let's say one state changed and that affects five widgets, so I need to go
- 18:01redraw those five widgets.
- 18:02It all just kind of happens automatically.
- 18:04And there's nothing like that built into PyScript itself.
- 18:07So PewPy kind of lives on top of PyScript and adds that layer and just other conveniences
- 18:14that I would want.
- 18:15Yeah, absolutely.
- 18:16And event handlers, right?
- 18:18As well.
- 18:19Yeah.
- 18:19So really a lot of neat stuff.
- 18:22And that is very nice about Vue.
- 18:23I like that as well.
- 18:24The data binding and the reactivity, where you can just say, here's a dictionary.
- 18:28I make changes to the values of that dictionary, that JSON object, and other parts of my UI
- 18:33are using it.
- 18:34Just also make those change.
- 18:36Or if I bound it to an input and somebody starts typing, propagate that back to the rest
- 18:40of the app, right?
- 18:41Right.
- 18:41And you've got reusable components.
- 18:43So if you make the perfect foreign key lookup widget, you can just reuse it all over your
- 18:50application.
- 18:50And reusing it is really easy.
- 18:52It just becomes a little HTML tag in view.
- 18:55Kind of like web components, if you've used those.
- 18:57But I think...
- 18:59Those didn't really catch on that well, did they?
- 19:00Compared to how...
- 19:01I think they should have caught on better, maybe.
- 19:02Oh, I think there's kind of a little movement behind them now.
- 19:05Okay.
- 19:06Maybe because people are so...
- 19:08I mean, not to come down on any projects, but I think there's a desire to have more stable
- 19:15development tools.
- 19:16And all the JavaScript stuff changes one day to the next.
- 19:20Like you go get a cup of coffee and then you need to upgrade all your node dependencies.
- 19:25So with web components, like you really only need to upgrade the components you use.
- 19:31And web components are how I see you using PewPy too.
- 19:35Okay.
- 19:35Very interesting.
- 19:36So that brings us to PewPy.
- 19:39The name is like Vue, but for Python, so Pew and then Py, right?
- 19:44Is that where the origin is?
- 19:45Am I getting this right?
- 19:46That is the origin.
- 19:47Awesome.
- 19:47Okay.
- 19:48So here I land on PewPy.dev and I see a red button with a minus and a green button with
- 19:53a plus.
- 19:54And I can just click on these and it does the reactivity and it does the changing.
- 19:57There's no navigation, but there's not really directly much JavaScript, is there?
- 20:02What is happening here?
- 20:03Tell us about this project.
- 20:04On your screen, if you have it pulled up, you'll see code directly below the counter.
- 20:09And that is the code that is running the site you're seeing with just a little bit of
- 20:14boilerplate that's missing.
- 20:15And it sounds very, yeah, just a tiny, tiny bit.
- 20:17It looks very familiar to a Vue.js app startup, right?
- 20:21How you would get that?
- 20:22Yeah.
- 20:23Especially Vue 2.
- 20:24I never upgraded to Vue 3 while I was working on Vue stuff before handing off my current
- 20:31project.
- 20:31You'll see that initial function defines state when the page loads.
- 20:36Populate defines the layout and DOM elements.
- 20:41And then there's two event handlers that update the state.
- 20:44And as the state updates, the DOM is updated.
- 20:46Yeah, awesome.
- 20:47And it looks, yeah, you combined functions, Python functions as the event handler.
- 20:52And you just say, go to the button and say onclick equals your Python function.
- 20:58And then in that function, you say state bracket current value from the dictionary.
- 21:04You can increment it like plus or minus it in this case.
- 21:06And that reactivity propagates back to the text box or the span in there that shows that
- 21:12information, right?
- 21:13That's kind of the full lifecycle in a pretty simple little bit of code.
- 21:16That's the snippet.
- 21:17That's the basic video.
- 21:19Yeah.
- 21:19Let's see about the old network here.
- 21:22What do we get?
- 21:23If I pull this up, a couple of things that I think are interesting.
- 21:26I pull up the network tools and I just pull up pewpie.dev.
- 21:29The whole page, I don't know how far away this is.
- 21:32Do you know where this is hosted?
- 21:32It's on GitHub pages, so I can't tell you.
- 21:35It's on the internet.
- 21:36Okay, awesome.
- 21:36All right.
- 21:37So it loads in, because I was thinking about, well, it's the ping time and stuff.
- 21:40So it loaded in 155 milliseconds and then it processed the DOM content in 144 milliseconds,
- 21:47which is, that's good.
- 21:49Like that's in a realm that people don't really perceive, right?
- 21:52Not really.
- 21:52And it looks like you're doing MicroPython here, which is, how big is our MicroPython?
- 21:59It is 1.6 megs.
- 22:01No, no, that's the age.
- 22:02Sorry.
- 22:02Where's the content length?
- 22:04There it is.
- 22:04188k.
- 22:05189k.
- 22:07That's pretty good.
- 22:08There's some stuff that was downloaded that you'll also see over there, like, you know,
- 22:12the PewPy wheel.
- 22:13Yeah, sure.
- 22:14The entering the file.
- 22:15I mean, hold on to what you just said there.
- 22:17The PewPy wheel was downloaded, okay?
- 22:20So talk about that.
- 22:22Like, this is not even the source, right?
- 22:24This is the distribution.
- 22:26I mean, I'm probably in there, it has the source, but.
- 22:28Yeah.
- 22:29I mean, a wheel file is just a zip file of the source.
- 22:32Yeah.
- 22:32It could have binary goodies in there as well, I suppose.
- 22:36But this one's platform neutral.
- 22:37So it's not likely.
- 22:38But this is basically like taking something off PyPI and pip installing it.
- 22:43But for your website, for your front end, you basically pip install it for it, right?
- 22:47Yeah.
- 22:47I would like to have it work that way.
- 22:50But for MicroPython, you don't get the full pip.
- 22:53Right, right, right.
- 22:54MicroPython has a funky way of working with its dependencies.
- 22:57I don't remember exactly how I got it working with this little thing, but it has three or
- 23:01four dependencies, my little, my 32-bit little chip thing.
- 23:05But I do remember that it was like, my intuition around pip wasn't quite working.
- 23:09If you said, if you went to somebody, so we have an interactive web page and it's 189k,
- 23:14plus a little bit, that's fine.
- 23:16Right?
- 23:17On a CDN, no one's going to have a problem with that amount of data.
- 23:20Yeah.
- 23:21I mean that.
- 23:21Oh, and the other thing.
- 23:22Absolutely competes with what a typical JavaScript framework would require.
- 23:26Yeah.
- 23:27And the other thing worth noting here is PewPy, its wheel comes from disk cache as well as
- 23:35MicroPython WebAssembly.
- 23:37So once I hit this, like for example, now looking at the processing times, it's 62 milliseconds
- 23:43and 50 milliseconds.
- 23:44All right.
- 23:45That's ridiculous.
- 23:45That's awesome.
- 23:46So yeah, really good.
- 23:48I don't know how fast your computer is, but I haven't been bothered by any of the performance
- 23:52I've seen from PyScript.
- 23:54Yeah, no, it's super fast.
- 23:55So it's down to a point where, you know, there had been, there had been statements like, well,
- 23:59it'd be cool if you could use something like Pyodide, but it's, it's just so slow.
- 24:04It takes five seconds for the page to come up or whatever on the early days.
- 24:08And you can't really assume that that's acceptable to people.
- 24:11150 milliseconds, 60 milliseconds here and there.
- 24:15Like that's blink of an eye type stuff.
- 24:17You're, you're good to go with that, right?
- 24:18Yeah.
- 24:18I probably wouldn't use it for like a WebGL kind of stuff or anything that needs to be super
- 24:25performant, but most business software is just fine with these.
- 24:28And even, you know, like that is a runtime performance versus a app initialization performance
- 24:34conversation, isn't it?
- 24:36Yeah.
- 24:36So let's talk a bit about that.
- 24:38What is this good for?
- 24:39And what is it bad for?
- 24:40It's most good for, especially with, with MicroPython, those kinds of use cases where you have
- 24:46business logic that is presentation relevant, like, like you have a form and what is shown
- 24:53on the form depends on what's already entered.
- 24:55You know, that's, that's the kind of stuff you would have done with jQuery back in the
- 24:59day.
- 24:59And you could do it very easily with PewPy.
- 25:01You could do kind of basic CRUD work.
- 25:04You could do data visualization.
- 25:05And also just anytime that you want a full Python environment in the browser, obviously it's a
- 25:11good choice.
- 25:12It's probably not a great choice if you don't already know and love Python, because if you're
- 25:19a JavaScript developer, why would you lose all the tooling?
- 25:22If for that matter, if you like a lot of tooling, you know, there's no Chrome debugger for PyScript.
- 25:28You just get your trace back.
- 25:30You're not going to do it wrong.
- 25:31Can you print?
- 25:32Can you print a console?
- 25:33You can print.
- 25:34And normal Python statements go to console.
- 25:36That's what you get.
- 25:37You're good.
- 25:39You know, you honestly, though, you probably could bring in some of these libraries.
- 25:42Gosh, I can't remember.
- 25:43There's a couple that are really nice that you can bring in and change the print statement,
- 25:48or they'll do much richer output of like the state of an object.
- 25:52They'll traverse the graph or they'll give better information about it.
- 25:55So you might be able to get those print statements a little bit supercharged, but they're still
- 25:59print statements, right?
- 25:59Yeah.
- 26:00I mean, hopefully one day you can run like a remote debugger into PyCharm or something too.
- 26:06But yeah.
- 26:07That would be cool.
- 26:08We'll get the PyCharm folks on that and just connect to the front.
- 26:11Look, they do a JavaScript.
- 26:12Yeah.
- 26:12Right.
- 26:13So.
- 26:13And also, you know, PyCharm supports remote debugging.
- 26:17So.
- 26:18Let's put them together.
- 26:19Yeah.
- 26:20All right.
- 26:21So one of the things that does jump out at me when I see this here is the populate method.
- 26:27So the way you create this interactive app that has the plus or minus increment or decrement
- 26:31or things is you create a class called counter page, derives from page.
- 26:36When it initializes itself, it has, it sets sort of the variables to their default values
- 26:42and creates them.
- 26:42You know, increment can change them, decrement can change them.
- 26:45But then there's this populate method that says with some kind of DOM mill, like with div
- 26:51with this class, with e.button as this text and its event hooks this.
- 26:56So you're expressing the UI of that little section, not the whole page, but that little section
- 27:03in Python code.
- 27:04Want to tell us about how that goes?
- 27:05Yeah.
- 27:06So the kind of two approaches that you can have toward building a DOM, building not even
- 27:11a DOM, but just any UI is like a templated language, which is usually real popular on the web.
- 27:17And I have experimented with embedding Genja to templates and it works sort of iodide.
- 27:24What I decided on is my preferred method is using context managers to specify nesting.
- 27:33So in the example you're looking at, there's a div tag and then there's two buttons and
- 27:39a span and they're nested in the div tag.
- 27:41And the context manager tells the UI.
- 27:50So every time you want to nest more elements, you use another with statement.
- 27:55And that way you can use if statements, for loops, just normal Python code.
- 28:02And the deeper you're into your context managers, the more nested you are.
- 28:07So in this case, you say with div and then you create a button, a span and a button.
- 28:11Basically, anything that gets created while within that context manager just goes to the children
- 28:16of the thing that was put into the context, right?
- 28:19Right.
- 28:19Exactly.
- 28:19And for that matter, you could also nest more PuePy components using that same.
- 28:25Oh, interesting.
- 28:26Okay.
- 28:27And what does a PuePy component look like?
- 28:29Is it just a class or is there like, how do we make one of the, or is it just a function
- 28:34that also does context manager stuff?
- 28:36What's the deal?
- 28:37I do have some examples of them, but yeah, a component, a page is a component.
- 28:41A component is any reusable chunk of code with that state and population that you can use and
- 28:49reuse throughout your application.
- 28:51This portion of Talk Python To Me is brought to you by Code Comments, an original podcast
- 28:56from Red Hat.
- 28:57You know, when you're working on a project and you leave behind a small comment in the
- 29:01code, maybe you're hoping to help others learn what isn't clear at first.
- 29:05Sometimes that Code Comment tells a story of a challenging journey to the current state of
- 29:11the project.
- 29:11Code Comments, the podcast, features technologists who've been through tough tech transitions and
- 29:18they share how their teams survived that journey.
- 29:20The host, Jamie Parker, is a Red Hatter and an experienced engineer.
- 29:24In each episode, Jamie recounts the stories of technologists from across the industry who've
- 29:30been on a journey implementing new technologies.
- 29:33I recently listened to an episode about DevOps from the folks at Worldwide Technology.
- 29:37The hardest challenge turned out to be getting buy-in on the new tech stack rather than using
- 29:43that tech stack directly.
- 29:44It's a message that we can all relate to, and I'm sure you can take some hard-won lessons
- 29:49back to your own team.
- 29:50Give Code Comments a listen.
- 29:52Search for Code Comments in your podcast player or just use our link, talkpython.fm/code
- 29:58dash comments.
- 29:59The link is in your podcast player's show notes.
- 30:02Thank you to Code Comments and Red Hat for supporting Talk Python To Me.
- 30:07See if I can find some examples.
- 30:09You also can run those examples on PyScript.com, right in your browser.
- 30:14Oh, that's right.
- 30:15Yeah.
- 30:16So, yeah, maybe tell people just about that capability.
- 30:19I'll link to the tutorials there.
- 30:21Yeah, I mean, PyScript.com is a really cool project, also from Anaconda, I believe, where it's kind
- 30:28of like all those million JavaScript IDEs in your browser.
- 30:32IDEs may be a strong word, but you can edit the code and then run it right in your browser.
- 30:37And just like you can see, there's the list of files.
- 30:40You can edit the files.
- 30:41You can fork other people's work and edit them.
- 30:45It's very convenient.
- 30:46Nice.
- 30:46Yeah.
- 30:47So here you have a component defined with the decorator, called it a card.
- 30:51And you've got three little UI cards on there.
- 30:53And they have their populate thing that I guess you would expect.
- 30:56Yeah.
- 30:56Yeah.
- 30:57And then you can just now create the cards as if you'd create any other DOM element, right?
- 31:01Right.
- 31:01Exactly.
- 31:01And you're also seeing slots where there's a card header in the card body.
- 31:06And so if you have a component where there's multiple, in Genja, these would be like template
- 31:13inheritance.
- 31:14If you have a component where you want to insert code from wherever you're using the component
- 31:20into where the component renders, that's what slots do.
- 31:23Again, a lot like Vue or Web Component.
- 31:26So it sounds to me like if I had lots of Vue experience, but at one point I created some apps
- 31:31with Vue, but it's been a while.
- 31:32I'm sure the Vue doesn't look much like that anymore.
- 31:34Yeah.
- 31:35It changed a lot.
- 31:36Yeah.
- 31:37But if you had that experience, it would carry over to Pupy pretty well, right?
- 31:40Yeah.
- 31:40I would hope you wouldn't need that experience either, but yeah.
- 31:43Sure.
- 31:43Yeah.
- 31:43You could just learn it from the Pupy perspective, but if you already knew it, like, hey, that's
- 31:48kind of nice, right?
- 31:48Yeah.
- 31:49If you know React or Web Components, that also would probably carry over.
- 31:53Sure.
- 31:54Sure.
- 31:54Sure.
- 31:54Okay.
- 31:55So one of the things that you talked about was a single page app, and I'm sure there's plenty
- 32:01of people out there who know what a single page app is or a spa, but there's
- 32:05probably a lot of people who are, I mean, from not a web developer areas that are like,
- 32:09what is that again?
- 32:10I want to talk about the router, but I think we need to talk about a single page app before
- 32:14we can talk routers.
- 32:15All right.
- 32:15What is this?
- 32:16You need a router to do it.
- 32:17But a single page app is instead of having that request response cycle where the server
- 32:23renders HTML, and then you go to a new page and the server renders the new HTML, and then
- 32:28you go to another page and the server renders that.
- 32:31A single page app works where it loads the page, and then when you click on a button or click on a link, the software in the client in your browser re-renders the page based on the link you clicked without ever talking to the server.
- 32:46Or if it does talk to the server, it's just kind of an API call to figure out what data it wants to render on the page.
- 32:53But the page itself and the structure is not done through server calls.
- 32:56It's not done through redrawing the page or navigating.
- 32:59Even though sometimes you'll see the URL change, it might not actually go anywhere, right?
- 33:05That might just be something so you kind of know where it is, so you can bookmark and deep link into it, but it doesn't actually make the browser go, right?
- 33:12Yeah, that's the gist.
- 33:13I mean, one telltale sign of kind of an older SPA is if all the URLs, like if it's index.html or something, but then the meat of the URL is after the hash.
- 33:24So it's, you know, example.com slash and then a hash, and then the hash tells you everything about the URL.
- 33:31Right.
- 33:31That's a telltale sign that it's an SPA, an older one that used for that.
- 33:36Okay.
- 33:36Because then the client is looking at what's after the hash and deciding what it wants to render.
- 33:41And by client, I mean the website.
- 33:43View or PuePy or whatever the front-end framework is, is figuring that out.
- 33:48So in order to do that, in order to make these faux URLs or whatever you call them, actually kind of take you from place to place and navigate and redraw the page, you need something like the URL structure that would be built in Django or Flask or other things.
- 34:02And that's called a router, right?
- 34:04Right.
- 34:04And you guys have a router, right?
- 34:06So that's pretty awesome.
- 34:07There is a router.
- 34:08It's not as powerful as one in Flask or Django, but it gets the job done.
- 34:12Mm-hmm.
- 34:13Okay.
- 34:13Let's see.
- 34:14Here we go.
- 34:15Router.
- 34:15There's a bunch of really nice tutorial walkthrough.
- 34:18I went through most of these up to basically here, more or less, earlier today.
- 34:24And yeah, tell us about how you set up this router and how this works.
- 34:28You have a link component.
- 34:29That's probably not real interesting.
- 34:31But if you scroll down, when you define pages, there it is.
- 34:35App.page is a decorator.
- 34:37That's how you're telling PuePy that you've made a page.
- 34:40And the default page is the one that renders if there is no route.
- 34:44But you'll also see above it, pet page, where just like with Flask, the URL is in the decorator.
- 34:50So it's saying if you go to pet and then there's a pet ID, use that class to render the page.
- 34:55And I can put that whole URL without the hash in there and it'll find it.
- 35:00So I could just say my server slash pet slash dog or whatever the thing's ID is, then it'll invoke the router instead of the browser?
- 35:08Well, there's two routing options.
- 35:10One is that hash I mentioned.
- 35:11And that's easiest to set up because you don't then require any changes on the server.
- 35:18If you have a server you want, like if you have a Django project, let's say, and you want a single page app,
- 35:24how that has to work is whenever the browser opens a URL, Django, if it's a URL for the single page app,
- 35:32needs to return the single page app and not try to process the URL on server side.
- 35:37So there's some tricks to doing that.
- 35:39I think there's actually a couple Django packages now that do that.
- 35:43But you're essentially just putting a wild card up.
- 35:45So maybe example.com slash app and then anything after that URL renders the exact same page as if it were indexed on HTML.
- 35:54I see.
- 35:54Which would you recommend, the hash or the server hack?
- 35:58Well, the hash doesn't require any server hack, so that's convenient.
- 36:01But yeah, it probably doesn't require any server communications either, right?
- 36:05No, it doesn't require you.
- 36:07Not directly.
- 36:07I mean, you can just have a static HTML website that works fine doing that.
- 36:12If you want cleaner URLs, you want to use what's called HTML5 history mode.
- 36:18And that's where there's an API you can hook into on the browser and navigate around.
- 36:24And it'll look exactly like a normal website where you're changing the URL, but the page isn't actually reloading.
- 36:32Then when you reload, you need that server hack to make sure it always serves the same page.
- 36:38Got it.
- 36:38So in effect, that would be what's sometimes called deep linking, right?
- 36:43Where it doesn't just load up the front page of the spa and you click around and get back.
- 36:47But if you were on this page with these details and that's contained in the URL, you could bookmark it and come back and it should come back to that setup, right?
- 36:55Yeah.
- 36:55I mean, you have to test that to make sure you did it right.
- 36:58Yeah, of course.
- 37:00You browse around the site and it all seems fine.
- 37:03And then you come back and reload later and you get a 404 because you haven't configured your server to always go to the spa.
- 37:09Okay.
- 37:10Interesting.
- 37:11What about working with external data and from the front end, that usually means APIs, something like that, right?
- 37:19Can I use some of our standard code that we would for HTTPX or requests or things along those lines to call out?
- 37:28Or how do I call out from this?
- 37:30Networking is where it gets a little messy because the browser doesn't let you just have untrammeled access to open whatever sockets you want.
- 37:38You have to work within either web sockets or requests.
- 37:42And the best way to do that is using PyScript's fetch function.
- 37:46That wraps the browser fetch, which is the new XML HTTP request.
- 37:53Guys, so basically you kind of do an AJAX thing in the browser and then pick it back up from there.
- 38:00Maybe you get some JSON back, but then you could maybe use the JSON module to process it or...
- 38:05AJAX or web sockets are basically your choices.
- 38:08Okay.
- 38:09In the PyPI library example, you have beautiful soup 4 for parsing data.
- 38:14The example that you run, you can run it and it'll show you...
- 38:18Actually, that's a pretty interesting example.
- 38:20Maybe it's worth giving a shout out to is...
- 38:22I think it's this one perhaps is to go and refresh your thing.
- 38:29It will actually go and you can give it some part of HTML, some HTML.
- 38:34Like, I don't know.
- 38:35I'll just make up some...
- 38:36See how forgiving this is.
- 38:38So you give it any HTML, some basic page data that you have.
- 38:41And in here, when you run this, it'll use beautiful soup to parse it.
- 38:45And then the output at the bottom is that populate thing.
- 38:51So it'll basically recreate that DOM structure, take an HTML file or HTML content and convert it to the component style of PewPy, right?
- 39:01Yeah.
- 39:01I kind of made that as a utility because I might go have some HTML that I really want to render that is going to be part of my web app.
- 39:10And rather than going line by line and trying to figure out how to generate that programmatically in Python, you can paste it into here and get your Python back.
- 39:19Does it even do classes?
- 39:21Yeah.
- 39:21So it knows all about the attributes.
- 39:24Yeah, it sure does.
- 39:24That's pretty awesome.
- 39:25So maybe you could do something like write out an important chunk of HTML with all the tooling of PyCharm or VS Code or whatever.
- 39:33Copy, paste.
- 39:35And then get it here, right?
- 39:36Is that like an accelerated way to generate the first bit of structure and then just tweak it from here?
- 39:40Maybe you don't like writing HTML or don't know how to and you ask ChatGPT to write some for you and then you copy and paste it into here and see how it works.
- 39:50Yeah, that's a totally reasonable thing.
- 39:52ChatGPT is pretty good at writing HTML.
- 39:54It does make up stuff.
- 39:56If you say use this framework or that framework like Bootstrap or Tailwind or something, but it'll still get you pretty close.
- 40:01Yeah, it's decent.
- 40:02I've used it before.
- 40:03It was pretty excellent.
- 40:04Let's see.
- 40:05What?
- 40:06Let me rerun this whole thing here.
- 40:08What other things you want to give a shout out to?
- 40:11I guess maybe the refs concept here is worth talking about because this is an interesting challenge that people could run into.
- 40:19Yeah, this is a problem that would happen in Vue as well.
- 40:24As that state changes, as your application state changes, that populate function that defines your DOM runs on every single state change.
- 40:34Unless you can override that.
- 40:36Maybe there's a state that isn't important and you can turn that off.
- 40:40But that's the default.
- 40:41And so what that means is every time that you have a state change, the DOM could be different.
- 40:47And if the DOM is different and it patches the DOM, that means that the browser might have, let's say you're typing in an input element and the input element moves.
- 40:58You would lose focus on that element.
- 41:01And that's the example that you see in this demo.
- 41:04So if you give it a ref, that does two things.
- 41:08One, it identifies within that component.
- 41:11It's kind of like an ID, but it's local to the component.
- 41:14It's not a document-wide ID.
- 41:16It identifies it so that when it comes time to patch, it will reuse that HTML tag, that element in the DOM, and only update the attributes on it and the elements around it.
- 41:30So you get ultimately a smoother browser experience because it's being a little more intelligent about how it wants to patch the DOM.
- 41:39Right. So in your example, there's an input, and as you start typing into it with the naive, straightforward way, the thing reruns, but it regenerates the DOM in a way that completely blasts away that text input.
- 41:52Right.
- 41:52It puts it back, but as you type, now all of a sudden it goes click, click, click, or beep, beep, beep, because it's no longer focused on there because that's not actually the same text box.
- 42:01It's a new one with the same value, right?
- 42:03Right.
- 42:03And so in order to say, no, this thing is permanent, leave it here, don't recreate it for whatever reason, maybe you could use that for performance, right?
- 42:10If you had like a big grid that didn't change or something.
- 42:12Yeah, it would probably help with performance.
- 42:14You also can use it to just reference those components elsewhere in your code.
- 42:20Like if you have an event handler and you want to get at a DOM element that's rendered, you can reference self.refs, use the reference as a dictionary key, and that gets you the component.
- 42:31Yeah, sure.
- 42:32All right, so I really recommend that people come check out this tutorial.
- 42:35It's got a bunch of neat pieces and not just necessarily jumping in here into the iScript runner, but on the documentation, which is somewhere.
- 42:45I found it somewhere.
- 42:46There you go.
- 42:47There's actually like a really nice walkthrough.
- 42:50Like you start here, you click, take me to the next one, see that example run, right?
- 42:54At docs.pupy.dev, walk through the tutorial.
- 42:57That's really quite nice there.
- 42:58Thanks.
- 42:59I hope it's nice.
- 43:00I mean, send me any feedback because it's hard to write a tutorial for something you made yourself and understand pretty well.
- 43:07Yeah, that's a good point, right?
- 43:08Because you know how it's supposed to look.
- 43:11Yeah, it's hard to evacuate that assumed knowledge from your context.
- 43:17Yeah, yeah, yeah, exactly.
- 43:18Okay, so this looks like a pretty well-polished framework.
- 43:23It's still at its super, super early stages.
- 43:26So I guess a couple questions.
- 43:29One, contributors, PRs welcome.
- 43:32What's the thoughts there?
- 43:33Yeah, absolutely.
- 43:34That's why it's on GitHub.
- 43:35Yeah, yeah.
- 43:36And if people want to try to build with it, you know, they can give it a try and maybe they'll discover an issue and put it on the GitHub repo or something like that.
- 43:43Yeah, it'd be cool.
- 43:43And then sort of towards that end, what is its readiness for use?
- 43:49If somebody said, I want to be all in on Python, I think PyScript's awesome.
- 43:53What's the stability look like?
- 43:54Where would you classify it?
- 43:56Is it an experimental stage?
- 43:58Is it a beta?
- 43:58What is it?
- 43:59If you're someone who is comfortable using a relatively new project that has one contributor of GitHub, I think you know who you are.
- 44:07If you took this and you try to bring it to like a review board of a Fortune 500 company, I don't think they would go for it.
- 44:14But then again, a lot of things kind of get smuggled in.
- 44:18They might, they can always fork it.
- 44:19Exactly.
- 44:20That's what I was going to say.
- 44:21That's why they might, because while there's not a huge team behind it, they could fork it and say, look, this is important enough for us that we'll like take it over effectively if we have to.
- 44:30It's also just not that much code.
- 44:33Yeah.
- 44:33I mean, I've been kind of working on it on and off in my free time for like six months, but the volume of code, I mean, I don't know how many lines there are off the top of my head, but there's like four main files.
- 44:45They're relatively straightforward.
- 44:47Most of the heavy lifting is with PyScript.
- 44:49Yeah.
- 44:50In terms of stability and breaking, like it promised that I won't break anything, but I think it's pretty deliberately laid out.
- 44:58And like I said, one complaint I have about the node JS world is how aggressively everything gets broken every six months.
- 45:06So I have some PTSD from that and I'm not looking to recreate it myself.
- 45:11Yeah.
- 45:11No more left pad.
- 45:12That's not even the problem.
- 45:14The problem is just that it's the constant change.
- 45:16This version changes.
- 45:18And it also happens in CSS frameworks like, oh, we've got bootstrap six.
- 45:22And I know five was awesome.
- 45:24You wrote a bunch of stuff in it, but we're completely redoing it because it's better now.
- 45:27It's like it would be even better if it's if I didn't have to start over or get pinned in the past or whatever, you know?
- 45:33And yeah, if you're living in that world, like it's fine because you get up every day and you eat, breathe and sleep.
- 45:42Everything in your world is this node front end framework and it's your full time job.
- 45:47You can keep up with it.
- 45:49But if you're like me and it's just something you did and then six months later you need to revisit it, it's too much.
- 45:55Yeah.
- 45:56Yeah.
- 45:56Well said.
- 45:56Okay.
- 45:57Last CuPy question.
- 45:59Where are you going from here?
- 46:02Like what do you got next in mind?
- 46:04The testing is basically just Python unit tests.
- 46:07I'm not really, I don't have any automated testing for how it behaves in different browsers.
- 46:13It's fine.
- 46:14It's code runs the same in all browsers.
- 46:15Don't worry about it.
- 46:16Well, I mean, it might with PyStream.
- 46:19But I know it's getting better.
- 46:20It used to be really bad, but like I'm just now dealing with an issue like this video will play back on every single browser except this particular one on this particular OS.
- 46:29Like, great.
- 46:30Right.
- 46:30Okay.
- 46:30You know, it's that kind of stuff, right?
- 46:32Can't solve that kind of stuff for you.
- 46:34The actual Python language is going to be the same.
- 46:37Maybe not the JavaScript APIs you import.
- 46:40Yeah.
- 46:40Well, to a large degree, you're basically built upon the stability or lack thereof of MicroPython, which has been pretty stable.
- 46:48Yeah.
- 46:48MicroPython's great.
- 46:49Pyodide's great.
- 46:50Yeah.
- 46:51I would like to get some playwright tests to actually do proper end-to-end testing instead of just unit tests.
- 46:57I think probably some direct support for progressive web apps would be helpful.
- 47:03Helpful for everyone.
- 47:05I would like to have some kind of example on how to hook it up to like a Django or Flask backend.
- 47:11No, that's not usually in scope for a fun-end framework, but I kind of like the batteries included approach to development.
- 47:18Sure.
- 47:19You know, you talked about the progressive web apps, and I think they're great.
- 47:22I think it'd be like I've already said, I think it's completely possible to do with PyScript because I've done it on iOS.
- 47:29But it is great.
- 47:30The challenge with progressive web apps is the how do I get it in my dock?
- 47:35How do I install this thing like for real in a discoverable way?
- 47:38You know, I can come over on some of these things.
- 47:41I can like right-click on it and say, for example, if I right-click on a GitHub page, I can install GitHub, which means it will install as a progressive web app.
- 47:51But if I go to PyScript and right-click, it'll say create shortcut, which if I say open as a window kind of looks like it, but it's not.
- 47:57And just like that's not an end user experience, right?
- 48:02That's a dev user experience, I think.
- 48:04Yeah.
- 48:05That's not for you to solve.
- 48:06I mean, that's a problem with progressive web apps globally.
- 48:09That's nothing to do with your project.
- 48:11But it would be nice if there was like a really nice way to click this.
- 48:14Here's how it goes in your dock or your taskbar.
- 48:16And like.
- 48:16Yeah.
- 48:16I think the problem that they're butting up against is that the people who make browsers are keenly aware of how spammy websites get.
- 48:25So they don't want to have it be where you visit like a, you know, a newspaper and the newspaper prompts you to install the newspaper.
- 48:33So having that easily self-documenting install process is not there for the desktop.
- 48:40You have to actually go click add shortcut and then it works.
- 48:42Right.
- 48:43Right.
- 48:43The Safari folks.
- 48:45I've been, I talked Apple down a little bit from their really horrible app store review experiences they put on people.
- 48:52But the Safari browser, which I don't generally use, but they've got a really nice install this, you know, go to file, add to dock.
- 49:01And then that experience, the lifecycle of using that app once you've done it is real nice.
- 49:05So, I mean, add to dock is I want this app as an applicant thing where my other apps are.
- 49:11That's pretty good.
- 49:12Yeah.
- 49:12I've like I've installed Google's old chat app, which I still use as a progressive web app using Safari on my desktop.
- 49:20And it's great.
- 49:21It's it's just like another application that I've downloaded and installed in it.
- 49:25It's Safari, which is fine.
- 49:27Yeah.
- 49:27As long as it stays in its little container and doesn't infect my Vivaldi experience.
- 49:32I have Proton Drive, Gmail, Google Contacts, Google Calendar, some of the e-commerce stuff that I have to do.
- 49:40I've got the analytics, my email newsletter app.
- 49:44I've got YouTube, YouTube Music.
- 49:46All those things are all installed that way these days for me.
- 49:49And it's really, really nice.
- 49:50It beats having all those Electron apps running.
- 49:52It does.
- 49:52However, I don't see any reason why this stuff wouldn't work for Electron as well.
- 49:57Right.
- 49:58You can ship your Electron app with a HTML page and then you can just put this PyScript and PewPy as part of your HTML.
- 50:05And it should it's on the client side.
- 50:07It should just run in Chrome just fine.
- 50:09It should.
- 50:10You know, I don't know what the process for that would be.
- 50:12The developer in me says make it a PWA.
- 50:14But I'm I'm sure there's some business cases for making it a .app file.
- 50:19It feels more real.
- 50:21Maybe data storage, maybe access to OS features.
- 50:25I know it's that's getting better, but it's running natively on the machine.
- 50:28You can do whatever you need to do.
- 50:30So possibly.
- 50:31That's true.
- 50:32That might get a little messy in terms of importing those features once in JavaScript and then from JavaScript into PewPy.
- 50:41Yeah, you might have to have a multi-layer interop type thing that's a little bit funky, but.
- 50:46Yeah.
- 50:47My suspicion is that most people making Electron apps have a team that does front end work.
- 50:54And probably that front end work is going to be in JavaScript.
- 50:57Right.
- 50:58Yeah, probably some framework there.
- 51:00All right.
- 51:00Awesome.
- 51:02So I think PewPy has got a lot of potential.
- 51:04That's why I invited you on the show to talk about it because it's it's very interesting.
- 51:08And honestly, it's this kind of stuff I would love to see when I visit PyScript and not a REPL because, right, that's not what most people do.
- 51:15I know it's PyScript's a little more data science focused, but even for them, they more have a notebook experience generally.
- 51:21All right.
- 51:22I do have a question, though.
- 51:23So I noticed when I was going through the documentation here for your PewPy docs that it says powered by JetBrains right side, writer side.
- 51:32Tell me about that.
- 51:32I have not used this, but it's like a new IDE for recruiting documentation and testing and stuff.
- 51:38Like, what do you think about this?
- 51:39Now you've got to play with it a little.
- 51:40Well, you're basically just calling out laziness on my behalf because all the real Python projects are using something awesome like Sphinx.
- 51:49And I have the JetBrains all products license.
- 51:52So I just saw that and tried downloading it.
- 51:56It works well.
- 51:57There's zero setup.
- 51:58You just open it up and start typing in Markdown.
- 52:01It's clean and polished.
- 52:03If you have a JetBrains license, you might as well try it out.
- 52:07But I expect that if people start contributing to the documentation, I'll need to switch to something more community oriented.
- 52:15Potentially.
- 52:15I can't remember.
- 52:16I feel like writer side might integrate with some of those frameworks like Sphinx.
- 52:20But I'm asking about all this because I've not used it at all.
- 52:23So I don't really know.
- 52:24It's kind of its own framework.
- 52:26It supports Markdown, but it has its own little kind of HTML-ish thing for making tabs and glossaries and all that.
- 52:34Yeah, excellent.
- 52:35Excellent.
- 52:35Okay.
- 52:36And then I guess anything else you want to give a shout out to or talk about on the PuePy side of things when we wrap up our show?
- 52:44I would kind of like to give a shout out just to the PyScript people.
- 52:47I've gotten stuck a few times and headed over to their Discord server and they're always really friendly.
- 52:54They run little meetups kind of on Zoom with the community.
- 52:58And they've been great.
- 53:00I wouldn't have been able to do this without their help.
- 53:02Yeah, awesome.
- 53:03They have been helpful for me as well.
- 53:05All right.
- 53:05And then notable IPI project library?
- 53:09Completely unrelated.
- 53:11But there is a project called PGQer.
- 53:16There you have it pulled up on GitHub.
- 53:18And if you want something kind of like Celery, but you don't want to have to install Celery and install a broker and figure out your Celery installation and make maybe even another Docker container for your workers, this is great.
- 53:33It uses some Postgres.
- 53:38You don't want to have a simple task queue.
- 53:42I've tried it.
- 53:43It works great.
- 53:44You can probably Celery is still, you know, quote unquote, better for complex needs.
- 53:50But if you just want something simple, this is great.
- 53:52Yeah, it's cool.
- 53:52I mean, the truth is most of us have not complex needs, simple needs.
- 53:56And then bringing that kind of stuff in just makes it way more complicated from a DevOps perspective, right?
- 54:02Like, I'm already talking to a database.
- 54:03I'm already talking to Postgres.
- 54:04What if I could just use it?
- 54:06There's a lot to learn with Celery.
- 54:08Like, it's a whole project unto itself.
- 54:10Sure.
- 54:11Yeah, over at Talk Python, I've got a MongoQer equivalent.
- 54:15That is, you know, because you scale out the worker processes, right?
- 54:19So it's not enough to just have them running.
- 54:21You want a little more durability in case for some reason, like the server restarts, but there's still work to be done.
- 54:26You just come back and look.
- 54:28Oh, look, there's some unprocessed work in the database.
- 54:30Let's do that.
- 54:31It's nice.
- 54:32It's not quite as nice as this, I think.
- 54:34But, I mean, suppose if it said send an email and it, like, had sent the email, but it hadn't acknowledged it sent the email yet, and you restart the server at that very moment, the person's probably getting a second email.
- 54:45You know what I mean?
- 54:45But there's a really, really small chance of these types of things.
- 54:49It's much more common to, like, you know, re-index these things or whatever.
- 54:53I think, actually, with PGQer, because it's Postgres, you would get strong consistency.
- 55:00So the chance of that duplicate email would be low.
- 55:03Well, but imagine this, like, if you do a transaction and you go to, like, start, let's say, like, I'm going to move the work into running.
- 55:10And then if you shut it down, that transaction's going to roll back and it'll probably go back to ready to run.
- 55:15I mean, I don't know how you deal with it.
- 55:17I mean, it almost comes back to the poison message thing of, like, celery and message queues, which is really very tricky.
- 55:23Like, sending an email, the thing is, you can't put that in your transaction.
- 55:27Yeah, exactly.
- 55:28You can't unset.
- 55:29Well, a few things have tried to recall email, but as in general, email doesn't support rollback.
- 55:34No, it might be a good feature for, like, SendGrid to consider.
- 55:37Yeah, it would be very cool.
- 55:38One thing you can kind of do in those situations, if you happen to have, like, Redis or something available, is if you, the content of the email is going to be exactly the same.
- 55:48So if you just hash the email to, identify it somehow, a combination of the email content and who it's for, and then you get a hash of that, then you can have a little Redis key.
- 56:00And if that Redis key is set, email has been sent and you can discard the task.
- 56:04Yeah, yeah.
- 56:05You just put that right next to where you've actually sent the email.
- 56:08And the chance that it's going to crash in between those two is pretty low.
- 56:11It's extremely low.
- 56:12Yeah, exactly.
- 56:13So things like this, things like that solution you talked about, while not bank-level bulletproof, most of us don't want to suffer through that level of durability, right?
- 56:22So very cool project.
- 56:23Yeah, I like it.
- 56:24Awesome.
- 56:25All right, Ken, final call to action.
- 56:26People are like, oh my gosh, front-end Python, what do they do?
- 56:31Well, I don't want to oversell it as solving all your problems, but if you want to check it out, PewPy might need spelling out.
- 56:37It's P-U-E-P-Y.dev.
- 56:41Excellent.
- 56:43And love the initiative.
- 56:44Happy to shine a light on the project.
- 56:46Would like to see it grow.
- 56:47Awesome.
- 56:47Thanks for having me on.
- 56:49Yeah, thanks for being on the show.
- 56:50Bye.
- 56:50Bye.
- 56:51This has been another episode of Talk Python To Me.
- 56:55Thank you to our sponsors.
- 56:57Be sure to check out what they're offering.
- 56:58It really helps support the show.
- 57:00Take some stress out of your life.
- 57:02Get notified immediately about errors and performance issues in your web or mobile applications with Sentry.
- 57:08Just visit talkpython.fm/sentry and get started for free.
- 57:13And be sure to use the promo code Talk Python, all one word.
- 57:17Code Comments, an original podcast from Red Hat.
- 57:20This podcast covers stories from technologists who've been through tough tech transitions and share how their teams survived the journey.
- 57:29Episodes are available everywhere you listen to your podcasts and at talkpython.fm/code dash comments.
- 57:35Want to level up your Python?
- 57:37We have one of the largest catalogs of Python video courses over at Talk Python.
- 57:41Our content ranges from true beginners to deeply advanced topics like memory and async.
- 57:46And best of all, there's not a subscription in sight.
- 57:48Check it out for yourself at training.talkpython.fm.
- 57:51Be sure to subscribe to the show.
- 57:53Open your favorite podcast app and search for Python.
- 57:56We should be right at the top.
- 57:57You can also find the iTunes feed at /itunes, the Google Play feed at /play, and the direct RSS feed at /rss on talkpython.fm.
- 58:07We're live streaming most of our recordings these days.
- 58:10If you want to be part of the show and have your comments featured on the air, be sure to subscribe to our YouTube channel at talkpython.fm/youtube.
- 58:18This is your host, Michael Kennedy.
- 58:20Thanks so much for listening.
- 58:21I really appreciate it.
- 58:22Now get out there and write some Python code.
- 58:24I'll see you next time.