Latest / Talk Python To Me / #449: Building UIs in Python with FastUI
Transcript
- 0:00Building web UIs in Python has always been an interesting proposition.
- 0:04On one end, we have the full web design story with artisanal HTML and CSS.
- 0:09On the other end, there are several Python platforms that aim to bring RAD,
- 0:13rapid application development style of building Python apps to the web.
- 0:18Those can be great, and I've covered a couple of them,
- 0:21but they usually reach a limit on what you can do
- 0:24or how they integrate with the larger web ecosystem.
- 0:27On this episode, we have Samuel Colvin back to share his latest exciting project, FastUI.
- 0:33With FastUI, you can build responsive web applications using React
- 0:38without writing a single line of JavaScript or touching npm.
- 0:41Yet designers and other tools can focus on React frontends
- 0:46for a professional spa-like app experience.
- 0:48This is Talk Python To Me, episode 449, recorded December 14th, 2023.
- 0:55Welcome to Talk Python To Me, a weekly podcast on Python.
- 1:12This is your host, Michael Kennedy.
- 1:14Follow me on Mastodon, where I'm @mkennedy,
- 1:17and follow the podcast using @talkpython, both on fosstodon.org.
- 1:22Keep up with the show and listen to over seven years of past episodes at talkpython.fm.
- 1:27We've started streaming most of our episodes live on YouTube.
- 1:31Subscribe to our YouTube channel over at talkpython.fm/youtube
- 1:34to get notified about upcoming shows and be part of that episode.
- 1:40This episode is sponsored by Bright Data.
- 1:42Bright Data is professional web scraping in a dataset marketplace.
- 1:46If you need data and it doesn't have an API,
- 1:49check out talkpython.fm/Bright Data today.
- 1:53And it's brought to you by Sentry.
- 1:56Don't let those errors go unnoticed.
- 1:58Use Sentry like we do here at Talk Python.
- 2:00Sign up at talkpython.fm/sentry.
- 2:05Hey, Samuel.
- 2:06Welcome back to Talk Python To Me.
- 2:07Thank you.
- 2:08Thank you very much for having me again.
- 2:09So soon after last time.
- 2:11It's always amazing to have you on.
- 2:12In fact, you were on just last week in a really cool show that tons of people enjoyed
- 2:19and is not yet out at the time of recording, but will be released to the world
- 2:23by the time your show goes out live.
- 2:25So it's a bit of a time travel thing.
- 2:27Very, very appropriate here.
- 2:29But it was under the full-time open source developers panel of like a bunch of folks,
- 2:35for example, Charlie Marsh, Will McGugan, Gina Houska, and so on, right?
- 2:40And you snuck in for a minute there on your travels.
- 2:44But now you're back and we're here to talk properly about something really excellent
- 2:49that you put together called Fast UI, which is going to be a lot of fun.
- 2:53Yeah.
- 2:54Thanks so much for having me.
- 2:55And yeah, I'm in a slightly better environment for a podcast than the stairwell of a restaurant
- 3:01somewhere in Istanbul.
- 3:03So yeah, it's nice to be there.
- 3:04High marks for effort there.
- 3:06Come on.
- 3:06That was great.
- 3:07It was good fun, but this is a better place to talk about these things.
- 3:12Yeah.
- 3:12Well, I hope you had a good trip and you're back in at it.
- 3:15Kim out in the audience points out, hey, could you just write another impressive tool for
- 3:19the next week's show?
- 3:20Because things are going pretty prolifically over there.
- 3:23Tell people a bit about Pydantic, the company they probably heard of the library, but just
- 3:27what are you up to these days?
- 3:29So Pydantic's obviously been around since 2017 originally, but then it's like something weird
- 3:34happened at the beginning of 2021.
- 3:36I don't know quite what that was, but Pydantic, the downloads just went crazy.
- 3:40So we were at 5 million downloads then and we're now at 130 million.
- 3:43So yeah, it's gone crazy.
- 3:46And then just a bit more than a year ago, I was very lucky.
- 3:49Sequoia got in touch with me and basically said that I want to start a company.
- 3:53I had been meaning to do that after I released Pydantic V2 that I was then working on.
- 3:58Yeah.
- 3:58I started the company beginning of this year and now have an amazing team of 10 people
- 4:03working with me.
- 4:04So we released Pydantic V2 finally.
- 4:06Having originally told people it would take me alone three months, it took me and I guess
- 4:10then six people a year in total.
- 4:12But that was released back in the summer.
- 4:15And now we're working on a platform that I'm not going to talk about now, but I would love
- 4:19it if you'd have me back, I guess, beginning of Q2.
- 4:22Is that next week or whatever?
- 4:24It's not quite next week.
- 4:25Q2 in 2024?
- 4:27Something like that?
- 4:28Yeah.
- 4:29I think we're going to try and get to Open Beta in Q1.
- 4:32So yeah.
- 4:33Okay.
- 4:33Fantastic.
- 4:34Yeah.
- 4:35Well.
- 4:35But off the back of, so that without getting as much details on it has platform component
- 4:41to it.
- 4:41And so we have people, people will be logging in, et cetera, et cetera.
- 4:44And I was just thinking about all of the path and the churn of building the relatively mechanical
- 4:50bits of an application.
- 4:51Again, it doesn't matter actually if you're building it with React or with one of the other
- 4:55front-end frameworks, you end up having a whole bunch of stuff that's duplicated between
- 4:59what the front-end guys are doing and what the full-stack developers or the back-end developers
- 5:04are building for us.
- 5:06And I guess for lots of people, there's a Pydantic model that's kind of at the core of lots of
- 5:09those bits.
- 5:09And I was just dreading all of that churn.
- 5:12And I had been wanting to build something like Fast UI for a long time, but the fact that we're
- 5:16going to be using it internally really spurred me on to go and get it built and release it
- 5:21in like a very incomplete phase to see what people thought.
- 5:23And yeah, there's been a great reaction.
- 5:25And here I am.
- 5:26Yeah, there has been quite the reaction to it.
- 5:28Let's see.
- 5:29Do the GitHub star test.
- 5:31It's 2.6 thousand stars and it's what?
- 5:36Two weeks old?
- 5:36Yeah.
- 5:37A month old?
- 5:37Yeah.
- 5:38A month old?
- 5:38Last month anyway.
- 5:39Well, it was only released publicly like, yeah, two weeks.
- 5:42Less than two weeks ago.
- 5:43Or maybe two weeks ago today.
- 5:44Oh, that's right.
- 5:45Yeah.
- 5:45You probably, so you worked on it a little bit private and then you flipped the bit on the
- 5:50public status.
- 5:50Yeah.
- 5:51That makes a lot of sense because you don't want people just to go, whoa, what are they building?
- 5:54I mean, maybe you do.
- 5:55What is this GitHub repo?
- 5:56They misspelled FastAPI.
- 5:59I don't know what they're working on.
- 6:00Yeah, exactly.
- 6:02And also, I mean, we have a team with lots of people who've done lots of open source, very
- 6:06strongly opinionated engineers.
- 6:08engineers.
- 6:08I can't even get my team to use it without kind of proving the value in it.
- 6:12So I worked on it a bit without really talking to them and then was like, right, I built this
- 6:15thing.
- 6:16Let's at least give it a try.
- 6:17Yeah.
- 6:17Because I don't know.
- 6:18Maybe I'm wrong in this.
- 6:20But I think it's quite a fundamentally different way of thinking about how you build user interfaces
- 6:26from lots of the tools that exist today in the Python ecosystem.
- 6:30And so there's a bit of a like education piece and trying to understand the principle as well
- 6:35as the like mechanics of going and using it.
- 6:37Yeah, absolutely.
- 6:38Well, we're going to dive into the philosophy, but I'll give people that too long didn't read
- 6:43version.
- 6:43Basically, you can create UIs in pure Python in sort of dynamic web framework friendly ways.
- 6:50Right.
- 6:51Yeah, probably the mistake is in my description of it because yes, it does that.
- 6:55But where I personally think fast UI is powerful and where we're using it in within the
- 7:01pedantic team is actually we have got front end developers.
- 7:04We've got some really expert guys like who are very comfortable building stuff in react.
- 7:08But we want to those two roles to have to constantly communicate to build every every
- 7:13individual bit.
- 7:14So the idea is I think if you go down the page a little bit, I kind of explain it.
- 7:18But like for a front for a Python developer, it's this way of building UIs without having
- 7:22to touch TypeScript or JavaScript or npm or any of those Byzantine like massive build tools.
- 7:28But then for a front end developer, it's this opportunity to go and build the best components
- 7:32you can and allow basically provide a powerful interface for your back end guys to go and build
- 7:38a build a UI with it.
- 7:40So kind of split those two things up and I guess allow react to do what react does brilliantly,
- 7:44which is allow which is provide these like reusable components.
- 7:47Yeah, absolutely.
- 7:48Kind of a framework as well to bring the navigation and the cohesion of the whole app together,
- 7:53not just a particular view or a page to what you would say, right?
- 7:56Yeah.
- 7:56Yeah.
- 7:57So the weird bit is principle of RESTful interfaces.
- 8:00We've all heard of RESTful and we all think we know what it means, which is basically something
- 8:05to do with a URL structure and return me some JSON that like gives me the data I need to render
- 8:10my view.
- 8:11Well, if you look at the rifle that Roy Fielding's original PhD, as is brilliantly described in
- 8:16this HTMX article that I talk about further on down here.
- 8:19He's not really talking about that stuff.
- 8:21Sure.
- 8:21He has some stuff on what the URL structure should be.
- 8:24But really, his principle is that the data returned from the back end should be self-describing
- 8:30as if it should have everything you need to go and render the user interface.
- 8:34So let's say, I think they're using the HTMX example, example of like a bank account.
- 8:38And if you go down to like principle, the long version, here we are, right?
- 8:43I've linked to the PhD, but more importantly, the HTMX article, which explains it really well.
- 8:47I think if we follow that, yeah, I think they'll even on that page, there's a very jokey tone
- 8:51lots of the time HTMX, but they also talk about a really cool thing.
- 8:55Yeah, absolutely.
- 8:56Somewhere I think they have, yeah, here we are, right?
- 8:57So if you look at the traditional JSON response, which I think is the second one, and you were
- 9:01trying to show, yeah, right.
- 9:03So this, you and I as humans can read this and be like, yeah, that kind of explains my
- 9:07bank account and what's going on.
- 9:08But there was not enough.
- 9:09It's got like an account number and a balance, which is a more complicated object, nested object
- 9:13and those types of things.
- 9:15Right.
- 9:15It's got all the things that we can read account number.
- 9:17Cool.
- 9:17That's a number balance.
- 9:18Yeah, that makes sense.
- 9:19But if you're a computer, there's not enough there to go and render someone the nice user interface
- 9:24they would want where they would have it displayed on a page.
- 9:26So if you were the engineering team in the bank trying to turn this into a web interface,
- 9:32you then need to go and have lots of very application specific or page specific logic to show where
- 9:39the account number goes and where the balance goes and where the status goes and stuff like
- 9:42that.
- 9:42And that causes an enormous amount of churn.
- 9:44And it means that it's particularly difficult when you have those engineers working in different
- 9:48time zones because you end up having this spec between the two.
- 9:51And then you always have this problem with software where fine, we can get it to work.
- 9:55But what happens when we come to add it?
- 9:56So what's the process of, let's say, we want to show as well on this page, your like joint
- 10:02account balance, let's say, just to make something up.
- 10:04What we probably need to do is we need to get back in guys to go and add that to endpoint.
- 10:09And then the front end, and that can be deployed.
- 10:12And then the front end can be updated to show that and the data is available.
- 10:15That is a lots of churn, lots of delay.
- 10:18Right.
- 10:18Lots of coordination between the two domain experts.
- 10:22And then it kind of, you've got that microservice cascading, like it's got to do, then this one's
- 10:26got to be upgraded.
- 10:27And then eventually there's enough flow of data through the system that the UI people can put
- 10:32it up there.
- 10:33Right.
- 10:33Right.
- 10:33And so, and it's bad in this case of like showing your bank balance, but it gets even
- 10:38worse when you have a form where every field in the form needs to be completed, for example.
- 10:44And so we basically have to deploy the front end that has all of the form components and
- 10:48the backend that receives that new form at the same time.
- 10:52And we've got this Pynantic model that, you know, depending on how we've done it, probably
- 10:56is used to define our form.
- 10:57And it might even be used to define our database.
- 10:59But like, we're not using a Pynantic model in the front end.
- 11:02TypeScript, in my opinion, is a big Achilles heel in typing is that you don't have any, you
- 11:07can't use type ins at runtime.
- 11:08And so we don't have an equivalent of Pynantic.
- 11:12And so we're basically trusting that data is how it is.
- 11:14So yeah, FastAPI is an attempt, sorry, Fast UI is an attempt to basically remove that
- 11:20need to like have complete synchronization between backend and front end by having beautifully
- 11:25designed components in the front end.
- 11:27Not saying what we have now is that beautiful, but that's the ideal log term.
- 11:31But then the backend can basically just do the orchestration, can say, show me a table,
- 11:35show me a form, show me a modal and put the following content in it, et cetera.
- 11:39Excellent.
- 11:40Nice comment from Tony on the audience.
- 11:42As I originally started in Python and went to using TypeScript, Pynantic made the transition
- 11:46back to Python so nice.
- 11:48And so in your description, you also have up here that this Pynantic is interesting,
- 11:54is involved here.
- 11:55Like what is the role that Pynantic plays in defining all this?
- 11:58So the idea is that we're getting to, of this RESTful UI is really that we end up having a
- 12:04bunch of components in a shared definition of some components.
- 12:08And we basically promise that the backend is going to send data that matches the types
- 12:13defined in the front end.
- 12:15Well, that's all very well, but if you're not careful, you end up not sending quite the
- 12:19right data.
- 12:19So what's nice is that all of the components that you can return from fast UI are themselves
- 12:25Pynantic models.
- 12:26So Pynantic goes off and does not only the validation, but also the coercion.
- 12:31And it does stuff like uses camel case.
- 12:33So the front end developers are happy because we've got no underscores anywhere.
- 12:36And so, yeah, all of the backend code for fast UI basically is just Pynantic models, which
- 12:44implement these components.
- 12:46Right?
- 12:47So it might be useful for those who can see this to go in and I can talk through an example.
- 12:51If we go into the code here and I can talk you through like a very basic component.
- 12:55Oh, maybe it'd be useful.
- 12:56I showed it here.
- 12:57So I've got the code base open here, just working on something.
- 13:02But if I open up here, source and then the Python package, and then we look into components and
- 13:08we can look at like a really simple component, probably a button, which would be kind of understandable
- 13:13to everyone.
- 13:14Where's button?
- 13:15Here we are.
- 13:15So this is just a plain Pynantic model, which contains text, which is the text you put within
- 13:20the button.
- 13:21Then it contains the event that you want to fire when someone clicks on it.
- 13:24And HTML type, which, you know, this matches what you can get in HTML button, reset, submit,
- 13:31and then class name, which becomes the classes that get applied.
- 13:35And then critically, this type, which is a literal, which has to be button.
- 13:39And that is used by the discriminated union in Pydantic to do the validation of different
- 13:45types.
- 13:45And it's also used by a big switch statement in the TypeScript to basically decide what component
- 13:51I'll go and render when I get an object.
- 13:54Right.
- 13:55So there's some TypeScript.
- 13:57Maybe it makes sense to talk a bit about the building blocks.
- 14:01You say FastUI is made up of four things, just so people can get a sense of like, you
- 14:06know, what's at play here?
- 14:07Right.
- 14:07So the four things that we have now, package, a Python package called FastUI, which I was
- 14:12just showing you there the types for.
- 14:14Yep.
- 14:14And then we have npm package called FastUI.
- 14:17Again, it's in the Pydantic organization, which is where the meat of the logic resides.
- 14:23And that's implementing basically the most of the components and all of the wiring to mean
- 14:29that when I return a button, the button component gets rendered.
- 14:33And then, but obviously, we don't probably want to end up using a vanilla button when we come
- 14:38to display it.
- 14:40So then I've implemented basically customization of the FastUI React library using Bootstrap.
- 14:45So all that's really doing is it's deciding what classes to append to use with each component
- 14:50and also just customizing a few of them.
- 14:52So for example, modal, there's no like nice way to do a vanilla modal.
- 14:55So the modal in the default FastUI, the end package just basically shows me alert saying
- 15:01this isn't implemented.
- 15:02Whereas the Bootstrap one uses a nice Bootstrap modal.
- 15:05And then we have finally FastUI prebuilt, which basically uses the FastUI package, customizes
- 15:11it with FastUI Bootstrap, and then builds it.
- 15:14And that means we can go and basically return that prebuilt React app without having to get
- 15:20our hands dirty with npm on Yarn and Vite and all the other.
- 15:24All the webpacky bundling, minifying, transpiling business.
- 15:29But the cool bit, in my opinion, of FastUI is that at its core, it's really the definition
- 15:33of a bunch of different schemas effectively.
- 15:36Those schemas are defined in Pydantic and they're defined in TypeScript, but they could
- 15:40perfectly well be, and really nicely, I just merged this the other day, we now use the JSON
- 15:46schema generated by Pydantic and JSON schema generated by the React types to basically go
- 15:53and test that there's an equivalent between those two models everywhere.
- 15:57But in theory, there's nothing to stop the front end from being built with another JavaScript
- 16:01library or even with something like HTML and HTMX.
- 16:04Or even you could go and use React Native and build, or even some kind of embedded device,
- 16:09you could go and implement those components.
- 16:11And then on the other side, and this is even more achievable, you could go and return data
- 16:16that matches those models from a Rust or Go service.
- 16:20And in theory, you don't have to change your UI at all, because all you're doing is I promise
- 16:24that I'm going to match these schemas, and then whatever front end or whatever back end
- 16:29can then communicate.
- 16:30Whether that comes to pass, I don't know yet.
- 16:32And obviously, I built the default back end in Pythin, because that's what I know best,
- 16:36and where I think Pydantic is really helpful.
- 16:38And I built the first front end in React and TypeScript, because one, that's what I know,
- 16:43and two, it's what we're using within Pydantic.
- 16:45But lots of people have asked about HTMX.
- 16:48People have also asked about Svelte and others.
- 16:50I think I wouldn't see the point in building fast UI in Vue, because I don't think it adds
- 16:55much.
- 16:56It's just a lot of work.
- 16:57But I think there's a world where we build a HTMX template rendered version of fast UI's
- 17:03front end that could be super valuable.
- 17:04That's interesting.
- 17:05So first point is, these different components sound like they are potentially a little mix
- 17:11and match.
- 17:11You know, you could take it all as one big thing, or you could say, really like the way
- 17:15it defines the React front end, but we're going to implement it some other endpoint.
- 17:20Yeah.
- 17:20I think it's something like, it'll be slightly skewed now because of tests, but I'd say it's
- 17:26sort of twice as much front end to back end at the moment, as in the, yeah, it's skewed
- 17:30a bit by tests, but even now there's more TypeScript.
- 17:33So I think the simplest thing to do, and you could do it pretty trivially would be to
- 17:37use another backend, another language for your backend service.
- 17:41And as long as it matches those types, and you could even go and use something like JSON
- 17:45Schema to enforce that.
- 17:46But yeah, re-implementing the front end, probably a bigger piece of work, but totally doable.
- 17:51I mean, I did it in my spare time in two weeks, built the whole thing.
- 17:54So it's not, you know, millions of different things.
- 17:56There's kind of 20 components at the moment that are then composable to build reasonably
- 18:00sophisticated like UIs.
- 18:02So this is a web front end, like Flask or Django sort of framework, but a way that really
- 18:08incorporates building the UI in Python and validating and enforcing that with Pydantic
- 18:14rather than just, hey, file new HTML.
- 18:17Let's just start typing and hope they line up, you know, like instead of trying to juggle
- 18:21all those different languages, CSS, HTML, all the JavaScript tooling for packing up stuff,
- 18:26just let's write Python, right?
- 18:28So maybe you have a simple example of what it looks like to define a real simple example
- 18:34here on the readme.
- 18:37It's got a very interesting parity between what is in the HTML DOM and is what is in the Python
- 18:44abstract syntax tree, I guess, right?
- 18:48And visually as well, the way you look at the code, it looks like the way it might look in
- 18:53HTML.
- 18:53Like give us a sense of what writing a UI in this would look like.
- 18:57Right.
- 18:57So I think the first of all, we have to talk about like the two enormous, the two most obvious
- 19:01pitfalls for this.
- 19:02One end of the pitfall you have, which I think is the biggest temptation is to basically mirror
- 19:09all of HTML in Python.
- 19:11And for those of us who are happy writing HTML or writing React, that sounds like hell.
- 19:16It's going to be slow because you have to do some weird rendering, but it's also just going
- 19:19to be a pig because I don't want to have to define every A, HRA, and everything else in
- 19:24Python code.
- 19:25It says, and there are going to be, it requires for a start, it requires you to know two things,
- 19:29Python and HTML.
- 19:30Whereas for HTML, you only need to know one.
- 19:34This portion of Talk Python To Me is brought to you by Bright Data.
- 19:38Bright Data helps you turn websites into structured data.
- 19:42There's an unimaginable amount of data available on the internet.
- 19:46And we're lucky to live in a time where we have so many APIs to access structured data.
- 19:52But the truth is that most of the data out there is not served up over a clean API.
- 19:58It's just sitting there on a web page as HTML.
- 20:01Maybe it's even further obscured behind some front-end JavaScript framework like Vue or React.
- 20:07What if you need access to that data?
- 20:09Web scraping to the rescue, right?
- 20:12Yes, but just like you wouldn't set up your own production infrastructure in your home office,
- 20:18running a web scraping job on a single computer at a fixed location can lead to a web
- 20:22your program being unreliable with data pinned to that IP's location and much of the time
- 20:28blocked for rate limits and other such causes.
- 20:30If you need to do professional web scraping, Bright Data is the place to start.
- 20:35They have award-winning proxy networks and powerful web scrapers.
- 20:39What's more is they have ready-to-use datasets for download,
- 20:43so you might not even need to scrape data at all.
- 20:46And if you can't find the dataset in their marketplace,
- 20:49they'll even build a custom dataset for you.
- 20:52From listening to the show, you know that I'm a privacy-conscious person,
- 20:56and that's why I'm happy to see that they are both CCPA and GDPR compliant.
- 21:01Bright Data has both low-code solutions as well as Python programming models with Async,
- 21:07IO, and Playwright.
- 21:08So if you have serious data needs and those websites don't offer APIs,
- 21:13then you need Bright Data.
- 21:15check them out today at talkpython.fm/brightdata.
- 21:19And please use that URL.
- 21:21That way they know you heard about them from us.
- 21:23That's talkpython.fm/brightdata.
- 21:27The link is in your podcast player show notes.
- 21:28Thank you to Bright Data for supporting the show.
- 21:32I always find these things that try to dodge,
- 21:35like dodge the fact that HTML exists.
- 21:37I find them, I don't know, I just, they don't resonate with me.
- 21:40I'm not entirely sure why.
- 21:42It's like, we have really nice things like CSS,
- 21:44and we have really, there's just so much tooling and frameworks,
- 21:50you know, you mentioned Brutestrap already, right?
- 21:53That just plug into there.
- 21:54And if it's like, well, we're just going to write, recreate it in Python.
- 21:57Well, it has all the oddities of HTML if it's going to be really high parity.
- 22:02And then you just have a less well-known way to do the same weird thing.
- 22:06You know, I don't know.
- 22:06It just, it doesn't resonate super with me.
- 22:08I agree.
- 22:09And I found the same thing at times with ORMs,
- 22:11that you end up, the worst case of an ORM is you work out what you need to do in SQL.
- 22:15Then you try and translate back from SQL to ORM,
- 22:18and it would be much nicer just to write my SQL.
- 22:21I mean, not always the case.
- 22:22ORMs can be powerful, but I think that they both can fall into the same trap if you're not careful.
- 22:27And then I was going to say, at the far end of the spectrum,
- 22:29the other end of the spectrum, you have, and I guess Django's admin view,
- 22:33for understandable reasons, could suffer from this,
- 22:35that you basically have a very small set of things.
- 22:36You have a table page and a details page and a form page, and that's kind of it, right?
- 22:41So there's this difficult trade-off, and where in that continuum
- 22:44do we try to choose what size of component to implement, right?
- 22:48So for example, here we have a heading,
- 22:50which is almost one-for-one matches what you would do in HTML.
- 22:54We have the text that goes within it, and we have the level,
- 22:56which, you know, it's slightly different syntax,
- 22:59but it's basically one-for-one matching an HTML tag.
- 23:02But then we have a table, which it doesn't look very much like an HTML table at all.
- 23:07We're not having to explicitly define the table body versus the table head.
- 23:12We're not having to put in each column.
- 23:13We're not having to worry.
- 23:15Yeah, there's lots of stuff here that is much less like it.
- 23:17And that's where it's in these very common components where there is consistent things
- 23:23that lots of people want to do, or lots of places in your app where you might want to do them,
- 23:26where I think a framework like Fast UI gets super powerful,
- 23:30because we can get you a table here with users defined and with a few columns with some customization
- 23:37on what happens when you, how we render each column much more quickly,
- 23:41then we could go write out all the HTML for that.
- 23:43And it's much more concise to read.
- 23:45It's like, it's consistent enough that something like GitHub Copilot will help you write it out
- 23:50where you do have a bit of customization to do.
- 23:52I think this is where it can be super powerful.
- 23:55Yeah, it is pretty interesting.
- 23:56And I like the hierarchy.
- 23:57For people listening, just check out github.com/pydantic slash fast UI.
- 24:02The example right there on the page.
- 24:03But what you do is you create a, in this case, a FastAPI, API endpoint,
- 24:09and then you return a hierarchy of elements out of fast UI.
- 24:12So we have a page.
- 24:14The page has components.
- 24:15The components are a list of a header and a table.
- 24:18The table has data, which maps over to a list of pydantic models,
- 24:22which then help say what goes in the field and for the column headings and things like that.
- 24:29It's pretty interesting.
- 24:30I think it's neat.
- 24:31Yeah.
- 24:31And obviously we can add other components like pagination that works.
- 24:34I think just to come back to the top, to how we do these views.
- 24:38The very simple, and it's most simple what fast UI's React app does,
- 24:43is it basically takes whatever the URL is you go to.
- 24:45So in this case, you might go to slash, to the base URL,
- 24:48and it prepens slash API and makes a request to that endpoint to basically say,
- 24:54what should I render?
- 24:55And it gets back.
- 24:56So here we're basically returning a list of pydantic models.
- 25:00All that the fast UI model is really doing is taking that list of pydantic models
- 25:05and calling model dump JSON on it to get the JSON that we return to the front end.
- 25:10And as I say, the front end then knows how to render each of those,
- 25:15each dictionary in the list is what it is.
- 25:17At its core, it's a list of objects to use JavaScript parlance.
- 25:21It just knows how to render each of them and renders each of them in turn.
- 25:24And then obviously they can then have nested other models,
- 25:28all of which it knows how to render.
- 25:29Yeah.
- 25:30It reminds me of a couple of things.
- 25:31I have an example.
- 25:33Is this?
- 25:33No.
- 25:34Somewhere along here.
- 25:34I pulled it up.
- 25:35It reminds me of kind of what React looks like.
- 25:39If people have done React, you know,
- 25:40you write a function that returns kind of an HTML thing,
- 25:44but then it has JavaScript arrow functions, right?
- 25:49But it has the same nested feel, right?
- 25:51Did React inspire you to create it this way or not really?
- 25:55Yeah, it did.
- 25:55I've done quite a lot of React and I like it a lot.
- 25:58I know as a popular piece of technology,
- 26:01there were lots of people who like to berate it,
- 26:05but I do think React has been a powerful step forward.
- 26:07And the greatest form of flattery is copying.
- 26:11There are enough other, like, sure, there are other more powerful,
- 26:14arguably more powerful, arguably more performant,
- 26:17new front-end libraries, but everything is component-based now.
- 26:20Like, you know, React has changed the,
- 26:23there was a sea change in how we did front-end
- 26:25with that component architecture.
- 26:26And JSX, similarly, is super powerful.
- 26:29So one of the things that I think we're going to get to,
- 26:31I don't want to dive into it yet,
- 26:32but like in React, you would say like,
- 26:34we're going to return a photo context or a switch
- 26:39or something that is not typically known in HTML.
- 26:41And these are higher order building blocks in the UI space, right?
- 26:45So when people think about what they're creating here in Python,
- 26:49it's not just the fundamental DOM objects and elements, is it?
- 26:53Right. So that is actually, yeah.
- 26:55So page here is a bit of ambiguity
- 26:57about how we're going to define a page.
- 26:59Like default implementation does something reasonably sensible.
- 27:02It like, you know, pads it, et cetera.
- 27:04But like heading isn't, there isn't much to do really.
- 27:07You're going to return a heading,
- 27:08but when you come to a table,
- 27:10there's a lot of debate about how you're going to do that.
- 27:12And then when you move on to like even higher order components,
- 27:15like a modal, then that's the,
- 27:17how exactly that's implemented is, you know,
- 27:19in some sense it's completely the choice
- 27:21of how you've implemented it in the front end.
- 27:23You could, you could do lots of different things,
- 27:24but yeah, the whole point is that it doesn't
- 27:27and shouldn't be like each HTML tag is written out.
- 27:31Because as I say,
- 27:31I think that would be a like obvious failure mode for this.
- 27:34Yeah.
- 27:34The other thing this reminds me of,
- 27:37by the way, just for people out there listening is
- 27:39that it looks a lot like a Flutter.
- 27:42If people have done any Flutter,
- 27:44you've got these widget hierarchies.
- 27:46You build them, you maybe set some properties,
- 27:48you add in a bunch of,
- 27:50a bunch of elements, you know,
- 27:52set some children to an array of other sub elements.
- 27:56And this is done, of course, in Dart,
- 27:57but it's, you know,
- 27:59this is kind of a Python version.
- 28:01That's similar as well.
- 28:02These higher order widgets.
- 28:03Yeah, absolutely.
- 28:04Similar thing.
- 28:05And actually, the other place where I've built this before
- 28:07is that internally Pydantic core,
- 28:09the Rust bit of Pydantic,
- 28:11is effectively not entirely different to this, right?
- 28:13You define these nested structures of different validators.
- 28:17Everything at its core is a like combined validator,
- 28:20which is in Rust terms,
- 28:22an enormous enum of all the different types of validator,
- 28:24some of which have nested within them,
- 28:26more and more validators.
- 28:27And that's how you build up nested structures of Pydantic models,
- 28:31which in turn is what these are.
- 28:33We're getting there.
- 28:33Yeah, the validators in the UI,
- 28:36they kind of like have a similar structure.
- 28:37A bit of a sidebar,
- 28:39just a bit of a piece of code in here.
- 28:40You've got table,
- 28:41which is a class,
- 28:42square bracket,
- 28:44user,
- 28:44which is another class,
- 28:46square bracket.
- 28:47I imagine that you and your team
- 28:49are deeper into the Python type system
- 28:51than the vast majority of others out there
- 28:55with all the work with Pydantic
- 28:56and the interoperability with Rust.
- 28:58What is that?
- 28:59Tell people about this.
- 29:01Yes, a table is a generic.
- 29:02So if you,
- 29:03you can imagine if you were doing list events,
- 29:05you would do list,
- 29:06square bracket,
- 29:07int.
- 29:07And that's basically the point is that
- 29:10list is a generic around its elements.
- 29:13Same as a dict is generic around its keys and its values.
- 29:16Well,
- 29:16table here is generic around the Pydantic model
- 29:19that you're using to,
- 29:21using for each row.
- 29:22And particularly what that means is that,
- 29:24what it means practically is that table has access
- 29:27to the class when it's deciding what the default columns are.
- 29:32So if you don't define the columns list as we have here
- 29:35to say what columns to display,
- 29:36it'll show all of the fields in the Pydantic model.
- 29:39And the point is we get access to that,
- 29:41to the user before we've,
- 29:43even if,
- 29:43even if data was empty,
- 29:45before the validation has happened.
- 29:47Is it necessary?
- 29:48Is it slightly like,
- 29:50yeah,
- 29:50fancy use of Pydantic types,
- 29:52Python types,
- 29:53maybe it is,
- 29:54but yeah,
- 29:54if you know,
- 29:55forgive the Pydantic team or me in particular for occasionally doing fancy things with Python types.
- 30:00That is definitely occupational hazard of what we do.
- 30:02Yeah.
- 30:02I didn't mean it as a negative.
- 30:04I just thought it was interesting.
- 30:05No,
- 30:05I agree.
- 30:06And actually,
- 30:06I had it somewhere else on forms and I removed it and realized it was,
- 30:10it was,
- 30:10it was unnecessary.
- 30:11So you can definitely do too much,
- 30:13such a thing as too much Python typing.
- 30:15Yeah.
- 30:15Yeah.
- 30:15Yeah.
- 30:15Yeah.
- 30:15For sure.
- 30:16It is pretty interesting.
- 30:17So let's maybe talk about some of the examples.
- 30:20Actually,
- 30:21before we do,
- 30:21just give us a sense of where does this fit in the UI space for Python?
- 30:27On one hand,
- 30:28we've got Flask,
- 30:29Django,
- 30:30FastAPI,
- 30:31returning HTML,
- 30:32et cetera,
- 30:33where it's all on you.
- 30:36you're doing all the five languages of web apps,
- 30:39SQL or some query language,
- 30:41Python,
- 30:42JavaScript,
- 30:43CSS,
- 30:44some other tools,
- 30:45right?
- 30:45Like you're doing all that and you're doing my hand.
- 30:48On the other end,
- 30:48we've got tools that are pretty cool.
- 30:50Like we've got Anvil that lets you just write Python and do a draggy dropy sort of thing,
- 30:55which is,
- 30:56is really neat,
- 30:57but it fits into a kind of a,
- 30:58a box for those types of apps.
- 31:00I just discovered DropBase.
- 31:02Have you heard of DropBase?
- 31:03Not seen DropBase.
- 31:04Yeah.
- 31:05We've seen a lot of these like,
- 31:07get me a UI more quickly.
- 31:08A lot of them are like kind of low code.
- 31:11Anvil,
- 31:12maybe I wouldn't really quite put it there,
- 31:13but they're pretty like low code,
- 31:14but then there's places where Python goes to make it dynamic,
- 31:18right?
- 31:18So where in that spectrum would you put fast UI as it is today?
- 31:23Interestingly,
- 31:23and one of the reasons I wanted to come and talk to you was I heard your,
- 31:25you were,
- 31:26you were talking the other day on,
- 31:27on your other podcast and I heard you talking about fast UI and kind of,
- 31:32I'd say categorizing it into that,
- 31:34that group.
- 31:35And what I wanted to kind of,
- 31:36one of the things I wanted to come and say was,
- 31:37yes,
- 31:38we can do that.
- 31:39But the,
- 31:39the use case we have within Pydantic is actually to go and build a pretty complex,
- 31:43fully fledged application with,
- 31:45with front end developers building components,
- 31:47but just get rid of that churn.
- 31:49Right.
- 31:49Something more like Gmail,
- 31:51less like,
- 31:52here's a table that I can click on and see some related table.
- 31:56Right.
- 31:56Exactly.
- 31:56And what I should probably put in the demo and probably where Pydantic is people most associated
- 32:01and where it's,
- 32:02this is going to be most useful is within forms.
- 32:05So I don't know if you want to go to the,
- 32:06to the demo and I can talk people through,
- 32:08but like within fast UI is dedicated to forms.
- 32:12We can do things like nested Pydantic models all become components within a form.
- 32:17And obviously we can do client side validation with a whole bunch of stuff,
- 32:20but we can also do server side validation,
- 32:22but then we get all the fancy stuff.
- 32:24Like if the,
- 32:25if the data is invalid and you get a validation error on the,
- 32:29on the server side,
- 32:30we'll then basically re-render the form with the errors in place.
- 32:33All that stuff that like anyone building a web application has to go and implement some version of it.
- 32:38At the moment there's,
- 32:39there are some,
- 32:40some react libraries that will build you a form from JSON schema,
- 32:44but they don't perfectly fit in with,
- 32:46with what Pydantic does or with,
- 32:47with FastAPI.
- 32:48And so I have built some variant of that about five times.
- 32:53I still think the state of the art until now is Django,
- 32:56but like lots of us don't want to build our web applications completely with Django
- 32:59because it's,
- 33:00it's pretty all or nothing despite the wonder that it's Django.
- 33:03And so that's the kind of space where for me,
- 33:06this,
- 33:06this like becomes a really stands out because what would have been to do it properly?
- 33:12It's days of work to get form,
- 33:13to get form submission to work,
- 33:15get client side validation,
- 33:16server side validation,
- 33:17get the redirect after your form.
- 33:19None of that stuff is,
- 33:20is entirely trivial,
- 33:21even for those of us who've done it before.
- 33:22Whereas with the theory is with fast UI and in,
- 33:27although fast UI does not require FastAPI,
- 33:29the form stuff is,
- 33:31is quite tightly integrated with FastAPI.
- 33:33and you can get,
- 33:34yeah,
- 33:34a really good experience of building,
- 33:36building stuff like forms.
- 33:37I think that,
- 33:38that where the alternative really today is,
- 33:40is to use no disrespect to any of the fast libraries or any of the other things.
- 33:45But I think the only real alternative right now is implement it yourself or use Django.
- 33:50Yeah.
- 33:50But I do also want to,
- 33:52but maybe before we get to that,
- 33:53let's try to take a little survey of what are these widgets,
- 33:56these building blocks that you can use.
- 33:58Yeah.
- 33:58Is that right?
- 33:58Yeah,
- 33:59absolutely.
- 33:59I think I can find them here.
- 34:01Yes.
- 34:01Yeah.
- 34:02So you've got a fast UI demo,
- 34:04which I'll link to at onrender.com prefix,
- 34:07but you talk about some of the things that you can just create in that Python hierarchy
- 34:13that you return that builds up your UI there.
- 34:17So maybe we talk us through some of the things that are here.
- 34:19Yes.
- 34:19We have the kind of generic markdown component,
- 34:21which will go up and renders a markdown.
- 34:24This table itself is,
- 34:25is implemented using the markdown component.
- 34:27Just a one side note,
- 34:28the markdown and the code,
- 34:30because they have quite a lot of JavaScript associated with them,
- 34:33but they're actually lazily loaded to make the,
- 34:35make the prebuilt fast UI app faster to load.
- 34:38Then we have text,
- 34:39probably the simplest one of all,
- 34:41just render some text paragraph.
- 34:42Again,
- 34:43very simple page titles,
- 34:45a slightly funny one.
- 34:46It doesn't actually display anything on the page,
- 34:48but it changes the,
- 34:49the browser title.
- 34:50So what you see in the tab at the top of the page,
- 34:52it's not always easy to do.
- 34:53Like how do you inject it into the head when you're in the body?
- 34:56And like,
- 34:56it takes a little bit of integration there.
- 34:58Yeah.
- 34:58Right.
- 34:59Exactly.
- 34:59Heading again,
- 35:00very simple,
- 35:00like one to six HTML heading code,
- 35:04bit more sophisticated.
- 35:05And if you click on code,
- 35:06maybe,
- 35:06maybe those who can see it will be able to click through code.
- 35:10Yeah.
- 35:10So code is there.
- 35:11We,
- 35:11we get a like highlighted bit of,
- 35:13a bit of source code displayed.
- 35:15It's color coded with like class types,
- 35:18having a color and keywords,
- 35:19having a color.
- 35:20That's nice.
- 35:21Like you would see in,
- 35:21in GitHub or something like that.
- 35:23So again,
- 35:23just,
- 35:24just like work out the box.
- 35:25Then we have some components like a link list and link,
- 35:28which are used in other components mostly.
- 35:30So if you,
- 35:31the nav bar,
- 35:31you see at the top of the page there that uses a link list.
- 35:34And then we have links.
- 35:35Then we get into kind of more sophisticated components.
- 35:37So the first one,
- 35:38you see a button,
- 35:39which loads a modal and then the button,
- 35:40which loads a dynamic modal.
- 35:42So that when the modal loads,
- 35:43it will make a request to get the content.
- 35:45You want to see within that modal.
- 35:47So that could be a form or it could be customized depending on,
- 35:50on the form in the page.
- 35:51Then we have loading content from the server,
- 35:54which is the same thing we were doing in the modal,
- 35:55but on the page.
- 35:56Then we have this SSE component.
- 35:58So again,
- 35:58very simple to use within fast UI,
- 36:01but like quite a lot of work to use server side events to basically
- 36:04dynamically update a react component.
- 36:06If you weren't using that.
- 36:08So your server load SSE widget that provides,
- 36:12like you said,
- 36:13server sent events,
- 36:14which I don't know how many people are familiar with SSE.
- 36:16I'm sure they're familiar with web sockets and they're familiar with just
- 36:20like a JavaScript event,
- 36:21but this is like an intermediate sort of lightweight one directional,
- 36:24but the normally the opposite in reverse,
- 36:27I guess from the server to the client sort of pushing out stuff.
- 36:29Right.
- 36:29So that's a really powerful thing.
- 36:31And if it's,
- 36:31if it's that easy to just hook a function call when something happens,
- 36:35that's pretty cool.
- 36:35One of the things I want to try with SSE that I think will work
- 36:38really nicely is LLM responses where you get like one token at a time
- 36:42because you don't want to wait for the whole thing.
- 36:43Yeah.
- 36:43The center events would be perfect for basically printing out the response
- 36:47from an LLM.
- 36:48And again,
- 36:48it would be like,
- 36:49you know,
- 36:49two lines of code to add that to an app with fast UI.
- 36:52It would not be two lines of code to go and implement that yourself,
- 36:55whether you're using pure JavaScript or react or whatever framework.
- 36:58Yeah.
- 36:59And we have,
- 37:00have iframe,
- 37:00which again,
- 37:01kind of map,
- 37:02we're back to kind of mapping one-to-one to a component.
- 37:04One of the nice things to say about both iframe and image is they were
- 37:08by other people.
- 37:09So I don't think I'd even created an issue asking for them,
- 37:11but people have come along and added them.
- 37:13It's been one of the nice things to see.
- 37:14I think we had 18 or so people contribute to the first release,
- 37:17first release after my initial release,
- 37:20or sorry,
- 37:20the second release of fast UI.
- 37:22So yeah,
- 37:22good engagement from lots of people.
- 37:24Image.
- 37:24Yeah.
- 37:25So you've got a bunch of UI stuff here and it just,
- 37:28as I look at this and I see what you're building,
- 37:30it just makes me think of like,
- 37:32wow,
- 37:32there's an opportunity for stuff like,
- 37:34like what you get out,
- 37:36not necessarily the same as,
- 37:37but like what you get out of say tailwind UI,
- 37:39where the things you might work with are on off switches,
- 37:43you know,
- 37:44like toggles,
- 37:44like you might see in your phone or other sort of elements that have like
- 37:48a lot of design imbued in them that people can just grab and use almost
- 37:53like a Django philosophy for the front end in a sense there.
- 37:56Is that something that you are dreaming of or?
- 38:00Someone was complaining somewhere that we didn't have a grid component yet.
- 38:03And I think we'll do one,
- 38:04but like those bits get quite opinionated,
- 38:06but yeah,
- 38:06like calendar completely obvious choice,
- 38:09right?
- 38:09Complete faff to go and implement that yourself in HTML.
- 38:12Commonly used trivial to define because,
- 38:15because the definition,
- 38:16there aren't that many different things to define.
- 38:17You,
- 38:17you choose your month,
- 38:18you know,
- 38:19most of us are on the Gregorian calendar,
- 38:21right?
- 38:21We're not,
- 38:21we're not going to have to change too much what calendar we're going to render.
- 38:24So yeah,
- 38:25that's a perfect example of the kind of thing.
- 38:27Tiles like this,
- 38:28again,
- 38:29totally possible to go and implement them.
- 38:31And again,
- 38:31obviously you can use,
- 38:33we can provide some nice default,
- 38:34but also if you're a bigger company and you want to go and customize it,
- 38:39you can totally do that.
- 38:40And you can have a front end developer go through and implement the classes that basically customize,
- 38:44customize the look.
- 38:45I wanted to come back just and show you some of the,
- 38:47some of that,
- 38:48some of the other components.
- 38:49So we were on,
- 38:50yeah,
- 38:51this one.
- 38:51Yeah.
- 38:52I don't know if we have anything more below that,
- 38:53but I would love to show you the tables because the tables and the forms are really where it comes into.
- 38:58So cities is probably the best example.
- 39:00Cities is the one.
- 39:00Okay.
- 39:00Yeah.
- 39:01Awesome.
- 39:01This is a list of cities just for some public data set with country and population.
- 39:06But at the top,
- 39:07you see,
- 39:07we have a filter to choose by country.
- 39:10And if we click here,
- 39:11if you start,
- 39:11start searching like UN or something,
- 39:13you'll see we're doing a server side.
- 39:15We're loading from the server,
- 39:16the list of cities.
- 39:17So again,
- 39:18this component to go and implement,
- 39:19if you were going to do that from scratch,
- 39:21you've got to have,
- 39:22use some like,
- 39:23whatever,
- 39:23this is a list of countries.
- 39:25So if you do like,
- 39:26all countries,
- 39:26sorry,
- 39:26I'm typing in cities.
- 39:27Good.
- 39:28Like UN,
- 39:29United Kingdom and United States.
- 39:30Yeah.
- 39:30Perfect.
- 39:31There you go.
- 39:31And then we do United States or whatever.
- 39:34Yeah.
- 39:35And then we'll get a bunch of cities in the United States.
- 39:37Building this and wiring it all up and using one of the,
- 39:41we use react select here,
- 39:42but you can use select two or one of those components.
- 39:44It's not trivial.
- 39:45You need to also set up the backend.
- 39:47You need to set up,
- 39:48there's like a few hundred lines of react dedicated just to setting up those,
- 39:53those selects correctly.
- 39:55And as you'll see in a minute on a form,
- 39:56you can add this to a,
- 39:57to form with us UI pretty trivially.
- 40:00Secondly,
- 40:01if you go to the bottom of the page on cities,
- 40:03you'll see pagination again,
- 40:05not a trivial thing to go and set up.
- 40:07If you've got,
- 40:07if you're just starting from scratch and you want to show like build an internal
- 40:10endpoint,
- 40:11for example,
- 40:11to show all of your users doing all that pagination and like wiring all that
- 40:15up is not trivial,
- 40:16but we effectively do the work for you to have that component and do the maths of
- 40:20which page we're on and stuff like that.
- 40:22Nice.
- 40:22I want to like reiterate,
- 40:24this is the fast UI is not just designed as a kind of Django admin interface
- 40:28alternative.
- 40:29We within financing are going to go and use it for UI that we're going to show
- 40:33to end users.
- 40:33But obviously it also comes into its own when people want to just get something
- 40:37up quickly.
- 40:40This portion of talk Python to me is brought to you by Sentry,
- 40:42you know,
- 40:43Sentry for the air monitoring service,
- 40:45the one that we use right here at talk Python.
- 40:46But this time I want to tell you about a new and free workshop.
- 40:51He means the Kraken managing a Python monorepo with Sentry.
- 40:55Join Salma Alam Nayor,
- 40:57Senior developer advocate at Sentry and David Winterbottom,
- 41:00head of engineering at Kraken Technologies for an inside look into how he and his team develop,
- 41:06deploy,
- 41:07and maintain a rapidly evolving Python monorepo with over 4 million lines of code that powers
- 41:13the Kraken utility platform.
- 41:15In this workshop,
- 41:16David will share how his department of 500 developers who deploy around 200 times a day
- 41:22use Sentry to reduce noise,
- 41:24prioritize issues,
- 41:25and maintain code quality without relying on a dedicated Q&A team.
- 41:28You'll learn how to find and fix root causes of crashes,
- 41:32ways to prioritize the most urgent crashes and errors,
- 41:35and tips to streamline your workflow.
- 41:37Join them for free on Tuesday,
- 41:39February 27th,
- 41:402024 at 2 a.m.
- 41:42Pacific time.
- 41:43Just visit talkpython.fm/sentry dash monorepo.
- 41:47That link is in your podcast player show notes.
- 41:492 a.m.
- 41:51might be a little early here in the U.S.,
- 41:52but go ahead and sign up anyway if you're a U.S. listener,
- 41:55because I'm sure they'll email you about a follow-up recording as well.
- 41:59Thank you to Sentry for supporting this episode.
- 42:02If we have a design language or something like that,
- 42:07or even using a framework,
- 42:08I mean,
- 42:09you mentioned Bootstrap,
- 42:09but Tailwind or Bulva,
- 42:12is that one of the new ones?
- 42:13Like,
- 42:13if we're working with one of those and we wanted to use this,
- 42:16like,
- 42:17how easy is it to sort of bring in those elements there?
- 42:21So if I show you here on Bootstrap,
- 42:24to ask you how we customize it with Bootstrap,
- 42:26which is probably the best definition of it.
- 42:28So you'll see here,
- 42:30this is in the,
- 42:30this is the,
- 42:31where am I looking?
- 42:32This is the pre-built version.
- 42:33So this,
- 42:34this is obviously the pre-built version of Fast UI you can get,
- 42:37but it's actually just,
- 42:39it's a very simple app in terms of React.
- 42:41this app has one,
- 42:42well,
- 42:42two components.
- 42:43It has a div,
- 42:43which contains the Fast UI component.
- 42:46And then we customize it in a bunch of ways.
- 42:48We have a like component that we render for not found.
- 42:50We have a component we render for spinner and for transitioning.
- 42:53but then these are the two that really matter where we can customize the
- 42:56classes and we can customize how we render certain components.
- 43:00So if we come in here to have this function from Bootstrap,
- 43:03which is how we customize the classes,
- 43:04you'll see that at its core,
- 43:06it's just this big old switch.
- 43:07So this is all TypeScript,
- 43:09like type safe because types are very powerful in TypeScript,
- 43:13but like all of the props will have this type key.
- 43:16As I showed you earlier,
- 43:17when we were looking at the Python code and all the different things.
- 43:21Yeah.
- 43:21Based on the switch,
- 43:22we just go through,
- 43:23and this is all just like defining the classes we want for all of the
- 43:26different components.
- 43:27Some of them depending on the exact state of the component.
- 43:29So all of these form inputs,
- 43:31we customize them depending on which type they are and on which mode we're in,
- 43:35et cetera,
- 43:36et cetera.
- 43:36But it's,
- 43:37it's all very mechanical,
- 43:38just like laying out the classes we need for each and each individual case.
- 43:41And then we have the other way of customizing it,
- 43:44which is to use custom components.
- 43:46We basically for three in particular components,
- 43:49nav bar,
- 43:49modal and pagination,
- 43:51we define our own,
- 43:53custom react components.
- 43:54So here's the one for nav bar where we use a bunch of bootstrap types to render a bootstrap nav bar.
- 44:00So you can basically create a react component that has all the settings necessary to create a nav bar in tailwind or whatever.
- 44:08Right.
- 44:08And then just plug that stuff in.
- 44:10So,
- 44:10so if you wanted to use tailwind,
- 44:11what's this like 20,
- 44:13it's like a hundred lines of code to define all of the classes and it's pretty mechanical code,
- 44:18right?
- 44:18So it would be,
- 44:19it wouldn't be hard at all to go and use tailwind,
- 44:20it wouldn't be hard at all to go and use tailwind,
- 44:21tailwind CSS.
- 44:22And then you might want to define a few of your components specifically.
- 44:26Yeah.
- 44:26But actually modal,
- 44:27modal,
- 44:27I think is the only one that really requires it to be custom implemented because the default just shows you an alert because there's nothing.
- 44:33Right.
- 44:33JavaScript.
- 44:34The page says,
- 44:35it's like,
- 44:36oh,
- 44:36no,
- 44:37the page doesn't say this isn't going to work.
- 44:38Yeah.
- 44:39So,
- 44:39yeah,
- 44:39I think this is one of the bits I'm most proud of here is that like how much you could customize it and how simply you could start to customize it.
- 44:46Right.
- 44:46Those are really like kind of pluggable or extensible.
- 44:49So you don't have to,
- 44:50you know,
- 44:51get in and know too much about it.
- 44:53You just plug in the class name generator and the renderer for a specific one.
- 44:57And so,
- 44:58yeah,
- 44:59and all of the types,
- 45:00it's all typescripted.
- 45:01So you,
- 45:01the type should do a lot of help telling you what,
- 45:03what you can implement.
- 45:04The last thing I'll show you is,
- 45:06yeah,
- 45:07so here in the default build,
- 45:09as I said,
- 45:09we,
- 45:09our custom render function is not just a bootstrap one.
- 45:12We do one special thing,
- 45:15which is where we,
- 45:16we have this idea of a custom component,
- 45:18which basically all it has is a subtype,
- 45:21which basically you should use to render it however you like.
- 45:24So in our case,
- 45:25we hit take custom.
- 45:26And if the subtype is cow say,
- 45:29we render that as a particular block,
- 45:31like use this,
- 45:32this component here.
- 45:33And we print out the cow says,
- 45:35whatever it was that the input was from the server.
- 45:37And otherwise we just go back to using the bootstrap render.
- 45:39And so if you look at,
- 45:40look at that component here.
- 45:42Yeah.
- 45:42We've got this like slightly silly example of a custom component of cow say,
- 45:46saying something.
- 45:47Oh,
- 45:47that's fun.
- 45:48But yeah,
- 45:49it shouldn't be too difficult to customize.
- 45:51And then even if you're customizing to go back to using bootstrap for,
- 45:54for the fallback case of everything else.
- 45:55Okay.
- 45:56So you could almost just for one section that has to be really specialized to some custom,
- 46:01but otherwise just lean on a framework.
- 46:02Yeah.
- 46:03Okay.
- 46:03Yeah.
- 46:03This looks like something that one person could take one for the team,
- 46:07create a tailwind or a whatever generator,
- 46:10class name generator,
- 46:12and then put that as either a contribution or put it up on GitHub.
- 46:16And then you just,
- 46:17you're kind of good to go.
- 46:18Yeah.
- 46:18I think we might,
- 46:19we might actually do it.
- 46:20We're,
- 46:20we're using tailwind and radix within Pydantic.
- 46:23So I suspect our front end guys will at some point get annoyed with my use of bootstrap
- 46:26and go off and go and change it.
- 46:29One of the reasons I use bootstrap is that because bootstrap is completely customized via
- 46:33SCSS and there's SCSS compilers for Python.
- 46:37We have the,
- 46:38at least the possibility in future to allow you to customize the complete look and feel of your
- 46:42app without ever having to touch npm.
- 46:44Cause you just go change basically the color definitions as we do here.
- 46:48So,
- 46:48so the,
- 46:49the default version of,
- 46:51uh,
- 46:51maybe I can even change it here and as it's running,
- 46:53it'll change.
- 46:53But if I hear you see,
- 46:55I've set the primary color to be black.
- 46:56And so you'll see the buttons here are all rendered as black.
- 47:00If I were to change it,
- 47:01I haven't tried this for a bit,
- 47:03so I hope it works commented out primary.
- 47:05You'll see that the primary,
- 47:08uh,
- 47:09which is the bootstrap primary button.
- 47:11If I changed the,
- 47:12I got rid of the default font.
- 47:14You would see,
- 47:15we went back to whatever the other font was.
- 47:17So there's a world in future where we allow you to customize the look and feel
- 47:20even within bootstrap from Python code.
- 47:22Yeah.
- 47:23Tell people maybe who don't know what SCSS is.
- 47:25They probably know what CSS is.
- 47:27It's generally referred to as SAS,
- 47:29which is S A S S S,
- 47:31which was,
- 47:32is,
- 47:32is basically,
- 47:32uh,
- 47:33a more powerful version of,
- 47:35of CSS where you can.
- 47:36SAS and less.
- 47:37Those were the two.
- 47:38Yeah.
- 47:38there was SAS and less.
- 47:39And then we kind of settled on SAS,
- 47:41but then we had a CSS,
- 47:42which is SAS with more CSS syntax.
- 47:46It's a way to like do slightly more powerful things in,
- 47:49in CSS and minify it and have stuff like variables for,
- 47:53they were available in CSS and,
- 47:55and defaults.
- 47:56And even you can do weird stuff like map functions.
- 47:59And they use very heavily in bootstrap.
- 48:01But the nice bit is because the compiler is written in C.
- 48:04There's Libsass in Python,
- 48:06where you can get kind of a front end customization without needing the whole of
- 48:11node and the,
- 48:12the whole dog and pony show of front end development.
- 48:15Yeah.
- 48:15Excellent.
- 48:15It's got a lot of legs.
- 48:17So when I saw this and I saw,
- 48:19okay,
- 48:20this is so for,
- 48:20for web apps and it's kind of got this,
- 48:22this Python code running that defines the backend and it's got the UI and it's all
- 48:27a little self-contained.
- 48:28One of the thoughts I had was,
- 48:30wouldn't it be neat if there was a,
- 48:32got a little bundler type of thing that made this into an electron app?
- 48:36Would this be possible?
- 48:37Can we get something that you could send out?
- 48:40Or is this really just going to be intended to be,
- 48:42you know,
- 48:42kind of a friend of Django type of thing?
- 48:45I have not used electron for a very long time,
- 48:48so I don't pretend to be an expert.
- 48:49What I will say is that unlike some of the other UI libraries,
- 48:54we're not trying to do clever things with web sockets and do all of the,
- 48:58all of the rendering requiring duplex communication between the client and the
- 49:02server.
- 49:02It's pretty simple.
- 49:03It's like make a request and the Jason contains some information about how to
- 49:07render it.
- 49:07And then the front end goes off and renders it.
- 49:09So it's the result.
- 49:10What you get when you finish is very,
- 49:12in terms of a networking point of view,
- 49:14very,
- 49:15very simple,
- 49:16very conventional.
- 49:16It's like make an HTTP request,
- 49:19get back Jason,
- 49:19JavaScript knows how to render it.
- 49:21And so I don't see why it shouldn't,
- 49:24shouldn't work in electron.
- 49:25There's even the world in which we don't need the whole of electron.
- 49:28And we could,
- 49:29someone could go and build fast UI components for,
- 49:32for whatever native library.
- 49:33And we could get like native apps running that are based on fast drive.
- 49:36not saying that's necessarily a good idea,
- 49:38but like those possibilities exist.
- 49:40It is.
- 49:41It does exist.
- 49:42Okay.
- 49:42Yeah.
- 49:42Yeah.
- 49:43Very interesting.
- 49:43Another thing that is convention,
- 49:46I suppose.
- 49:46I'll see if I can pull it out here is the UI.
- 49:49A lot of times you'll have either just slash,
- 49:51you'll have slash users,
- 49:54but then you'll have an API that backs it.
- 49:56And there's this convention that if it's in the URL,
- 49:59if you have slash API slash,
- 50:00in this example,
- 50:01we were talking about before,
- 50:02it's like slash table slash cities.
- 50:04If you say API slash table slash,
- 50:06that's the data endpoint.
- 50:07And then if you drop the API,
- 50:09that's the front end that then turns around and calls the backend with the API
- 50:13inserted.
- 50:14Right.
- 50:14You want to talk about that convention a little bit?
- 50:15So people kind of see where that's going.
- 50:17So that's how,
- 50:18how I've set it up in the default app.
- 50:20It doesn't,
- 50:21you don't have to do it like that.
- 50:22And I think we're using a separate subdomain to avoid like path-based
- 50:26routing and all that fun.
- 50:28But yeah,
- 50:28the,
- 50:28the,
- 50:29the principle that the default simplest way of basically doing a,
- 50:32excuse me,
- 50:33a calculation to go from,
- 50:34I've got a URL.
- 50:35How do I get the data for it?
- 50:37Is as I said earlier,
- 50:38basically prepend slash API.
- 50:39So maybe a more general way to think about it is for every page,
- 50:43there is an endpoint that is a FastAPI endpoint or a pair of them.
- 50:47Maybe even one returns the HTML front end stuff that makes it run.
- 50:52It talks around and goes back to itself.
- 50:54Right.
- 50:55Yeah.
- 50:55So what we have in the default app here,
- 50:57what I would generally recommend is where are we?
- 51:00We have a bunch of routers that connect and do all of the API stuff.
- 51:05And I've just been implementing all,
- 51:06which I can show you in a minute,
- 51:07but that's not available.
- 51:08There's a PR for it,
- 51:09but it's not available in the demo you're looking at.
- 51:11But then we have this like basically catch all endpoint,
- 51:14which if nothing else has been hit,
- 51:16will render the standard HTML.
- 51:18And one of the nice things is that the Python library gives you this prebuilt HTML,
- 51:23which will basically render you some,
- 51:24render you the HTML that you'll get.
- 51:26If you,
- 51:27I went here and I view page source,
- 51:29you'll see.
- 51:30You just go to home page, yeah.
- 51:31Returning.
- 51:31Well,
- 51:32yeah.
- 51:32In this particular,
- 51:33if I went to 8,000,
- 51:34then it wouldn't be messed up by Vite.
- 51:36You just get this very simple HTML,
- 51:38which in turn renders the app.
- 51:39So yeah,
- 51:40there's effectively,
- 51:41you're right.
- 51:41There's two,
- 51:41there's two,
- 51:42there's like matching endpoints for,
- 51:44for every view you might want to have one to get,
- 51:46to return the Jason,
- 51:48the one to,
- 51:48to render the HTML.
- 51:49But you don't write,
- 51:50you don't write them both,
- 51:51right?
- 51:51You write the API one and then fast UI magically turns out into UI.
- 51:56Right.
- 51:57And whatever,
- 51:57and this would,
- 51:58all of most of this,
- 51:59with the exception of the form submission would all just work out the box with,
- 52:02with any Python web framework.
- 52:04You just need to produce your financing model,
- 52:07dump it to Jason and return that in a response.
- 52:10But one of the really nice things about the,
- 52:13this being the like actual data existing in Jason is that writing a test.
- 52:18There's quite a lot here,
- 52:19but you'll see most of it is,
- 52:20is markdown.
- 52:21So writing a test that our views contain what we expect them to is massively easier
- 52:26when we're testing against Jason,
- 52:27which we can convert to Python objects and tests than it would be.
- 52:30If we've got an HTML page,
- 52:31we're running a bunch of regexes for does this page contain the user's name?
- 52:35Does it contain the word logout?
- 52:37Blah,
- 52:37blah,
- 52:37blah.
- 52:38Yeah.
- 52:38By a right type of things or those types of tests.
- 52:42Sure.
- 52:42Oh yeah.
- 52:43Even worse.
- 52:44You end up with like play,
- 52:45right.
- 52:45And like play,
- 52:46right.
- 52:46That's an image of it and see if the image looks like the image used to look.
- 52:49And yeah,
- 52:49things I don't want to have to build.
- 52:51I mean,
- 52:52they have to happen occasionally,
- 52:53but like we're,
- 52:54and ironically we'll probably end up with them in fast UI to like even more
- 52:57certainty that our components work correctly,
- 52:59but hopefully that thereby avoid everyone else having to,
- 53:02having to go and build.
- 53:03Is there any concern that maybe there's unintended APIs in the sense that like
- 53:08all of this stuff,
- 53:09I'm sure this is probably true for pretty much any react site,
- 53:13but like a lot of the page is available also as an API,
- 53:16even if you don't intend it to be an API,
- 53:18like what's.
- 53:19Yeah.
- 53:19That's a limitation of any,
- 53:21I mean,
- 53:22in some ways the data will be slightly less nice to.
- 53:24Yeah.
- 53:24You're right.
- 53:25If you're a company that give people foreign exchange rates and you want them
- 53:29to always come to your site,
- 53:30you obviously can't render that with,
- 53:32with react because there's going to be a Jason endpoint where someone can just
- 53:35go scrape your exchange rates or whatever else.
- 53:37Right.
- 53:37But you can still do session based off and say you have to log in to do it.
- 53:41Right.
- 53:42It's not just that it's public.
- 53:43It just,
- 53:44there's always a Jason version,
- 53:46but honestly,
- 53:47there's so many interesting ways to pull data out of HTML.
- 53:49Like,
- 53:50yeah.
- 53:50If someone's that valuable,
- 53:52someone will do it anyway.
- 53:53I also think that like,
- 53:55in theory,
- 53:55if your options are build pure react or do this,
- 53:59and this has the,
- 54:00the,
- 54:00like,
- 54:01as I say,
- 54:01there's the realistic chance.
- 54:03Someone's going to come along and implement a fast UI front end that,
- 54:06that renders HTML.
- 54:07And then,
- 54:08and then you don't have to expose your,
- 54:10expose those Jason endpoints at all.
- 54:12And you could,
- 54:12you could return HTML from your server.
- 54:14We just haven't got around to building it yet.
- 54:16Yeah.
- 54:16I guess you could maybe do some kind of server side rendering potentially as well.
- 54:20Exactly.
- 54:20That's what I mean.
- 54:21Whether it's Python server side rendering,
- 54:22or whether it's JavaScript server side rendering,
- 54:24or whether it's edge rendering.
- 54:25I've tried to build a sort of edge rendering thing in Cloudflare years ago using Rust.
- 54:30And for a bunch of reasons,
- 54:31it didn't quite work,
- 54:32but there's real possibility of doing like,
- 54:34yeah,
- 54:35any number of different things in that direction.
- 54:36That's interesting.
- 54:37Some of the CDNs have pretty dynamic stuff right at the edge,
- 54:41where you can sort of put your last bit of code.
- 54:42I haven't done anything with that.
- 54:44That's kind of what Remix is doing,
- 54:46and Next.js to a lesser extent.
- 54:48But again,
- 54:49in theory,
- 54:49I mean,
- 54:50maybe I'm overblowing it,
- 54:52and Fast UI will remain what it is now.
- 54:54But like,
- 54:54in theory,
- 54:55we've set up this language of different components that hopefully is,
- 55:00whilst by no means universal,
- 55:02complete enough that you can build lots of common user interfaces with it.
- 55:05And then,
- 55:06if it really gains adoption,
- 55:07then people can go and build new backends and new frontends,
- 55:10and they all,
- 55:11in theory,
- 55:11should be able to mix and match with each other.
- 55:13We'll see if that happens.
- 55:14Yeah.
- 55:15And widgets too,
- 55:16right?
- 55:16Kind of like,
- 55:17see a Tailwind UI create a paid thing for higher order widgets,
- 55:21potentially.
- 55:21Just being React already makes that,
- 55:24that probably exists,
- 55:25and I just don't know.
- 55:25And there's been a number of issues of people wanting to render existing,
- 55:30basically build extensions to Fast UI to render their widgets.
- 55:33I think we will probably support the rep for HTML,
- 55:36that things like Pandas data frames already returned,
- 55:39so that you could,
- 55:39for example,
- 55:40return a data frame,
- 55:41and it might not be pretty,
- 55:42but you'll get something coming up as HTML,
- 55:44and,
- 55:44you know,
- 55:45start ugly,
- 55:46and then move on to doing those things in an even more powerful way.
- 55:49Sure.
- 55:49Yeah,
- 55:50I didn't even think of the data science side,
- 55:51but there's probably a lot of cool dashboard widgets connected to pandas and pullers that are potential out there.
- 55:57Yeah.
- 55:57And charts and visualizing data is something Pydantic is interested in.
- 56:00There's no reason why a lot of them couldn't be implemented as Fast UI components and then displayed.
- 56:06Okay.
- 56:07We are running pretty short on time.
- 56:09I feel like we should probably bring a little more Pydantic to the side.
- 56:13Just talk real quickly about forms,
- 56:15right?
- 56:15What do you think?
- 56:16Yeah,
- 56:16absolutely.
- 56:16So if you,
- 56:17probably easiest,
- 56:18if you share,
- 56:19let me see,
- 56:20share my screen.
- 56:20I'll do it from here,
- 56:21because I can also,
- 56:22it's like,
- 56:23you can show more behind the scenes.
- 56:25Yeah,
- 56:25yeah,
- 56:25yeah.
- 56:25It's probably most interesting if we,
- 56:27if we look at the,
- 56:28how the form is implemented in the code first,
- 56:31and then we look at what that,
- 56:32what that means for the UI.
- 56:33So this is the,
- 56:34the login form that Michael,
- 56:35you were just showing here that I can show,
- 56:37which is just,
- 56:37so there's a login form with an email address,
- 56:39password,
- 56:40some validation,
- 56:41basically like that.
- 56:42Yeah.
- 56:43powered entirely by,
- 56:43again,
- 56:44a completely vanilla Pydantic model.
- 56:45And the way that we return that is we return three things,
- 56:50heading,
- 56:51which is like just telling the person what we're looking at here in the demo.
- 56:53And then this third thing is the,
- 56:55it's the interesting bit where again,
- 56:56actually the model form is again,
- 56:59generic around the Pydantic model.
- 57:00And then it takes one other argument,
- 57:02which is the submit URL.
- 57:03And that's enough information.
- 57:04Right.
- 57:05So what you're returning as part of that hierarchy in Python is a model form
- 57:10and you give it a Pydantic model.
- 57:12And so it looks at the Pydantic class and says,
- 57:15we're going to create like an email address and a password field and so on.
- 57:19Right.
- 57:19Exactly that.
- 57:20Awesome.
- 57:20Okay.
- 57:21And then when you submit that form,
- 57:23it's submitted as form data.
- 57:25So is it not as,
- 57:27as JSON data,
- 57:28but as a vanilla HTML form,
- 57:30a standard form post type of thing.
- 57:32Post form.
- 57:33And then we have this,
- 57:34it's this syntax is definitely slightly funky here,
- 57:37but,
- 57:37but it's how we do it in fast.
- 57:38You are a FastAPI.
- 57:39We have form,
- 57:41which is annotated as a login form,
- 57:42but it's also got fast UI form,
- 57:45which in turn,
- 57:45which also takes login form,
- 57:47all of which looks a bit ugly.
- 57:49But what we're really doing in the background is converting form data into the Pydantic model,
- 57:54including flattening and deflattening the model in the case where we have nested models,
- 57:59which I'll show you in a minute.
- 58:00But the result of this is once we,
- 58:02in our,
- 58:03in our post endpoint,
- 58:03we get an instance of,
- 58:05of the login form that we can then go do stuff with.
- 58:07If I show you a more comprehensive or complex example,
- 58:10this is big model here becomes big form.
- 58:13And this has,
- 58:14has a bunch more stuff in it.
- 58:15So it has file inputs.
- 58:17Now file inputs are one of the reasons we can't just submit,
- 58:20submit JSON because,
- 58:21Yeah.
- 58:22Because we need a multi-part encoding and all those things.
- 58:25Yeah.
- 58:26All those things.
- 58:26Right.
- 58:27And so here we have name.
- 58:29We use bold again,
- 58:31as I have before to,
- 58:32to indicate required fields.
- 58:33So we could,
- 58:35I don't know,
- 58:35have got some Pydantic logos here that I'll use as images.
- 58:39This one is multiple images.
- 58:41So we can select multiple images,
- 58:43a date field in this case.
- 58:45I've got a calendar picker.
- 58:46Very nice.
- 58:47Is that just input type equals?
- 58:49That's just input type equals,
- 58:50equals date.
- 58:51Okay.
- 58:51We have switches.
- 58:52We have,
- 58:53and then you'll see here,
- 58:53we have size model arrow width and size model arrow height.
- 58:57And the,
- 58:57the point is that we're doing here,
- 58:59and these are integer fields,
- 59:00but the cool bit is that they map to a nested Pydantic model within the big
- 59:06model.
- 59:06What fast UI is doing internally is basically flattening this into,
- 59:11one list of form fields,
- 59:12which is then what we get rendered here.
- 59:14I see.
- 59:15So in your Pydantic model,
- 59:16you have a size object,
- 59:18but then in the form,
- 59:19it just has the width and the height,
- 59:21the one after another.
- 59:21Size width,
- 59:22size height.
- 59:22Exactly.
- 59:23If I put a,
- 59:24a requirement or a restriction like min or max onto the field in the size
- 59:29model,
- 59:30would that become a client side min and max in the form?
- 59:33There's an open PR to do exactly that.
- 59:35Yeah.
- 59:35Awesome.
- 59:36But obviously we will get server side validation as well.
- 59:39And then for a couple of weeks.
- 59:40So like it's,
- 59:41there's more to do,
- 59:43right?
- 59:43But that's awesome.
- 59:44That'll be fun.
- 59:45And then you'll,
- 59:45you'll see in uploads,
- 59:46we have some,
- 59:47some quite powerful things we can do here.
- 59:48So we use the upload file,
- 59:51which is a starlet type,
- 59:52but we can also annotate it with form file,
- 59:55file,
- 59:56which takes two optional arguments of what rule,
- 59:59what accepts to apply.
- 1:00:00So that will both in the browser,
- 1:00:02when you open the,
- 1:00:04when you choose a file browse dialogue,
- 1:00:06yeah,
- 1:00:07it'll tell you.
- 1:00:07You have a MIME.
- 1:00:08So for people listening,
- 1:00:09you have the MIME type set,
- 1:00:10not like a extension,
- 1:00:11but you have image slash star,
- 1:00:13which means,
- 1:00:14you know,
- 1:00:14image slash JPEG,
- 1:00:15PNG,
- 1:00:15WebP,
- 1:00:16et cetera.
- 1:00:16Right.
- 1:00:16And that's understood by the browser and then by the,
- 1:00:18and then by the OS to,
- 1:00:20to let you select files,
- 1:00:21but it's also validated server side.
- 1:00:23So if someone goes and edits their HTML and submits a not image,
- 1:00:26the server side validation will check at least based on the file extension
- 1:00:30that it,
- 1:00:30that it looks like an image and you get back the bytes.
- 1:00:33So you could also go do validation that the bytes are a valid image.
- 1:00:36If you,
- 1:00:37if you say you can read the bomb,
- 1:00:38the,
- 1:00:39the mark that indicates the file type that's sometimes in these different files.
- 1:00:43Yeah.
- 1:00:43If I submit this,
- 1:00:44but let's say,
- 1:00:45well,
- 1:00:45first of all,
- 1:00:45if I try and submit this,
- 1:00:46because we've got server side validation of which fields are required,
- 1:00:48it won't let me submit if this file field is not completed.
- 1:00:52And then I think if we put a name and we don't capitalize it in this case,
- 1:00:56we'll go off and do the validation and come back and we'll say,
- 1:00:59name will start with the capital because I've implemented it.
- 1:01:02Where's that validation?
- 1:01:03Oh,
- 1:01:03I see.
- 1:01:03That's a function that you write.
- 1:01:05Right.
- 1:01:05So just to prove the point,
- 1:01:07I've just written a validator in,
- 1:01:08in Pydantic,
- 1:01:09which says this must start with,
- 1:01:11with uppercase.
- 1:01:11And if I then went in here and edited that,
- 1:01:16print out form,
- 1:01:17is that going to now clear my form?
- 1:01:19No,
- 1:01:19it's not,
- 1:01:19which is magic.
- 1:01:20And if I submit that,
- 1:01:21you'll see here where I printed out the form.
- 1:01:24We got the,
- 1:01:26we got the different file objects and we got the raw data all come through as a Pydantic model.
- 1:01:29Yeah,
- 1:01:30that's really cool.
- 1:01:31And so I love how even the custom validators in Pydantic,
- 1:01:35like Python code that you wrote appears on what feels like client side,
- 1:01:40but is really server side validation run by React,
- 1:01:42right?
- 1:01:43Yeah,
- 1:01:44exactly that.
- 1:01:44so we'll do stuff like link checks and all the things you can do on an input client side as well.
- 1:01:49But of course,
- 1:01:49there'll also be,
- 1:01:50be enforced server side,
- 1:01:52which obviously if you're building anything that you're going to be exposed to the internet,
- 1:01:55you've got to do.
- 1:01:56Yeah,
- 1:01:56you should never,
- 1:01:57never trust what comes into your web app.
- 1:01:59It's just put it online for five minutes and look at the log.
- 1:02:02It's already trying.
- 1:02:03Somebody's already after WP admin.php,
- 1:02:06you know?
- 1:02:06Yeah,
- 1:02:07exactly that.
- 1:02:07And then the last thing I'll show,
- 1:02:09I know we haven't got very long at all is authentication,
- 1:02:11which I've just been working on now.
- 1:02:13This is,
- 1:02:14again,
- 1:02:14it's a simple form.
- 1:02:15I'm just going to select an email,
- 1:02:17put in a random password and I can log in.
- 1:02:20And in this case,
- 1:02:21I've logged it.
- 1:02:22It just says who I am and how many people are logged in.
- 1:02:24If I come back to this page,
- 1:02:25it'll show me logged in and I can do post requests to log out.
- 1:02:29And what it's doing internally is,
- 1:02:32and again,
- 1:02:32this is the kind of thing that would be lots and lots of work to implement if you're doing it yourself,
- 1:02:35is it's storing in session storage,
- 1:02:37the auth token,
- 1:02:38then adding it as a header where we do the fetch from the front end to the back end.
- 1:02:43So we can effectively store,
- 1:02:45store sessions that way.
- 1:02:46Oh yeah.
- 1:02:46Very cool.
- 1:02:46Yeah.
- 1:02:47That auth token's coming in as a header item or being set as a header item.
- 1:02:50Excellent.
- 1:02:51Right.
- 1:02:51Exactly.
- 1:02:52Cool.
- 1:02:52So yeah,
- 1:02:53I hope that we've done a bit of a whirlwind tour through,
- 1:02:55through fast UI and what's there now and what,
- 1:02:57what I hope is coming up and the like slightly philosophy of how,
- 1:03:01why I,
- 1:03:02why I built it.
- 1:03:02But yeah,
- 1:03:03that was interesting.
- 1:03:03It's super interesting.
- 1:03:04And it's really early days.
- 1:03:06I'm,
- 1:03:06I'm looking forward to two things to see what people go do with it,
- 1:03:09what widgets and stuff they build.
- 1:03:11So,
- 1:03:12you know,
- 1:03:12can you drop in,
- 1:03:13like you said,
- 1:03:13a calendar or something awesome like that.
- 1:03:15And I'm also looking forward to see what you all internally release in a couple months.
- 1:03:19Absolutely.
- 1:03:20Yeah.
- 1:03:21Thanks so much for,
- 1:03:22for having me and letting me witter on about,
- 1:03:25about this,
- 1:03:26this random library.
- 1:03:27Yeah,
- 1:03:27of course.
- 1:03:28Good work.
- 1:03:28It's certainly creative.
- 1:03:30Maybe just give people a sense of,
- 1:03:32you know,
- 1:03:32as we wrap it up,
- 1:03:33can they use it now?
- 1:03:35Should they use it now?
- 1:03:36Can they contribute?
- 1:03:37Maybe they're interested.
- 1:03:38What do you tell that crew?
- 1:03:39I'd love people to contribute both.
- 1:03:41I mean,
- 1:03:42almost most useful is,
- 1:03:43it's issues saying how you're using it,
- 1:03:45where it's working,
- 1:03:46where it's not.
- 1:03:46There is a bunch of people who've already submitted PRs and,
- 1:03:49and continue to do so.
- 1:03:50And yeah,
- 1:03:51I think what works works pretty rigorously and it's probably better implemented and tested than lots of like private code,
- 1:03:58but definitely within internal uses,
- 1:04:01use it now.
- 1:04:01And like I say,
- 1:04:02Pynantic is building things,
- 1:04:03building things with it now.
- 1:04:04So look,
- 1:04:06I mean,
- 1:04:06I'm not,
- 1:04:07I give the open source guarantee that it's relatively safe,
- 1:04:10which is the guarantee that means nothing.
- 1:04:12But mostly because at the end,
- 1:04:14it's just defining how you build your UI and how you implement your session authentication.
- 1:04:18It's not having strong opinions about that.
- 1:04:20So yeah,
- 1:04:21I think it's,
- 1:04:22I think it's the place where people should go and try it and give,
- 1:04:24give feedback.
- 1:04:25Excellent.
- 1:04:25All right.
- 1:04:26Well,
- 1:04:26thanks again for coming on the show.
- 1:04:28Looking forward to talking to you next week.
- 1:04:29No,
- 1:04:29just kidding.
- 1:04:30Like two in a row.
- 1:04:31I suppose.
- 1:04:31Looking forward to talking to 2024.
- 1:04:33Absolutely.
- 1:04:33Have a good Christmas.
- 1:04:34Thank you so much.
- 1:04:35Yeah.
- 1:04:35Thanks.
- 1:04:36Bye.
- 1:04:36This has been another episode of talk Python to me.
- 1:04:39Thank you to our sponsors.
- 1:04:41Be sure to check out what they're offering.
- 1:04:42It really helps support the show.
- 1:04:44Bright data is professional web scraping and a dataset marketplace.
- 1:04:49If you need data and it doesn't have an API,
- 1:04:52check out talkpython.fm/bright data today.
- 1:04:56Take some stress out of your life.
- 1:04:59Get notified immediately about errors and performance issues in your web or mobile applications with
- 1:05:05Sentry.
- 1:05:05Just visit talkpython.fm/sentry and get started for free.
- 1:05:10And be sure to use the promo code talkpython,
- 1:05:13all one word.
- 1:05:14Want to level up your Python?
- 1:05:16We have one of the largest catalogs of Python video courses over at Talk Python.
- 1:05:20Our content ranges from true beginners to deeply advanced topics like memory and async.
- 1:05:25And best of all, there's not a subscription in sight.
- 1:05:28Check it out for yourself at training.talkpython.fm.
- 1:05:31Be sure to subscribe to the show.
- 1:05:33Open your favorite podcast app and search for Python.
- 1:05:36We should be right at the top.
- 1:05:37You can also find the iTunes feed at /itunes,
- 1:05:40the Google Play feed at /play,
- 1:05:42and the direct RSS feed at /rss on talkpython.fm.
- 1:05:46We're live streaming most of our recordings these days.
- 1:05:49If you want to be part of the show and have your comments featured on the air,
- 1:05:53be sure to subscribe to our YouTube channel at talkpython.fm/youtube.
- 1:05:57This is your host, Michael Kennedy.
- 1:05:59Thanks so much for listening.
- 1:06:00I really appreciate it.
- 1:06:02Now get out there and write some Python code.
- 1:06:04I'll see you next time.