WEBVTT

00:00:00.001 --> 00:00:04.000
Building web UIs in Python has always been an interesting proposition.

00:00:04.000 --> 00:00:09.200
On one end, we have the full web design story with artisanal HTML and CSS.

00:00:09.200 --> 00:00:13.900
On the other end, there are several Python platforms that aim to bring RAD,

00:00:13.900 --> 00:00:18.180
rapid application development style of building Python apps to the web.

00:00:18.180 --> 00:00:21.060
Those can be great, and I've covered a couple of them,

00:00:21.060 --> 00:00:24.400
but they usually reach a limit on what you can do

00:00:24.400 --> 00:00:27.100
or how they integrate with the larger web ecosystem.

00:00:27.700 --> 00:00:33.800
On this episode, we have Samuel Colvin back to share his latest exciting project, FastUI.

00:00:33.800 --> 00:00:38.080
With FastUI, you can build responsive web applications using React

00:00:38.080 --> 00:00:41.920
without writing a single line of JavaScript or touching npm.

00:00:41.920 --> 00:00:46.040
Yet designers and other tools can focus on React frontends

00:00:46.040 --> 00:00:48.900
for a professional spa-like app experience.

00:00:48.900 --> 00:00:55.400
This is Talk Python To Me, episode 449, recorded December 14th, 2023.

00:00:55.400 --> 00:01:12.980
Welcome to Talk Python To Me, a weekly podcast on Python.

00:01:12.980 --> 00:01:14.700
This is your host, Michael Kennedy.

00:01:14.700 --> 00:01:17.360
Follow me on Mastodon, where I'm @mkennedy,

00:01:17.360 --> 00:01:22.200
and follow the podcast using @talkpython, both on fosstodon.org.

00:01:22.400 --> 00:01:27.280
Keep up with the show and listen to over seven years of past episodes at talkpython.fm.

00:01:27.280 --> 00:01:31.040
We've started streaming most of our episodes live on YouTube.

00:01:31.040 --> 00:01:34.820
Subscribe to our YouTube channel over at talkpython.fm/youtube

00:01:34.820 --> 00:01:38.600
to get notified about upcoming shows and be part of that episode.

00:01:40.120 --> 00:01:42.740
This episode is sponsored by Bright Data.

00:01:42.740 --> 00:01:46.660
Bright Data is professional web scraping in a dataset marketplace.

00:01:46.660 --> 00:01:49.580
If you need data and it doesn't have an API,

00:01:49.580 --> 00:01:53.640
check out talkpython.fm/Bright Data today.

00:01:53.640 --> 00:01:56.220
And it's brought to you by Sentry.

00:01:56.220 --> 00:01:58.280
Don't let those errors go unnoticed.

00:01:58.280 --> 00:02:00.800
Use Sentry like we do here at Talk Python.

00:02:00.800 --> 00:02:04.140
Sign up at talkpython.fm/sentry.

00:02:05.500 --> 00:02:06.240
Hey, Samuel.

00:02:06.240 --> 00:02:07.820
Welcome back to Talk Python To Me.

00:02:07.820 --> 00:02:08.460
Thank you.

00:02:08.460 --> 00:02:09.900
Thank you very much for having me again.

00:02:09.900 --> 00:02:11.340
So soon after last time.

00:02:11.340 --> 00:02:12.900
It's always amazing to have you on.

00:02:12.900 --> 00:02:19.500
In fact, you were on just last week in a really cool show that tons of people enjoyed

00:02:19.500 --> 00:02:23.440
and is not yet out at the time of recording, but will be released to the world

00:02:23.440 --> 00:02:25.780
by the time your show goes out live.

00:02:25.780 --> 00:02:27.980
So it's a bit of a time travel thing.

00:02:27.980 --> 00:02:29.260
Very, very appropriate here.

00:02:29.260 --> 00:02:35.420
But it was under the full-time open source developers panel of like a bunch of folks,

00:02:35.420 --> 00:02:40.380
for example, Charlie Marsh, Will McGugan, Gina Houska, and so on, right?

00:02:40.380 --> 00:02:44.540
And you snuck in for a minute there on your travels.

00:02:44.540 --> 00:02:49.080
But now you're back and we're here to talk properly about something really excellent

00:02:49.080 --> 00:02:53.780
that you put together called Fast UI, which is going to be a lot of fun.

00:02:53.780 --> 00:02:53.980
Yeah.

00:02:54.220 --> 00:02:55.200
Thanks so much for having me.

00:02:55.200 --> 00:03:01.380
And yeah, I'm in a slightly better environment for a podcast than the stairwell of a restaurant

00:03:01.380 --> 00:03:03.200
somewhere in Istanbul.

00:03:03.200 --> 00:03:04.520
So yeah, it's nice to be there.

00:03:04.520 --> 00:03:06.260
High marks for effort there.

00:03:06.260 --> 00:03:06.660
Come on.

00:03:06.660 --> 00:03:07.300
That was great.

00:03:07.300 --> 00:03:12.280
It was good fun, but this is a better place to talk about these things.

00:03:12.280 --> 00:03:12.620
Yeah.

00:03:12.620 --> 00:03:15.560
Well, I hope you had a good trip and you're back in at it.

00:03:15.560 --> 00:03:19.220
Kim out in the audience points out, hey, could you just write another impressive tool for

00:03:19.220 --> 00:03:20.020
the next week's show?

00:03:20.020 --> 00:03:23.440
Because things are going pretty prolifically over there.

00:03:23.560 --> 00:03:27.860
Tell people a bit about Pydantic, the company they probably heard of the library, but just

00:03:27.860 --> 00:03:29.140
what are you up to these days?

00:03:29.140 --> 00:03:34.760
So Pydantic's obviously been around since 2017 originally, but then it's like something weird

00:03:34.760 --> 00:03:36.180
happened at the beginning of 2021.

00:03:36.180 --> 00:03:40.500
I don't know quite what that was, but Pydantic, the downloads just went crazy.

00:03:40.500 --> 00:03:43.900
So we were at 5 million downloads then and we're now at 130 million.

00:03:43.900 --> 00:03:46.280
So yeah, it's gone crazy.

00:03:46.280 --> 00:03:49.380
And then just a bit more than a year ago, I was very lucky.

00:03:49.380 --> 00:03:53.520
Sequoia got in touch with me and basically said that I want to start a company.

00:03:53.520 --> 00:03:58.460
I had been meaning to do that after I released Pydantic V2 that I was then working on.

00:03:58.460 --> 00:03:58.920
Yeah.

00:03:58.920 --> 00:04:03.560
I started the company beginning of this year and now have an amazing team of 10 people

00:04:03.560 --> 00:04:04.460
working with me.

00:04:04.460 --> 00:04:06.500
So we released Pydantic V2 finally.

00:04:06.500 --> 00:04:10.780
Having originally told people it would take me alone three months, it took me and I guess

00:04:10.780 --> 00:04:12.480
then six people a year in total.

00:04:12.480 --> 00:04:15.220
But that was released back in the summer.

00:04:15.560 --> 00:04:19.920
And now we're working on a platform that I'm not going to talk about now, but I would love

00:04:19.920 --> 00:04:22.400
it if you'd have me back, I guess, beginning of Q2.

00:04:22.400 --> 00:04:24.020
Is that next week or whatever?

00:04:24.020 --> 00:04:25.960
It's not quite next week.

00:04:25.960 --> 00:04:27.200
Q2 in 2024?

00:04:27.200 --> 00:04:28.400
Something like that?

00:04:28.400 --> 00:04:28.900
Yeah.

00:04:29.020 --> 00:04:32.420
I think we're going to try and get to Open Beta in Q1.

00:04:32.420 --> 00:04:33.200
So yeah.

00:04:33.200 --> 00:04:33.720
Okay.

00:04:33.720 --> 00:04:34.300
Fantastic.

00:04:34.300 --> 00:04:35.000
Yeah.

00:04:35.000 --> 00:04:35.420
Well.

00:04:35.420 --> 00:04:41.080
But off the back of, so that without getting as much details on it has platform component

00:04:41.080 --> 00:04:41.460
to it.

00:04:41.460 --> 00:04:44.580
And so we have people, people will be logging in, et cetera, et cetera.

00:04:44.580 --> 00:04:50.160
And I was just thinking about all of the path and the churn of building the relatively mechanical

00:04:50.160 --> 00:04:51.160
bits of an application.

00:04:51.160 --> 00:04:55.820
Again, it doesn't matter actually if you're building it with React or with one of the other

00:04:55.820 --> 00:04:59.580
front-end frameworks, you end up having a whole bunch of stuff that's duplicated between

00:04:59.580 --> 00:05:04.400
what the front-end guys are doing and what the full-stack developers or the back-end developers

00:05:04.400 --> 00:05:06.120
are building for us.

00:05:06.120 --> 00:05:09.340
And I guess for lots of people, there's a Pydantic model that's kind of at the core of lots of

00:05:09.340 --> 00:05:09.780
those bits.

00:05:09.780 --> 00:05:12.180
And I was just dreading all of that churn.

00:05:12.180 --> 00:05:16.600
And I had been wanting to build something like Fast UI for a long time, but the fact that we're

00:05:16.600 --> 00:05:21.400
going to be using it internally really spurred me on to go and get it built and release it

00:05:21.400 --> 00:05:23.960
in like a very incomplete phase to see what people thought.

00:05:23.960 --> 00:05:25.420
And yeah, there's been a great reaction.

00:05:25.660 --> 00:05:26.220
And here I am.

00:05:26.220 --> 00:05:28.820
Yeah, there has been quite the reaction to it.

00:05:28.820 --> 00:05:29.620
Let's see.

00:05:29.620 --> 00:05:31.560
Do the GitHub star test.

00:05:31.560 --> 00:05:36.140
It's 2.6 thousand stars and it's what?

00:05:36.140 --> 00:05:36.900
Two weeks old?

00:05:36.900 --> 00:05:37.360
Yeah.

00:05:37.360 --> 00:05:37.860
A month old?

00:05:37.860 --> 00:05:38.180
Yeah.

00:05:38.180 --> 00:05:38.760
A month old?

00:05:38.760 --> 00:05:39.840
Last month anyway.

00:05:39.840 --> 00:05:42.600
Well, it was only released publicly like, yeah, two weeks.

00:05:42.600 --> 00:05:43.400
Less than two weeks ago.

00:05:43.400 --> 00:05:44.720
Or maybe two weeks ago today.

00:05:44.720 --> 00:05:45.620
Oh, that's right.

00:05:45.620 --> 00:05:45.780
Yeah.

00:05:45.780 --> 00:05:50.100
You probably, so you worked on it a little bit private and then you flipped the bit on the

00:05:50.100 --> 00:05:50.960
public status.

00:05:50.960 --> 00:05:51.480
Yeah.

00:05:51.480 --> 00:05:54.380
That makes a lot of sense because you don't want people just to go, whoa, what are they building?

00:05:54.380 --> 00:05:55.400
I mean, maybe you do.

00:05:55.500 --> 00:05:56.980
What is this GitHub repo?

00:05:56.980 --> 00:05:59.640
They misspelled FastAPI.

00:05:59.640 --> 00:06:00.920
I don't know what they're working on.

00:06:00.920 --> 00:06:02.300
Yeah, exactly.

00:06:02.300 --> 00:06:06.900
And also, I mean, we have a team with lots of people who've done lots of open source, very

00:06:06.900 --> 00:06:08.060
strongly opinionated engineers.

00:06:08.060 --> 00:06:08.500
engineers.

00:06:08.500 --> 00:06:12.500
I can't even get my team to use it without kind of proving the value in it.

00:06:12.500 --> 00:06:15.740
So I worked on it a bit without really talking to them and then was like, right, I built this

00:06:15.740 --> 00:06:16.020
thing.

00:06:16.020 --> 00:06:17.400
Let's at least give it a try.

00:06:17.400 --> 00:06:17.760
Yeah.

00:06:17.760 --> 00:06:18.720
Because I don't know.

00:06:18.720 --> 00:06:20.080
Maybe I'm wrong in this.

00:06:20.140 --> 00:06:26.300
But I think it's quite a fundamentally different way of thinking about how you build user interfaces

00:06:26.300 --> 00:06:30.260
from lots of the tools that exist today in the Python ecosystem.

00:06:30.260 --> 00:06:35.180
And so there's a bit of a like education piece and trying to understand the principle as well

00:06:35.180 --> 00:06:37.460
as the like mechanics of going and using it.

00:06:37.520 --> 00:06:38.220
Yeah, absolutely.

00:06:38.220 --> 00:06:43.200
Well, we're going to dive into the philosophy, but I'll give people that too long didn't read

00:06:43.200 --> 00:06:43.500
version.

00:06:43.500 --> 00:06:50.700
Basically, you can create UIs in pure Python in sort of dynamic web framework friendly ways.

00:06:50.700 --> 00:06:51.220
Right.

00:06:51.340 --> 00:06:55.740
Yeah, probably the mistake is in my description of it because yes, it does that.

00:06:55.740 --> 00:07:01.000
But where I personally think fast UI is powerful and where we're using it in within the

00:07:01.000 --> 00:07:04.020
pedantic team is actually we have got front end developers.

00:07:04.020 --> 00:07:08.080
We've got some really expert guys like who are very comfortable building stuff in react.

00:07:08.080 --> 00:07:13.960
But we want to those two roles to have to constantly communicate to build every every

00:07:13.960 --> 00:07:14.580
individual bit.

00:07:14.580 --> 00:07:18.020
So the idea is I think if you go down the page a little bit, I kind of explain it.

00:07:18.020 --> 00:07:22.180
But like for a front for a Python developer, it's this way of building UIs without having

00:07:22.180 --> 00:07:28.600
to touch TypeScript or JavaScript or npm or any of those Byzantine like massive build tools.

00:07:28.600 --> 00:07:32.700
But then for a front end developer, it's this opportunity to go and build the best components

00:07:32.700 --> 00:07:38.980
you can and allow basically provide a powerful interface for your back end guys to go and build

00:07:38.980 --> 00:07:40.180
a build a UI with it.

00:07:40.180 --> 00:07:44.840
So kind of split those two things up and I guess allow react to do what react does brilliantly,

00:07:44.840 --> 00:07:47.700
which is allow which is provide these like reusable components.

00:07:47.940 --> 00:07:48.680
Yeah, absolutely.

00:07:48.680 --> 00:07:53.860
Kind of a framework as well to bring the navigation and the cohesion of the whole app together,

00:07:53.860 --> 00:07:56.680
not just a particular view or a page to what you would say, right?

00:07:56.680 --> 00:07:56.940
Yeah.

00:07:56.940 --> 00:07:57.360
Yeah.

00:07:57.360 --> 00:08:00.500
So the weird bit is principle of RESTful interfaces.

00:08:00.500 --> 00:08:05.120
We've all heard of RESTful and we all think we know what it means, which is basically something

00:08:05.120 --> 00:08:10.600
to do with a URL structure and return me some JSON that like gives me the data I need to render

00:08:10.600 --> 00:08:11.020
my view.

00:08:11.020 --> 00:08:16.940
Well, if you look at the rifle that Roy Fielding's original PhD, as is brilliantly described in

00:08:16.940 --> 00:08:19.760
this HTMX article that I talk about further on down here.

00:08:19.760 --> 00:08:21.380
He's not really talking about that stuff.

00:08:21.380 --> 00:08:21.620
Sure.

00:08:21.620 --> 00:08:24.280
He has some stuff on what the URL structure should be.

00:08:24.280 --> 00:08:30.100
But really, his principle is that the data returned from the back end should be self-describing

00:08:30.100 --> 00:08:33.940
as if it should have everything you need to go and render the user interface.

00:08:34.140 --> 00:08:38.940
So let's say, I think they're using the HTMX example, example of like a bank account.

00:08:38.940 --> 00:08:43.240
And if you go down to like principle, the long version, here we are, right?

00:08:43.240 --> 00:08:47.800
I've linked to the PhD, but more importantly, the HTMX article, which explains it really well.

00:08:47.800 --> 00:08:51.980
I think if we follow that, yeah, I think they'll even on that page, there's a very jokey tone

00:08:51.980 --> 00:08:55.100
lots of the time HTMX, but they also talk about a really cool thing.

00:08:55.100 --> 00:08:56.000
Yeah, absolutely.

00:08:56.000 --> 00:08:57.700
Somewhere I think they have, yeah, here we are, right?

00:08:57.940 --> 00:09:01.860
So if you look at the traditional JSON response, which I think is the second one, and you were

00:09:01.860 --> 00:09:03.220
trying to show, yeah, right.

00:09:03.220 --> 00:09:07.480
So this, you and I as humans can read this and be like, yeah, that kind of explains my

00:09:07.480 --> 00:09:08.860
bank account and what's going on.

00:09:08.860 --> 00:09:09.700
But there was not enough.

00:09:09.700 --> 00:09:13.960
It's got like an account number and a balance, which is a more complicated object, nested object

00:09:13.960 --> 00:09:15.320
and those types of things.

00:09:15.320 --> 00:09:15.620
Right.

00:09:15.620 --> 00:09:17.440
It's got all the things that we can read account number.

00:09:17.440 --> 00:09:17.700
Cool.

00:09:17.700 --> 00:09:18.620
That's a number balance.

00:09:18.620 --> 00:09:19.700
Yeah, that makes sense.

00:09:19.700 --> 00:09:24.000
But if you're a computer, there's not enough there to go and render someone the nice user interface

00:09:24.000 --> 00:09:26.380
they would want where they would have it displayed on a page.

00:09:26.760 --> 00:09:32.620
So if you were the engineering team in the bank trying to turn this into a web interface,

00:09:32.620 --> 00:09:39.220
you then need to go and have lots of very application specific or page specific logic to show where

00:09:39.220 --> 00:09:42.680
the account number goes and where the balance goes and where the status goes and stuff like

00:09:42.680 --> 00:09:42.920
that.

00:09:42.920 --> 00:09:44.600
And that causes an enormous amount of churn.

00:09:44.600 --> 00:09:48.320
And it means that it's particularly difficult when you have those engineers working in different

00:09:48.320 --> 00:09:51.540
time zones because you end up having this spec between the two.

00:09:51.540 --> 00:09:55.260
And then you always have this problem with software where fine, we can get it to work.

00:09:55.260 --> 00:09:56.700
But what happens when we come to add it?

00:09:56.700 --> 00:10:02.400
So what's the process of, let's say, we want to show as well on this page, your like joint

00:10:02.400 --> 00:10:04.320
account balance, let's say, just to make something up.

00:10:04.320 --> 00:10:09.440
What we probably need to do is we need to get back in guys to go and add that to endpoint.

00:10:09.440 --> 00:10:12.100
And then the front end, and that can be deployed.

00:10:12.100 --> 00:10:15.340
And then the front end can be updated to show that and the data is available.

00:10:15.340 --> 00:10:18.120
That is a lots of churn, lots of delay.

00:10:18.440 --> 00:10:18.600
Right.

00:10:18.600 --> 00:10:22.140
Lots of coordination between the two domain experts.

00:10:22.140 --> 00:10:26.880
And then it kind of, you've got that microservice cascading, like it's got to do, then this one's

00:10:26.880 --> 00:10:27.820
got to be upgraded.

00:10:27.820 --> 00:10:32.600
And then eventually there's enough flow of data through the system that the UI people can put

00:10:32.600 --> 00:10:33.020
it up there.

00:10:33.020 --> 00:10:33.220
Right.

00:10:33.220 --> 00:10:33.500
Right.

00:10:33.740 --> 00:10:38.240
And so, and it's bad in this case of like showing your bank balance, but it gets even

00:10:38.240 --> 00:10:44.040
worse when you have a form where every field in the form needs to be completed, for example.

00:10:44.040 --> 00:10:48.560
And so we basically have to deploy the front end that has all of the form components and

00:10:48.560 --> 00:10:51.820
the backend that receives that new form at the same time.

00:10:52.160 --> 00:10:56.140
And we've got this Pynantic model that, you know, depending on how we've done it, probably

00:10:56.140 --> 00:10:57.440
is used to define our form.

00:10:57.440 --> 00:10:59.820
And it might even be used to define our database.

00:10:59.820 --> 00:11:02.600
But like, we're not using a Pynantic model in the front end.

00:11:02.600 --> 00:11:07.420
TypeScript, in my opinion, is a big Achilles heel in typing is that you don't have any, you

00:11:07.420 --> 00:11:08.860
can't use type ins at runtime.

00:11:08.860 --> 00:11:12.100
And so we don't have an equivalent of Pynantic.

00:11:12.100 --> 00:11:14.620
And so we're basically trusting that data is how it is.

00:11:14.620 --> 00:11:20.080
So yeah, FastAPI is an attempt, sorry, Fast UI is an attempt to basically remove that

00:11:20.080 --> 00:11:25.840
need to like have complete synchronization between backend and front end by having beautifully

00:11:25.840 --> 00:11:27.760
designed components in the front end.

00:11:27.760 --> 00:11:31.020
Not saying what we have now is that beautiful, but that's the ideal log term.

00:11:31.020 --> 00:11:35.360
But then the backend can basically just do the orchestration, can say, show me a table,

00:11:35.360 --> 00:11:39.860
show me a form, show me a modal and put the following content in it, et cetera.

00:11:39.860 --> 00:11:40.220
Excellent.

00:11:40.220 --> 00:11:42.080
Nice comment from Tony on the audience.

00:11:42.080 --> 00:11:46.740
As I originally started in Python and went to using TypeScript, Pynantic made the transition

00:11:46.740 --> 00:11:48.480
back to Python so nice.

00:11:48.960 --> 00:11:54.300
And so in your description, you also have up here that this Pynantic is interesting,

00:11:54.300 --> 00:11:55.400
is involved here.

00:11:55.400 --> 00:11:58.760
Like what is the role that Pynantic plays in defining all this?

00:11:58.760 --> 00:12:04.680
So the idea is that we're getting to, of this RESTful UI is really that we end up having a

00:12:04.680 --> 00:12:08.620
bunch of components in a shared definition of some components.

00:12:08.620 --> 00:12:13.580
And we basically promise that the backend is going to send data that matches the types

00:12:13.580 --> 00:12:15.200
defined in the front end.

00:12:15.520 --> 00:12:19.020
Well, that's all very well, but if you're not careful, you end up not sending quite the

00:12:19.020 --> 00:12:19.400
right data.

00:12:19.400 --> 00:12:25.540
So what's nice is that all of the components that you can return from fast UI are themselves

00:12:25.540 --> 00:12:26.520
Pynantic models.

00:12:26.720 --> 00:12:31.260
So Pynantic goes off and does not only the validation, but also the coercion.

00:12:31.260 --> 00:12:33.160
And it does stuff like uses camel case.

00:12:33.160 --> 00:12:36.940
So the front end developers are happy because we've got no underscores anywhere.

00:12:36.940 --> 00:12:44.500
And so, yeah, all of the backend code for fast UI basically is just Pynantic models, which

00:12:44.500 --> 00:12:46.540
implement these components.

00:12:46.540 --> 00:12:46.860
Right?

00:12:47.080 --> 00:12:51.240
So it might be useful for those who can see this to go in and I can talk through an example.

00:12:51.240 --> 00:12:55.640
If we go into the code here and I can talk you through like a very basic component.

00:12:55.640 --> 00:12:56.720
Oh, maybe it'd be useful.

00:12:56.720 --> 00:12:57.600
I showed it here.

00:12:57.600 --> 00:13:02.260
So I've got the code base open here, just working on something.

00:13:02.260 --> 00:13:08.820
But if I open up here, source and then the Python package, and then we look into components and

00:13:08.820 --> 00:13:13.640
we can look at like a really simple component, probably a button, which would be kind of understandable

00:13:13.640 --> 00:13:14.380
to everyone.

00:13:14.380 --> 00:13:14.920
Where's button?

00:13:15.020 --> 00:13:15.460
Here we are.

00:13:15.460 --> 00:13:20.800
So this is just a plain Pynantic model, which contains text, which is the text you put within

00:13:20.800 --> 00:13:21.240
the button.

00:13:21.240 --> 00:13:24.880
Then it contains the event that you want to fire when someone clicks on it.

00:13:24.880 --> 00:13:31.580
And HTML type, which, you know, this matches what you can get in HTML button, reset, submit,

00:13:31.580 --> 00:13:35.540
and then class name, which becomes the classes that get applied.

00:13:35.540 --> 00:13:39.120
And then critically, this type, which is a literal, which has to be button.

00:13:39.120 --> 00:13:45.080
And that is used by the discriminated union in Pydantic to do the validation of different

00:13:45.080 --> 00:13:45.420
types.

00:13:45.420 --> 00:13:51.840
And it's also used by a big switch statement in the TypeScript to basically decide what component

00:13:51.840 --> 00:13:54.680
I'll go and render when I get an object.

00:13:54.680 --> 00:13:55.740
Right.

00:13:55.740 --> 00:13:57.140
So there's some TypeScript.

00:13:57.140 --> 00:14:01.640
Maybe it makes sense to talk a bit about the building blocks.

00:14:01.900 --> 00:14:06.580
You say FastUI is made up of four things, just so people can get a sense of like, you

00:14:06.580 --> 00:14:07.540
know, what's at play here?

00:14:07.540 --> 00:14:07.800
Right.

00:14:07.800 --> 00:14:12.660
So the four things that we have now, package, a Python package called FastUI, which I was

00:14:12.660 --> 00:14:14.340
just showing you there the types for.

00:14:14.340 --> 00:14:14.620
Yep.

00:14:14.660 --> 00:14:17.640
And then we have npm package called FastUI.

00:14:17.640 --> 00:14:23.720
Again, it's in the Pydantic organization, which is where the meat of the logic resides.

00:14:23.720 --> 00:14:29.920
And that's implementing basically the most of the components and all of the wiring to mean

00:14:29.920 --> 00:14:33.360
that when I return a button, the button component gets rendered.

00:14:33.360 --> 00:14:38.760
And then, but obviously, we don't probably want to end up using a vanilla button when we come

00:14:38.760 --> 00:14:40.140
to display it.

00:14:40.140 --> 00:14:45.940
So then I've implemented basically customization of the FastUI React library using Bootstrap.

00:14:45.940 --> 00:14:50.780
So all that's really doing is it's deciding what classes to append to use with each component

00:14:50.780 --> 00:14:52.600
and also just customizing a few of them.

00:14:52.600 --> 00:14:55.740
So for example, modal, there's no like nice way to do a vanilla modal.

00:14:55.740 --> 00:15:01.420
So the modal in the default FastUI, the end package just basically shows me alert saying

00:15:01.420 --> 00:15:02.300
this isn't implemented.

00:15:02.300 --> 00:15:05.020
Whereas the Bootstrap one uses a nice Bootstrap modal.

00:15:05.020 --> 00:15:11.540
And then we have finally FastUI prebuilt, which basically uses the FastUI package, customizes

00:15:11.540 --> 00:15:14.140
it with FastUI Bootstrap, and then builds it.

00:15:14.140 --> 00:15:20.120
And that means we can go and basically return that prebuilt React app without having to get

00:15:20.120 --> 00:15:24.000
our hands dirty with npm on Yarn and Vite and all the other.

00:15:24.000 --> 00:15:29.160
All the webpacky bundling, minifying, transpiling business.

00:15:29.300 --> 00:15:33.960
But the cool bit, in my opinion, of FastUI is that at its core, it's really the definition

00:15:33.960 --> 00:15:36.400
of a bunch of different schemas effectively.

00:15:36.400 --> 00:15:40.860
Those schemas are defined in Pydantic and they're defined in TypeScript, but they could

00:15:40.860 --> 00:15:46.820
perfectly well be, and really nicely, I just merged this the other day, we now use the JSON

00:15:46.820 --> 00:15:53.840
schema generated by Pydantic and JSON schema generated by the React types to basically go

00:15:53.840 --> 00:15:57.380
and test that there's an equivalent between those two models everywhere.

00:15:57.380 --> 00:16:01.200
But in theory, there's nothing to stop the front end from being built with another JavaScript

00:16:01.200 --> 00:16:04.600
library or even with something like HTML and HTMX.

00:16:04.600 --> 00:16:09.420
Or even you could go and use React Native and build, or even some kind of embedded device,

00:16:09.420 --> 00:16:11.020
you could go and implement those components.

00:16:11.020 --> 00:16:16.840
And then on the other side, and this is even more achievable, you could go and return data

00:16:16.840 --> 00:16:20.880
that matches those models from a Rust or Go service.

00:16:20.880 --> 00:16:24.860
And in theory, you don't have to change your UI at all, because all you're doing is I promise

00:16:24.860 --> 00:16:29.400
that I'm going to match these schemas, and then whatever front end or whatever back end

00:16:29.400 --> 00:16:30.740
can then communicate.

00:16:30.740 --> 00:16:32.640
Whether that comes to pass, I don't know yet.

00:16:32.640 --> 00:16:36.600
And obviously, I built the default back end in Pythin, because that's what I know best,

00:16:36.600 --> 00:16:38.240
and where I think Pydantic is really helpful.

00:16:38.240 --> 00:16:43.500
And I built the first front end in React and TypeScript, because one, that's what I know,

00:16:43.580 --> 00:16:45.240
and two, it's what we're using within Pydantic.

00:16:45.240 --> 00:16:48.400
But lots of people have asked about HTMX.

00:16:48.400 --> 00:16:50.820
People have also asked about Svelte and others.

00:16:50.820 --> 00:16:55.820
I think I wouldn't see the point in building fast UI in Vue, because I don't think it adds

00:16:55.820 --> 00:16:56.160
much.

00:16:56.160 --> 00:16:57.020
It's just a lot of work.

00:16:57.020 --> 00:17:03.220
But I think there's a world where we build a HTMX template rendered version of fast UI's

00:17:03.220 --> 00:17:04.900
front end that could be super valuable.

00:17:04.900 --> 00:17:05.540
That's interesting.

00:17:05.540 --> 00:17:11.400
So first point is, these different components sound like they are potentially a little mix

00:17:11.400 --> 00:17:11.940
and match.

00:17:11.940 --> 00:17:15.500
You know, you could take it all as one big thing, or you could say, really like the way

00:17:15.500 --> 00:17:20.300
it defines the React front end, but we're going to implement it some other endpoint.

00:17:20.300 --> 00:17:20.760
Yeah.

00:17:20.760 --> 00:17:26.000
I think it's something like, it'll be slightly skewed now because of tests, but I'd say it's

00:17:26.000 --> 00:17:30.960
sort of twice as much front end to back end at the moment, as in the, yeah, it's skewed

00:17:30.960 --> 00:17:32.980
a bit by tests, but even now there's more TypeScript.

00:17:33.320 --> 00:17:37.460
So I think the simplest thing to do, and you could do it pretty trivially would be to

00:17:37.460 --> 00:17:41.400
use another backend, another language for your backend service.

00:17:41.400 --> 00:17:45.600
And as long as it matches those types, and you could even go and use something like JSON

00:17:45.600 --> 00:17:46.740
Schema to enforce that.

00:17:46.740 --> 00:17:51.780
But yeah, re-implementing the front end, probably a bigger piece of work, but totally doable.

00:17:51.920 --> 00:17:54.560
I mean, I did it in my spare time in two weeks, built the whole thing.

00:17:54.560 --> 00:17:56.720
So it's not, you know, millions of different things.

00:17:56.720 --> 00:18:00.440
There's kind of 20 components at the moment that are then composable to build reasonably

00:18:00.440 --> 00:18:02.120
sophisticated like UIs.

00:18:02.480 --> 00:18:08.940
So this is a web front end, like Flask or Django sort of framework, but a way that really

00:18:08.940 --> 00:18:14.140
incorporates building the UI in Python and validating and enforcing that with Pydantic

00:18:14.140 --> 00:18:17.280
rather than just, hey, file new HTML.

00:18:17.280 --> 00:18:21.640
Let's just start typing and hope they line up, you know, like instead of trying to juggle

00:18:21.640 --> 00:18:26.880
all those different languages, CSS, HTML, all the JavaScript tooling for packing up stuff,

00:18:26.880 --> 00:18:28.900
just let's write Python, right?

00:18:28.900 --> 00:18:34.720
So maybe you have a simple example of what it looks like to define a real simple example

00:18:34.720 --> 00:18:37.200
here on the readme.

00:18:37.200 --> 00:18:44.900
It's got a very interesting parity between what is in the HTML DOM and is what is in the Python

00:18:44.900 --> 00:18:48.140
abstract syntax tree, I guess, right?

00:18:48.140 --> 00:18:53.200
And visually as well, the way you look at the code, it looks like the way it might look in

00:18:53.200 --> 00:18:53.680
HTML.

00:18:53.680 --> 00:18:57.460
Like give us a sense of what writing a UI in this would look like.

00:18:57.460 --> 00:18:57.740
Right.

00:18:57.740 --> 00:19:01.620
So I think the first of all, we have to talk about like the two enormous, the two most obvious

00:19:01.620 --> 00:19:02.500
pitfalls for this.

00:19:02.500 --> 00:19:09.320
One end of the pitfall you have, which I think is the biggest temptation is to basically mirror

00:19:09.320 --> 00:19:11.800
all of HTML in Python.

00:19:11.800 --> 00:19:16.160
And for those of us who are happy writing HTML or writing React, that sounds like hell.

00:19:16.160 --> 00:19:19.560
It's going to be slow because you have to do some weird rendering, but it's also just going

00:19:19.560 --> 00:19:24.620
to be a pig because I don't want to have to define every A, HRA, and everything else in

00:19:24.620 --> 00:19:25.340
Python code.

00:19:25.340 --> 00:19:29.620
It says, and there are going to be, it requires for a start, it requires you to know two things,

00:19:29.620 --> 00:19:30.600
Python and HTML.

00:19:30.600 --> 00:19:33.100
Whereas for HTML, you only need to know one.

00:19:34.720 --> 00:19:38.400
This portion of Talk Python To Me is brought to you by Bright Data.

00:19:38.400 --> 00:19:42.440
Bright Data helps you turn websites into structured data.

00:19:42.440 --> 00:19:46.880
There's an unimaginable amount of data available on the internet.

00:19:46.880 --> 00:19:52.360
And we're lucky to live in a time where we have so many APIs to access structured data.

00:19:52.760 --> 00:19:58.140
But the truth is that most of the data out there is not served up over a clean API.

00:19:58.140 --> 00:20:01.240
It's just sitting there on a web page as HTML.

00:20:01.240 --> 00:20:07.260
Maybe it's even further obscured behind some front-end JavaScript framework like Vue or React.

00:20:07.260 --> 00:20:09.880
What if you need access to that data?

00:20:09.880 --> 00:20:12.040
Web scraping to the rescue, right?

00:20:12.040 --> 00:20:18.240
Yes, but just like you wouldn't set up your own production infrastructure in your home office,

00:20:18.240 --> 00:20:22.740
running a web scraping job on a single computer at a fixed location can lead to a web

00:20:22.740 --> 00:20:28.020
your program being unreliable with data pinned to that IP's location and much of the time

00:20:28.020 --> 00:20:30.580
blocked for rate limits and other such causes.

00:20:30.580 --> 00:20:35.420
If you need to do professional web scraping, Bright Data is the place to start.

00:20:35.420 --> 00:20:39.680
They have award-winning proxy networks and powerful web scrapers.

00:20:39.680 --> 00:20:43.500
What's more is they have ready-to-use datasets for download,

00:20:43.500 --> 00:20:46.400
so you might not even need to scrape data at all.

00:20:46.400 --> 00:20:49.620
And if you can't find the dataset in their marketplace,

00:20:49.620 --> 00:20:52.600
they'll even build a custom dataset for you.

00:20:52.720 --> 00:20:56.320
From listening to the show, you know that I'm a privacy-conscious person,

00:20:56.320 --> 00:21:01.640
and that's why I'm happy to see that they are both CCPA and GDPR compliant.

00:21:01.640 --> 00:21:07.320
Bright Data has both low-code solutions as well as Python programming models with Async,

00:21:07.320 --> 00:21:08.840
IO, and Playwright.

00:21:08.840 --> 00:21:13.060
So if you have serious data needs and those websites don't offer APIs,

00:21:13.060 --> 00:21:14.800
then you need Bright Data.

00:21:15.000 --> 00:21:19.160
check them out today at talkpython.fm/brightdata.

00:21:19.160 --> 00:21:21.180
And please use that URL.

00:21:21.180 --> 00:21:23.920
That way they know you heard about them from us.

00:21:23.920 --> 00:21:27.060
That's talkpython.fm/brightdata.

00:21:27.060 --> 00:21:28.920
The link is in your podcast player show notes.

00:21:28.920 --> 00:21:31.140
Thank you to Bright Data for supporting the show.

00:21:32.720 --> 00:21:35.140
I always find these things that try to dodge,

00:21:35.140 --> 00:21:37.560
like dodge the fact that HTML exists.

00:21:37.560 --> 00:21:40.480
I find them, I don't know, I just, they don't resonate with me.

00:21:40.480 --> 00:21:42.020
I'm not entirely sure why.

00:21:42.020 --> 00:21:44.620
It's like, we have really nice things like CSS,

00:21:44.620 --> 00:21:50.500
and we have really, there's just so much tooling and frameworks,

00:21:50.500 --> 00:21:53.500
you know, you mentioned Brutestrap already, right?

00:21:53.500 --> 00:21:54.640
That just plug into there.

00:21:54.640 --> 00:21:57.880
And if it's like, well, we're just going to write, recreate it in Python.

00:21:57.880 --> 00:22:02.240
Well, it has all the oddities of HTML if it's going to be really high parity.

00:22:02.240 --> 00:22:06.360
And then you just have a less well-known way to do the same weird thing.

00:22:06.360 --> 00:22:06.880
You know, I don't know.

00:22:06.880 --> 00:22:08.740
It just, it doesn't resonate super with me.

00:22:08.740 --> 00:22:09.080
I agree.

00:22:09.080 --> 00:22:11.520
And I found the same thing at times with ORMs,

00:22:11.520 --> 00:22:15.780
that you end up, the worst case of an ORM is you work out what you need to do in SQL.

00:22:15.960 --> 00:22:18.500
Then you try and translate back from SQL to ORM,

00:22:18.500 --> 00:22:21.280
and it would be much nicer just to write my SQL.

00:22:21.280 --> 00:22:22.140
I mean, not always the case.

00:22:22.140 --> 00:22:27.480
ORMs can be powerful, but I think that they both can fall into the same trap if you're not careful.

00:22:27.480 --> 00:22:29.560
And then I was going to say, at the far end of the spectrum,

00:22:29.560 --> 00:22:33.340
the other end of the spectrum, you have, and I guess Django's admin view,

00:22:33.340 --> 00:22:35.200
for understandable reasons, could suffer from this,

00:22:35.200 --> 00:22:36.940
that you basically have a very small set of things.

00:22:36.940 --> 00:22:41.720
You have a table page and a details page and a form page, and that's kind of it, right?

00:22:41.720 --> 00:22:44.820
So there's this difficult trade-off, and where in that continuum

00:22:44.820 --> 00:22:48.400
do we try to choose what size of component to implement, right?

00:22:48.400 --> 00:22:50.580
So for example, here we have a heading,

00:22:50.580 --> 00:22:54.140
which is almost one-for-one matches what you would do in HTML.

00:22:54.140 --> 00:22:56.820
We have the text that goes within it, and we have the level,

00:22:56.820 --> 00:22:59.040
which, you know, it's slightly different syntax,

00:22:59.040 --> 00:23:02.380
but it's basically one-for-one matching an HTML tag.

00:23:02.380 --> 00:23:07.660
But then we have a table, which it doesn't look very much like an HTML table at all.

00:23:07.660 --> 00:23:12.380
We're not having to explicitly define the table body versus the table head.

00:23:12.480 --> 00:23:13.820
We're not having to put in each column.

00:23:13.820 --> 00:23:15.080
We're not having to worry.

00:23:15.080 --> 00:23:17.920
Yeah, there's lots of stuff here that is much less like it.

00:23:17.920 --> 00:23:23.160
And that's where it's in these very common components where there is consistent things

00:23:23.160 --> 00:23:26.820
that lots of people want to do, or lots of places in your app where you might want to do them,

00:23:26.820 --> 00:23:30.640
where I think a framework like Fast UI gets super powerful,

00:23:30.640 --> 00:23:37.320
because we can get you a table here with users defined and with a few columns with some customization

00:23:37.320 --> 00:23:41.320
on what happens when you, how we render each column much more quickly,

00:23:41.320 --> 00:23:43.300
then we could go write out all the HTML for that.

00:23:43.300 --> 00:23:45.140
And it's much more concise to read.

00:23:45.140 --> 00:23:50.960
It's like, it's consistent enough that something like GitHub Copilot will help you write it out

00:23:50.960 --> 00:23:52.740
where you do have a bit of customization to do.

00:23:52.740 --> 00:23:54.980
I think this is where it can be super powerful.

00:23:55.160 --> 00:23:56.460
Yeah, it is pretty interesting.

00:23:56.460 --> 00:23:57.580
And I like the hierarchy.

00:23:57.580 --> 00:24:02.440
For people listening, just check out github.com/pydantic slash fast UI.

00:24:02.440 --> 00:24:03.980
The example right there on the page.

00:24:03.980 --> 00:24:09.280
But what you do is you create a, in this case, a FastAPI, API endpoint,

00:24:09.280 --> 00:24:12.980
and then you return a hierarchy of elements out of fast UI.

00:24:12.980 --> 00:24:14.080
So we have a page.

00:24:14.080 --> 00:24:15.400
The page has components.

00:24:15.400 --> 00:24:18.180
The components are a list of a header and a table.

00:24:18.180 --> 00:24:22.920
The table has data, which maps over to a list of pydantic models,

00:24:22.920 --> 00:24:29.340
which then help say what goes in the field and for the column headings and things like that.

00:24:29.340 --> 00:24:30.260
It's pretty interesting.

00:24:30.260 --> 00:24:31.180
I think it's neat.

00:24:31.180 --> 00:24:31.500
Yeah.

00:24:31.500 --> 00:24:34.640
And obviously we can add other components like pagination that works.

00:24:34.640 --> 00:24:38.100
I think just to come back to the top, to how we do these views.

00:24:38.100 --> 00:24:43.240
The very simple, and it's most simple what fast UI's React app does,

00:24:43.240 --> 00:24:45.940
is it basically takes whatever the URL is you go to.

00:24:45.940 --> 00:24:48.760
So in this case, you might go to slash, to the base URL,

00:24:48.760 --> 00:24:54.840
and it prepens slash API and makes a request to that endpoint to basically say,

00:24:54.840 --> 00:24:55.620
what should I render?

00:24:55.620 --> 00:24:56.680
And it gets back.

00:24:56.680 --> 00:25:00.580
So here we're basically returning a list of pydantic models.

00:25:00.580 --> 00:25:05.500
All that the fast UI model is really doing is taking that list of pydantic models

00:25:05.500 --> 00:25:10.760
and calling model dump JSON on it to get the JSON that we return to the front end.

00:25:10.760 --> 00:25:15.640
And as I say, the front end then knows how to render each of those,

00:25:15.640 --> 00:25:17.340
each dictionary in the list is what it is.

00:25:17.340 --> 00:25:21.680
At its core, it's a list of objects to use JavaScript parlance.

00:25:21.680 --> 00:25:24.920
It just knows how to render each of them and renders each of them in turn.

00:25:24.920 --> 00:25:28.060
And then obviously they can then have nested other models,

00:25:28.060 --> 00:25:29.760
all of which it knows how to render.

00:25:29.940 --> 00:25:30.060
Yeah.

00:25:30.060 --> 00:25:31.980
It reminds me of a couple of things.

00:25:31.980 --> 00:25:33.280
I have an example.

00:25:33.280 --> 00:25:33.800
Is this?

00:25:33.800 --> 00:25:34.100
No.

00:25:34.100 --> 00:25:34.780
Somewhere along here.

00:25:34.780 --> 00:25:35.300
I pulled it up.

00:25:35.300 --> 00:25:39.160
It reminds me of kind of what React looks like.

00:25:39.160 --> 00:25:40.500
If people have done React, you know,

00:25:40.500 --> 00:25:44.820
you write a function that returns kind of an HTML thing,

00:25:44.820 --> 00:25:48.400
but then it has JavaScript arrow functions, right?

00:25:49.160 --> 00:25:51.400
But it has the same nested feel, right?

00:25:51.400 --> 00:25:55.060
Did React inspire you to create it this way or not really?

00:25:55.060 --> 00:25:55.840
Yeah, it did.

00:25:55.840 --> 00:25:58.680
I've done quite a lot of React and I like it a lot.

00:25:58.680 --> 00:26:01.160
I know as a popular piece of technology,

00:26:01.160 --> 00:26:05.100
there were lots of people who like to berate it,

00:26:05.100 --> 00:26:07.800
but I do think React has been a powerful step forward.

00:26:07.800 --> 00:26:11.060
And the greatest form of flattery is copying.

00:26:11.780 --> 00:26:14.600
There are enough other, like, sure, there are other more powerful,

00:26:14.600 --> 00:26:17.160
arguably more powerful, arguably more performant,

00:26:17.160 --> 00:26:20.640
new front-end libraries, but everything is component-based now.

00:26:20.640 --> 00:26:23.380
Like, you know, React has changed the,

00:26:23.380 --> 00:26:25.660
there was a sea change in how we did front-end

00:26:25.660 --> 00:26:26.840
with that component architecture.

00:26:26.840 --> 00:26:29.220
And JSX, similarly, is super powerful.

00:26:29.220 --> 00:26:31.600
So one of the things that I think we're going to get to,

00:26:31.600 --> 00:26:32.600
I don't want to dive into it yet,

00:26:32.600 --> 00:26:34.220
but like in React, you would say like,

00:26:34.220 --> 00:26:39.220
we're going to return a photo context or a switch

00:26:39.220 --> 00:26:41.760
or something that is not typically known in HTML.

00:26:41.760 --> 00:26:45.220
And these are higher order building blocks in the UI space, right?

00:26:45.220 --> 00:26:49.600
So when people think about what they're creating here in Python,

00:26:49.600 --> 00:26:53.780
it's not just the fundamental DOM objects and elements, is it?

00:26:53.780 --> 00:26:55.500
Right. So that is actually, yeah.

00:26:55.500 --> 00:26:57.580
So page here is a bit of ambiguity

00:26:57.580 --> 00:26:59.120
about how we're going to define a page.

00:26:59.120 --> 00:27:02.680
Like default implementation does something reasonably sensible.

00:27:02.680 --> 00:27:04.520
It like, you know, pads it, et cetera.

00:27:04.520 --> 00:27:07.680
But like heading isn't, there isn't much to do really.

00:27:07.680 --> 00:27:08.820
You're going to return a heading,

00:27:08.820 --> 00:27:10.020
but when you come to a table,

00:27:10.020 --> 00:27:12.540
there's a lot of debate about how you're going to do that.

00:27:12.540 --> 00:27:15.840
And then when you move on to like even higher order components,

00:27:15.840 --> 00:27:17.740
like a modal, then that's the,

00:27:17.740 --> 00:27:19.980
how exactly that's implemented is, you know,

00:27:19.980 --> 00:27:21.660
in some sense it's completely the choice

00:27:21.660 --> 00:27:23.260
of how you've implemented it in the front end.

00:27:23.260 --> 00:27:24.780
You could, you could do lots of different things,

00:27:24.780 --> 00:27:27.740
but yeah, the whole point is that it doesn't

00:27:27.740 --> 00:27:31.100
and shouldn't be like each HTML tag is written out.

00:27:31.100 --> 00:27:31.700
Because as I say,

00:27:31.700 --> 00:27:34.500
I think that would be a like obvious failure mode for this.

00:27:34.500 --> 00:27:34.880
Yeah.

00:27:34.880 --> 00:27:36.800
The other thing this reminds me of,

00:27:37.000 --> 00:27:39.520
by the way, just for people out there listening is

00:27:39.520 --> 00:27:42.540
that it looks a lot like a Flutter.

00:27:42.540 --> 00:27:44.000
If people have done any Flutter,

00:27:44.000 --> 00:27:46.480
you've got these widget hierarchies.

00:27:46.480 --> 00:27:48.800
You build them, you maybe set some properties,

00:27:48.800 --> 00:27:50.460
you add in a bunch of,

00:27:50.460 --> 00:27:52.160
a bunch of elements, you know,

00:27:52.160 --> 00:27:56.620
set some children to an array of other sub elements.

00:27:56.620 --> 00:27:57.980
And this is done, of course, in Dart,

00:27:57.980 --> 00:27:59.120
but it's, you know,

00:27:59.120 --> 00:28:01.300
this is kind of a Python version.

00:28:01.300 --> 00:28:02.600
That's similar as well.

00:28:02.600 --> 00:28:03.580
These higher order widgets.

00:28:03.780 --> 00:28:04.420
Yeah, absolutely.

00:28:04.420 --> 00:28:05.040
Similar thing.

00:28:05.040 --> 00:28:07.540
And actually, the other place where I've built this before

00:28:07.540 --> 00:28:09.800
is that internally Pydantic core,

00:28:09.800 --> 00:28:11.280
the Rust bit of Pydantic,

00:28:11.280 --> 00:28:13.840
is effectively not entirely different to this, right?

00:28:13.840 --> 00:28:17.800
You define these nested structures of different validators.

00:28:17.800 --> 00:28:20.780
Everything at its core is a like combined validator,

00:28:20.780 --> 00:28:22.420
which is in Rust terms,

00:28:22.420 --> 00:28:24.640
an enormous enum of all the different types of validator,

00:28:24.640 --> 00:28:26.400
some of which have nested within them,

00:28:26.400 --> 00:28:27.400
more and more validators.

00:28:27.400 --> 00:28:31.700
And that's how you build up nested structures of Pydantic models,

00:28:31.700 --> 00:28:33.260
which in turn is what these are.

00:28:33.260 --> 00:28:33.960
We're getting there.

00:28:33.960 --> 00:28:36.040
Yeah, the validators in the UI,

00:28:36.040 --> 00:28:37.840
they kind of like have a similar structure.

00:28:37.840 --> 00:28:39.620
A bit of a sidebar,

00:28:39.620 --> 00:28:40.820
just a bit of a piece of code in here.

00:28:40.820 --> 00:28:41.900
You've got table,

00:28:41.900 --> 00:28:42.920
which is a class,

00:28:42.920 --> 00:28:44.100
square bracket,

00:28:44.100 --> 00:28:44.980
user,

00:28:44.980 --> 00:28:46.500
which is another class,

00:28:46.500 --> 00:28:47.280
square bracket.

00:28:47.280 --> 00:28:49.540
I imagine that you and your team

00:28:49.540 --> 00:28:51.440
are deeper into the Python type system

00:28:51.440 --> 00:28:55.260
than the vast majority of others out there

00:28:55.260 --> 00:28:56.560
with all the work with Pydantic

00:28:56.560 --> 00:28:58.260
and the interoperability with Rust.

00:28:58.260 --> 00:28:59.740
What is that?

00:28:59.740 --> 00:29:01.080
Tell people about this.

00:29:01.080 --> 00:29:02.900
Yes, a table is a generic.

00:29:02.900 --> 00:29:03.760
So if you,

00:29:03.760 --> 00:29:05.520
you can imagine if you were doing list events,

00:29:05.520 --> 00:29:06.760
you would do list,

00:29:06.760 --> 00:29:07.540
square bracket,

00:29:07.540 --> 00:29:07.920
int.

00:29:07.920 --> 00:29:10.300
And that's basically the point is that

00:29:10.300 --> 00:29:13.280
list is a generic around its elements.

00:29:13.280 --> 00:29:16.020
Same as a dict is generic around its keys and its values.

00:29:16.020 --> 00:29:16.360
Well,

00:29:16.360 --> 00:29:19.440
table here is generic around the Pydantic model

00:29:19.440 --> 00:29:21.060
that you're using to,

00:29:21.060 --> 00:29:22.680
using for each row.

00:29:22.680 --> 00:29:24.640
And particularly what that means is that,

00:29:24.780 --> 00:29:27.560
what it means practically is that table has access

00:29:27.560 --> 00:29:32.500
to the class when it's deciding what the default columns are.

00:29:32.500 --> 00:29:35.080
So if you don't define the columns list as we have here

00:29:35.080 --> 00:29:36.500
to say what columns to display,

00:29:36.500 --> 00:29:39.480
it'll show all of the fields in the Pydantic model.

00:29:39.480 --> 00:29:41.560
And the point is we get access to that,

00:29:41.560 --> 00:29:43.320
to the user before we've,

00:29:43.320 --> 00:29:43.760
even if,

00:29:43.760 --> 00:29:45.280
even if data was empty,

00:29:45.280 --> 00:29:47.200
before the validation has happened.

00:29:47.200 --> 00:29:48.600
Is it necessary?

00:29:48.600 --> 00:29:50.280
Is it slightly like,

00:29:50.280 --> 00:29:50.660
yeah,

00:29:50.660 --> 00:29:52.400
fancy use of Pydantic types,

00:29:52.400 --> 00:29:53.380
Python types,

00:29:53.380 --> 00:29:53.940
maybe it is,

00:29:54.000 --> 00:29:54.300
but yeah,

00:29:54.300 --> 00:29:55.040
if you know,

00:29:55.040 --> 00:30:00.340
forgive the Pydantic team or me in particular for occasionally doing fancy things with Python types.

00:30:00.340 --> 00:30:02.520
That is definitely occupational hazard of what we do.

00:30:02.520 --> 00:30:02.840
Yeah.

00:30:02.840 --> 00:30:04.420
I didn't mean it as a negative.

00:30:04.420 --> 00:30:05.580
I just thought it was interesting.

00:30:05.580 --> 00:30:05.960
No,

00:30:05.960 --> 00:30:06.500
I agree.

00:30:06.500 --> 00:30:06.860
And actually,

00:30:06.860 --> 00:30:10.140
I had it somewhere else on forms and I removed it and realized it was,

00:30:10.140 --> 00:30:10.500
it was,

00:30:10.500 --> 00:30:11.100
it was unnecessary.

00:30:11.100 --> 00:30:13.060
So you can definitely do too much,

00:30:13.060 --> 00:30:14.880
such a thing as too much Python typing.

00:30:15.040 --> 00:30:15.200
Yeah.

00:30:15.200 --> 00:30:15.520
Yeah.

00:30:15.520 --> 00:30:15.780
Yeah.

00:30:15.780 --> 00:30:15.860
Yeah.

00:30:15.860 --> 00:30:16.360
For sure.

00:30:16.360 --> 00:30:17.460
It is pretty interesting.

00:30:17.460 --> 00:30:20.920
So let's maybe talk about some of the examples.

00:30:20.920 --> 00:30:21.320
Actually,

00:30:21.320 --> 00:30:21.940
before we do,

00:30:21.940 --> 00:30:27.700
just give us a sense of where does this fit in the UI space for Python?

00:30:27.840 --> 00:30:28.460
On one hand,

00:30:28.460 --> 00:30:29.860
we've got Flask,

00:30:29.860 --> 00:30:30.700
Django,

00:30:30.700 --> 00:30:31.720
FastAPI,

00:30:31.720 --> 00:30:32.660
returning HTML,

00:30:32.660 --> 00:30:33.740
et cetera,

00:30:33.740 --> 00:30:35.960
where it's all on you.

00:30:36.080 --> 00:30:39.240
you're doing all the five languages of web apps,

00:30:39.240 --> 00:30:41.640
SQL or some query language,

00:30:41.640 --> 00:30:42.340
Python,

00:30:42.340 --> 00:30:43.260
JavaScript,

00:30:43.260 --> 00:30:44.060
CSS,

00:30:44.060 --> 00:30:45.600
some other tools,

00:30:45.600 --> 00:30:45.900
right?

00:30:45.900 --> 00:30:48.160
Like you're doing all that and you're doing my hand.

00:30:48.160 --> 00:30:48.960
On the other end,

00:30:48.960 --> 00:30:50.700
we've got tools that are pretty cool.

00:30:50.700 --> 00:30:55.900
Like we've got Anvil that lets you just write Python and do a draggy dropy sort of thing,

00:30:55.900 --> 00:30:56.380
which is,

00:30:56.380 --> 00:30:57.180
is really neat,

00:30:57.180 --> 00:30:58.680
but it fits into a kind of a,

00:30:58.680 --> 00:31:00.660
a box for those types of apps.

00:31:00.660 --> 00:31:02.500
I just discovered DropBase.

00:31:02.500 --> 00:31:03.340
Have you heard of DropBase?

00:31:03.340 --> 00:31:04.520
Not seen DropBase.

00:31:04.520 --> 00:31:04.800
Yeah.

00:31:05.160 --> 00:31:07.360
We've seen a lot of these like,

00:31:07.360 --> 00:31:08.940
get me a UI more quickly.

00:31:08.940 --> 00:31:11.720
A lot of them are like kind of low code.

00:31:11.720 --> 00:31:12.000
Anvil,

00:31:12.000 --> 00:31:13.300
maybe I wouldn't really quite put it there,

00:31:13.300 --> 00:31:14.800
but they're pretty like low code,

00:31:14.800 --> 00:31:18.580
but then there's places where Python goes to make it dynamic,

00:31:18.580 --> 00:31:18.880
right?

00:31:18.880 --> 00:31:23.100
So where in that spectrum would you put fast UI as it is today?

00:31:23.100 --> 00:31:23.700
Interestingly,

00:31:23.700 --> 00:31:25.980
and one of the reasons I wanted to come and talk to you was I heard your,

00:31:25.980 --> 00:31:26.520
you were,

00:31:26.520 --> 00:31:27.820
you were talking the other day on,

00:31:27.820 --> 00:31:32.480
on your other podcast and I heard you talking about fast UI and kind of,

00:31:32.480 --> 00:31:34.200
I'd say categorizing it into that,

00:31:34.280 --> 00:31:35.080
that group.

00:31:35.080 --> 00:31:36.100
And what I wanted to kind of,

00:31:36.100 --> 00:31:37.680
one of the things I wanted to come and say was,

00:31:37.680 --> 00:31:38.240
yes,

00:31:38.240 --> 00:31:39.000
we can do that.

00:31:39.000 --> 00:31:39.420
But the,

00:31:39.420 --> 00:31:43.800
the use case we have within Pydantic is actually to go and build a pretty complex,

00:31:43.800 --> 00:31:45.580
fully fledged application with,

00:31:45.580 --> 00:31:47.400
with front end developers building components,

00:31:47.400 --> 00:31:49.280
but just get rid of that churn.

00:31:49.280 --> 00:31:49.820
Right.

00:31:49.820 --> 00:31:51.260
Something more like Gmail,

00:31:51.260 --> 00:31:52.240
less like,

00:31:52.740 --> 00:31:56.100
here's a table that I can click on and see some related table.

00:31:56.100 --> 00:31:56.420
Right.

00:31:56.420 --> 00:31:56.760
Exactly.

00:31:56.760 --> 00:32:01.980
And what I should probably put in the demo and probably where Pydantic is people most associated

00:32:01.980 --> 00:32:02.580
and where it's,

00:32:02.580 --> 00:32:04.600
this is going to be most useful is within forms.

00:32:05.040 --> 00:32:06.920
So I don't know if you want to go to the,

00:32:06.920 --> 00:32:08.480
to the demo and I can talk people through,

00:32:08.480 --> 00:32:12.500
but like within fast UI is dedicated to forms.

00:32:12.500 --> 00:32:17.240
We can do things like nested Pydantic models all become components within a form.

00:32:17.240 --> 00:32:20.580
And obviously we can do client side validation with a whole bunch of stuff,

00:32:20.580 --> 00:32:22.360
but we can also do server side validation,

00:32:22.360 --> 00:32:24.340
but then we get all the fancy stuff.

00:32:24.340 --> 00:32:25.740
Like if the,

00:32:25.740 --> 00:32:29.200
if the data is invalid and you get a validation error on the,

00:32:29.200 --> 00:32:30.440
on the server side,

00:32:30.440 --> 00:32:33.420
we'll then basically re-render the form with the errors in place.

00:32:33.420 --> 00:32:38.240
All that stuff that like anyone building a web application has to go and implement some version of it.

00:32:38.240 --> 00:32:39.320
At the moment there's,

00:32:39.320 --> 00:32:40.200
there are some,

00:32:40.200 --> 00:32:44.100
some react libraries that will build you a form from JSON schema,

00:32:44.100 --> 00:32:46.360
but they don't perfectly fit in with,

00:32:46.480 --> 00:32:47.960
with what Pydantic does or with,

00:32:47.960 --> 00:32:48.960
with FastAPI.

00:32:48.960 --> 00:32:53.440
And so I have built some variant of that about five times.

00:32:53.440 --> 00:32:56.380
I still think the state of the art until now is Django,

00:32:56.380 --> 00:32:59.840
but like lots of us don't want to build our web applications completely with Django

00:32:59.840 --> 00:33:00.400
because it's,

00:33:00.400 --> 00:33:03.420
it's pretty all or nothing despite the wonder that it's Django.

00:33:03.420 --> 00:33:06.600
And so that's the kind of space where for me,

00:33:06.600 --> 00:33:06.900
this,

00:33:06.900 --> 00:33:12.080
this like becomes a really stands out because what would have been to do it properly?

00:33:12.080 --> 00:33:13.600
It's days of work to get form,

00:33:13.600 --> 00:33:15.420
to get form submission to work,

00:33:15.600 --> 00:33:16.580
get client side validation,

00:33:16.580 --> 00:33:17.720
server side validation,

00:33:17.720 --> 00:33:19.760
get the redirect after your form.

00:33:19.760 --> 00:33:20.600
None of that stuff is,

00:33:20.600 --> 00:33:21.480
is entirely trivial,

00:33:21.480 --> 00:33:22.960
even for those of us who've done it before.

00:33:22.960 --> 00:33:27.220
Whereas with the theory is with fast UI and in,

00:33:27.220 --> 00:33:29.880
although fast UI does not require FastAPI,

00:33:29.880 --> 00:33:31.260
the form stuff is,

00:33:31.260 --> 00:33:33.360
is quite tightly integrated with FastAPI.

00:33:33.360 --> 00:33:34.300
and you can get,

00:33:34.300 --> 00:33:34.680
yeah,

00:33:34.680 --> 00:33:36.460
a really good experience of building,

00:33:36.460 --> 00:33:37.680
building stuff like forms.

00:33:37.680 --> 00:33:38.540
I think that,

00:33:38.540 --> 00:33:40.800
that where the alternative really today is,

00:33:40.800 --> 00:33:45.680
is to use no disrespect to any of the fast libraries or any of the other things.

00:33:45.680 --> 00:33:50.620
But I think the only real alternative right now is implement it yourself or use Django.

00:33:50.840 --> 00:33:50.960
Yeah.

00:33:50.960 --> 00:33:52.220
But I do also want to,

00:33:52.220 --> 00:33:53.440
but maybe before we get to that,

00:33:53.440 --> 00:33:56.480
let's try to take a little survey of what are these widgets,

00:33:56.480 --> 00:33:58.040
these building blocks that you can use.

00:33:58.040 --> 00:33:58.460
Yeah.

00:33:58.460 --> 00:33:58.800
Is that right?

00:33:58.800 --> 00:33:59.220
Yeah,

00:33:59.220 --> 00:33:59.560
absolutely.

00:33:59.560 --> 00:34:01.340
I think I can find them here.

00:34:01.340 --> 00:34:01.700
Yes.

00:34:01.700 --> 00:34:02.140
Yeah.

00:34:02.300 --> 00:34:04.020
So you've got a fast UI demo,

00:34:04.020 --> 00:34:07.500
which I'll link to at onrender.com prefix,

00:34:07.500 --> 00:34:13.540
but you talk about some of the things that you can just create in that Python hierarchy

00:34:13.540 --> 00:34:17.380
that you return that builds up your UI there.

00:34:17.380 --> 00:34:19.120
So maybe we talk us through some of the things that are here.

00:34:19.120 --> 00:34:19.440
Yes.

00:34:19.440 --> 00:34:21.360
We have the kind of generic markdown component,

00:34:21.360 --> 00:34:24.060
which will go up and renders a markdown.

00:34:24.060 --> 00:34:25.200
This table itself is,

00:34:25.200 --> 00:34:27.300
is implemented using the markdown component.

00:34:27.300 --> 00:34:28.760
Just a one side note,

00:34:28.760 --> 00:34:30.220
the markdown and the code,

00:34:30.220 --> 00:34:33.080
because they have quite a lot of JavaScript associated with them,

00:34:33.080 --> 00:34:35.360
but they're actually lazily loaded to make the,

00:34:35.360 --> 00:34:38.920
make the prebuilt fast UI app faster to load.

00:34:38.920 --> 00:34:39.940
Then we have text,

00:34:39.940 --> 00:34:41.160
probably the simplest one of all,

00:34:41.160 --> 00:34:42.980
just render some text paragraph.

00:34:42.980 --> 00:34:43.600
Again,

00:34:43.600 --> 00:34:45.320
very simple page titles,

00:34:45.320 --> 00:34:46.180
a slightly funny one.

00:34:46.180 --> 00:34:48.080
It doesn't actually display anything on the page,

00:34:48.080 --> 00:34:49.260
but it changes the,

00:34:49.260 --> 00:34:50.340
the browser title.

00:34:50.340 --> 00:34:52.600
So what you see in the tab at the top of the page,

00:34:52.600 --> 00:34:53.700
it's not always easy to do.

00:34:53.700 --> 00:34:56.360
Like how do you inject it into the head when you're in the body?

00:34:56.360 --> 00:34:56.620
And like,

00:34:56.620 --> 00:34:58.600
it takes a little bit of integration there.

00:34:58.600 --> 00:34:58.800
Yeah.

00:34:58.800 --> 00:34:59.120
Right.

00:34:59.120 --> 00:34:59.480
Exactly.

00:34:59.720 --> 00:35:00.260
Heading again,

00:35:00.260 --> 00:35:00.920
very simple,

00:35:00.920 --> 00:35:04.000
like one to six HTML heading code,

00:35:04.000 --> 00:35:05.140
bit more sophisticated.

00:35:05.140 --> 00:35:06.440
And if you click on code,

00:35:06.440 --> 00:35:06.720
maybe,

00:35:06.720 --> 00:35:10.100
maybe those who can see it will be able to click through code.

00:35:10.100 --> 00:35:10.420
Yeah.

00:35:10.420 --> 00:35:11.320
So code is there.

00:35:11.320 --> 00:35:11.740
We,

00:35:11.740 --> 00:35:13.580
we get a like highlighted bit of,

00:35:13.580 --> 00:35:15.300
a bit of source code displayed.

00:35:15.300 --> 00:35:18.780
It's color coded with like class types,

00:35:18.780 --> 00:35:19.840
having a color and keywords,

00:35:19.840 --> 00:35:20.460
having a color.

00:35:20.460 --> 00:35:21.080
That's nice.

00:35:21.080 --> 00:35:21.980
Like you would see in,

00:35:21.980 --> 00:35:23.220
in GitHub or something like that.

00:35:23.220 --> 00:35:23.740
So again,

00:35:23.740 --> 00:35:24.120
just,

00:35:24.120 --> 00:35:25.240
just like work out the box.

00:35:25.240 --> 00:35:28.160
Then we have some components like a link list and link,

00:35:28.160 --> 00:35:30.620
which are used in other components mostly.

00:35:30.620 --> 00:35:31.100
So if you,

00:35:31.100 --> 00:35:31.680
the nav bar,

00:35:31.680 --> 00:35:34.140
you see at the top of the page there that uses a link list.

00:35:34.140 --> 00:35:35.280
And then we have links.

00:35:35.480 --> 00:35:37.720
Then we get into kind of more sophisticated components.

00:35:37.720 --> 00:35:38.480
So the first one,

00:35:38.480 --> 00:35:39.040
you see a button,

00:35:39.040 --> 00:35:40.980
which loads a modal and then the button,

00:35:40.980 --> 00:35:42.180
which loads a dynamic modal.

00:35:42.180 --> 00:35:43.940
So that when the modal loads,

00:35:43.940 --> 00:35:45.600
it will make a request to get the content.

00:35:45.600 --> 00:35:46.900
You want to see within that modal.

00:35:47.020 --> 00:35:50.200
So that could be a form or it could be customized depending on,

00:35:50.200 --> 00:35:51.760
on the form in the page.

00:35:51.760 --> 00:35:54.000
Then we have loading content from the server,

00:35:54.000 --> 00:35:55.600
which is the same thing we were doing in the modal,

00:35:55.600 --> 00:35:56.420
but on the page.

00:35:56.420 --> 00:35:58.240
Then we have this SSE component.

00:35:58.240 --> 00:35:58.860
So again,

00:35:58.860 --> 00:36:01.560
very simple to use within fast UI,

00:36:01.560 --> 00:36:04.580
but like quite a lot of work to use server side events to basically

00:36:04.580 --> 00:36:06.600
dynamically update a react component.

00:36:06.600 --> 00:36:07.880
If you weren't using that.

00:36:08.420 --> 00:36:12.920
So your server load SSE widget that provides,

00:36:12.920 --> 00:36:13.320
like you said,

00:36:13.320 --> 00:36:14.600
server sent events,

00:36:14.600 --> 00:36:16.800
which I don't know how many people are familiar with SSE.

00:36:16.800 --> 00:36:20.340
I'm sure they're familiar with web sockets and they're familiar with just

00:36:20.340 --> 00:36:21.620
like a JavaScript event,

00:36:21.620 --> 00:36:24.780
but this is like an intermediate sort of lightweight one directional,

00:36:24.780 --> 00:36:27.040
but the normally the opposite in reverse,

00:36:27.040 --> 00:36:29.720
I guess from the server to the client sort of pushing out stuff.

00:36:29.720 --> 00:36:29.920
Right.

00:36:29.920 --> 00:36:31.280
So that's a really powerful thing.

00:36:31.280 --> 00:36:31.900
And if it's,

00:36:31.900 --> 00:36:35.000
if it's that easy to just hook a function call when something happens,

00:36:35.000 --> 00:36:35.740
that's pretty cool.

00:36:35.740 --> 00:36:38.380
One of the things I want to try with SSE that I think will work

00:36:38.380 --> 00:36:42.060
really nicely is LLM responses where you get like one token at a time

00:36:42.060 --> 00:36:43.500
because you don't want to wait for the whole thing.

00:36:43.500 --> 00:36:43.800
Yeah.

00:36:43.800 --> 00:36:47.700
The center events would be perfect for basically printing out the response

00:36:47.700 --> 00:36:48.320
from an LLM.

00:36:48.320 --> 00:36:48.680
And again,

00:36:48.680 --> 00:36:49.540
it would be like,

00:36:49.540 --> 00:36:49.760
you know,

00:36:49.760 --> 00:36:52.240
two lines of code to add that to an app with fast UI.

00:36:52.240 --> 00:36:55.300
It would not be two lines of code to go and implement that yourself,

00:36:55.300 --> 00:36:58.600
whether you're using pure JavaScript or react or whatever framework.

00:36:58.600 --> 00:36:59.160
Yeah.

00:36:59.160 --> 00:37:00.040
And we have,

00:37:00.040 --> 00:37:00.780
have iframe,

00:37:00.780 --> 00:37:01.600
which again,

00:37:01.600 --> 00:37:02.140
kind of map,

00:37:02.140 --> 00:37:04.660
we're back to kind of mapping one-to-one to a component.

00:37:04.660 --> 00:37:07.800
One of the nice things to say about both iframe and image is they were

00:37:08.340 --> 00:37:09.240
by other people.

00:37:09.240 --> 00:37:11.440
So I don't think I'd even created an issue asking for them,

00:37:11.440 --> 00:37:13.000
but people have come along and added them.

00:37:13.000 --> 00:37:14.340
It's been one of the nice things to see.

00:37:14.340 --> 00:37:17.900
I think we had 18 or so people contribute to the first release,

00:37:17.900 --> 00:37:20.040
first release after my initial release,

00:37:20.040 --> 00:37:20.620
or sorry,

00:37:20.620 --> 00:37:22.020
the second release of fast UI.

00:37:22.020 --> 00:37:22.520
So yeah,

00:37:22.520 --> 00:37:24.040
good engagement from lots of people.

00:37:24.040 --> 00:37:24.740
Image.

00:37:24.920 --> 00:37:25.040
Yeah.

00:37:25.040 --> 00:37:28.440
So you've got a bunch of UI stuff here and it just,

00:37:28.440 --> 00:37:30.740
as I look at this and I see what you're building,

00:37:30.740 --> 00:37:32.580
it just makes me think of like,

00:37:32.580 --> 00:37:32.760
wow,

00:37:32.760 --> 00:37:34.900
there's an opportunity for stuff like,

00:37:34.900 --> 00:37:36.140
like what you get out,

00:37:36.140 --> 00:37:37.200
not necessarily the same as,

00:37:37.200 --> 00:37:39.700
but like what you get out of say tailwind UI,

00:37:39.700 --> 00:37:43.680
where the things you might work with are on off switches,

00:37:43.680 --> 00:37:44.240
you know,

00:37:44.240 --> 00:37:44.780
like toggles,

00:37:44.780 --> 00:37:48.620
like you might see in your phone or other sort of elements that have like

00:37:48.620 --> 00:37:53.040
a lot of design imbued in them that people can just grab and use almost

00:37:53.040 --> 00:37:56.580
like a Django philosophy for the front end in a sense there.

00:37:56.580 --> 00:38:00.140
Is that something that you are dreaming of or?

00:38:00.140 --> 00:38:03.240
Someone was complaining somewhere that we didn't have a grid component yet.

00:38:03.240 --> 00:38:04.380
And I think we'll do one,

00:38:04.380 --> 00:38:06.500
but like those bits get quite opinionated,

00:38:06.500 --> 00:38:06.780
but yeah,

00:38:06.780 --> 00:38:09.420
like calendar completely obvious choice,

00:38:09.420 --> 00:38:09.660
right?

00:38:09.660 --> 00:38:12.080
Complete faff to go and implement that yourself in HTML.

00:38:12.080 --> 00:38:15.260
Commonly used trivial to define because,

00:38:15.260 --> 00:38:16.020
because the definition,

00:38:16.020 --> 00:38:17.560
there aren't that many different things to define.

00:38:17.560 --> 00:38:17.760
You,

00:38:17.760 --> 00:38:18.640
you choose your month,

00:38:18.640 --> 00:38:19.180
you know,

00:38:19.180 --> 00:38:21.280
most of us are on the Gregorian calendar,

00:38:21.280 --> 00:38:21.580
right?

00:38:21.580 --> 00:38:21.980
We're not,

00:38:21.980 --> 00:38:24.920
we're not going to have to change too much what calendar we're going to render.

00:38:24.920 --> 00:38:25.800
So yeah,

00:38:25.800 --> 00:38:27.660
that's a perfect example of the kind of thing.

00:38:27.660 --> 00:38:28.700
Tiles like this,

00:38:28.700 --> 00:38:29.060
again,

00:38:29.060 --> 00:38:31.240
totally possible to go and implement them.

00:38:31.240 --> 00:38:31.940
And again,

00:38:31.940 --> 00:38:33.180
obviously you can use,

00:38:33.180 --> 00:38:34.760
we can provide some nice default,

00:38:34.760 --> 00:38:39.400
but also if you're a bigger company and you want to go and customize it,

00:38:39.440 --> 00:38:40.300
you can totally do that.

00:38:40.300 --> 00:38:44.540
And you can have a front end developer go through and implement the classes that basically customize,

00:38:44.540 --> 00:38:45.720
customize the look.

00:38:45.720 --> 00:38:47.820
I wanted to come back just and show you some of the,

00:38:47.820 --> 00:38:48.200
some of that,

00:38:48.200 --> 00:38:49.460
some of the other components.

00:38:49.460 --> 00:38:50.820
So we were on,

00:38:50.820 --> 00:38:51.240
yeah,

00:38:51.240 --> 00:38:51.680
this one.

00:38:51.680 --> 00:38:51.960
Yeah.

00:38:52.200 --> 00:38:53.700
I don't know if we have anything more below that,

00:38:53.700 --> 00:38:58.480
but I would love to show you the tables because the tables and the forms are really where it comes into.

00:38:58.480 --> 00:39:00.100
So cities is probably the best example.

00:39:00.100 --> 00:39:00.660
Cities is the one.

00:39:00.660 --> 00:39:00.920
Okay.

00:39:00.920 --> 00:39:01.260
Yeah.

00:39:01.260 --> 00:39:01.520
Awesome.

00:39:01.520 --> 00:39:06.460
This is a list of cities just for some public data set with country and population.

00:39:06.460 --> 00:39:07.440
But at the top,

00:39:07.500 --> 00:39:07.820
you see,

00:39:07.820 --> 00:39:10.300
we have a filter to choose by country.

00:39:10.300 --> 00:39:11.380
And if we click here,

00:39:11.380 --> 00:39:11.820
if you start,

00:39:11.820 --> 00:39:13.740
start searching like UN or something,

00:39:13.740 --> 00:39:15.580
you'll see we're doing a server side.

00:39:15.580 --> 00:39:16.700
We're loading from the server,

00:39:16.700 --> 00:39:17.460
the list of cities.

00:39:17.460 --> 00:39:18.380
So again,

00:39:18.380 --> 00:39:19.900
this component to go and implement,

00:39:19.900 --> 00:39:21.440
if you were going to do that from scratch,

00:39:21.440 --> 00:39:22.220
you've got to have,

00:39:22.220 --> 00:39:23.280
use some like,

00:39:23.280 --> 00:39:23.740
whatever,

00:39:23.740 --> 00:39:25.360
this is a list of countries.

00:39:25.360 --> 00:39:25.920
So if you do like,

00:39:26.020 --> 00:39:26.440
all countries,

00:39:26.440 --> 00:39:26.700
sorry,

00:39:26.700 --> 00:39:27.540
I'm typing in cities.

00:39:27.540 --> 00:39:28.660
Good.

00:39:28.660 --> 00:39:29.020
Like UN,

00:39:29.020 --> 00:39:30.720
United Kingdom and United States.

00:39:30.720 --> 00:39:30.940
Yeah.

00:39:30.940 --> 00:39:31.440
Perfect.

00:39:31.440 --> 00:39:31.840
There you go.

00:39:31.840 --> 00:39:34.500
And then we do United States or whatever.

00:39:34.500 --> 00:39:35.480
Yeah.

00:39:35.480 --> 00:39:37.940
And then we'll get a bunch of cities in the United States.

00:39:37.940 --> 00:39:41.320
Building this and wiring it all up and using one of the,

00:39:41.320 --> 00:39:42.560
we use react select here,

00:39:42.560 --> 00:39:44.640
but you can use select two or one of those components.

00:39:44.640 --> 00:39:45.700
It's not trivial.

00:39:45.700 --> 00:39:47.420
You need to also set up the backend.

00:39:47.420 --> 00:39:48.460
You need to set up,

00:39:48.460 --> 00:39:53.480
there's like a few hundred lines of react dedicated just to setting up those,

00:39:53.480 --> 00:39:54.760
those selects correctly.

00:39:55.000 --> 00:39:56.840
And as you'll see in a minute on a form,

00:39:56.840 --> 00:39:57.960
you can add this to a,

00:39:57.960 --> 00:40:00.480
to form with us UI pretty trivially.

00:40:00.480 --> 00:40:01.120
Secondly,

00:40:01.120 --> 00:40:03.380
if you go to the bottom of the page on cities,

00:40:03.380 --> 00:40:05.440
you'll see pagination again,

00:40:05.440 --> 00:40:07.140
not a trivial thing to go and set up.

00:40:07.140 --> 00:40:07.740
If you've got,

00:40:07.740 --> 00:40:10.760
if you're just starting from scratch and you want to show like build an internal

00:40:10.760 --> 00:40:11.080
endpoint,

00:40:11.080 --> 00:40:11.580
for example,

00:40:11.580 --> 00:40:15.820
to show all of your users doing all that pagination and like wiring all that

00:40:15.820 --> 00:40:16.560
up is not trivial,

00:40:16.560 --> 00:40:20.720
but we effectively do the work for you to have that component and do the maths of

00:40:20.720 --> 00:40:22.420
which page we're on and stuff like that.

00:40:22.420 --> 00:40:22.680
Nice.

00:40:22.680 --> 00:40:24.360
I want to like reiterate,

00:40:24.540 --> 00:40:28.480
this is the fast UI is not just designed as a kind of Django admin interface

00:40:28.480 --> 00:40:29.000
alternative.

00:40:29.000 --> 00:40:33.200
We within financing are going to go and use it for UI that we're going to show

00:40:33.200 --> 00:40:33.860
to end users.

00:40:33.860 --> 00:40:37.220
But obviously it also comes into its own when people want to just get something

00:40:37.220 --> 00:40:37.700
up quickly.

00:40:40.100 --> 00:40:42.960
This portion of talk Python to me is brought to you by Sentry,

00:40:42.960 --> 00:40:43.480
you know,

00:40:43.480 --> 00:40:45.280
Sentry for the air monitoring service,

00:40:45.280 --> 00:40:46.940
the one that we use right here at talk Python.

00:40:46.940 --> 00:40:50.720
But this time I want to tell you about a new and free workshop.

00:40:51.420 --> 00:40:55.080
He means the Kraken managing a Python monorepo with Sentry.

00:40:55.080 --> 00:40:57.340
Join Salma Alam Nayor,

00:40:57.340 --> 00:41:00.780
Senior developer advocate at Sentry and David Winterbottom,

00:41:00.780 --> 00:41:06.520
head of engineering at Kraken Technologies for an inside look into how he and his team develop,

00:41:06.520 --> 00:41:07.060
deploy,

00:41:07.060 --> 00:41:13.600
and maintain a rapidly evolving Python monorepo with over 4 million lines of code that powers

00:41:13.600 --> 00:41:15.060
the Kraken utility platform.

00:41:15.540 --> 00:41:16.680
In this workshop,

00:41:16.680 --> 00:41:22.340
David will share how his department of 500 developers who deploy around 200 times a day

00:41:22.340 --> 00:41:24.100
use Sentry to reduce noise,

00:41:24.100 --> 00:41:25.120
prioritize issues,

00:41:25.120 --> 00:41:28.880
and maintain code quality without relying on a dedicated Q&A team.

00:41:28.880 --> 00:41:32.000
You'll learn how to find and fix root causes of crashes,

00:41:32.000 --> 00:41:35.260
ways to prioritize the most urgent crashes and errors,

00:41:35.260 --> 00:41:37.280
and tips to streamline your workflow.

00:41:37.280 --> 00:41:39.080
Join them for free on Tuesday,

00:41:39.080 --> 00:41:40.420
February 27th,

00:41:40.420 --> 00:41:42.140
2024 at 2 a.m.

00:41:42.140 --> 00:41:43.180
Pacific time.

00:41:43.180 --> 00:41:47.660
Just visit talkpython.fm/sentry dash monorepo.

00:41:47.660 --> 00:41:49.820
That link is in your podcast player show notes.

00:41:49.820 --> 00:41:51.040
2 a.m.

00:41:51.040 --> 00:41:52.980
might be a little early here in the U.S.,

00:41:52.980 --> 00:41:55.180
but go ahead and sign up anyway if you're a U.S. listener,

00:41:55.180 --> 00:41:59.380
because I'm sure they'll email you about a follow-up recording as well.

00:41:59.380 --> 00:42:02.300
Thank you to Sentry for supporting this episode.

00:42:02.300 --> 00:42:07.360
If we have a design language or something like that,

00:42:07.360 --> 00:42:08.860
or even using a framework,

00:42:08.860 --> 00:42:09.160
I mean,

00:42:09.160 --> 00:42:09.980
you mentioned Bootstrap,

00:42:09.980 --> 00:42:11.860
but Tailwind or Bulva,

00:42:12.480 --> 00:42:13.480
is that one of the new ones?

00:42:13.480 --> 00:42:13.720
Like,

00:42:13.720 --> 00:42:16.640
if we're working with one of those and we wanted to use this,

00:42:16.640 --> 00:42:17.080
like,

00:42:17.080 --> 00:42:21.200
how easy is it to sort of bring in those elements there?

00:42:21.560 --> 00:42:24.560
So if I show you here on Bootstrap,

00:42:24.560 --> 00:42:26.500
to ask you how we customize it with Bootstrap,

00:42:26.500 --> 00:42:28.880
which is probably the best definition of it.

00:42:28.880 --> 00:42:30.200
So you'll see here,

00:42:30.200 --> 00:42:30.940
this is in the,

00:42:30.940 --> 00:42:31.840
this is the,

00:42:31.840 --> 00:42:32.640
where am I looking?

00:42:32.640 --> 00:42:33.800
This is the pre-built version.

00:42:33.800 --> 00:42:34.180
So this,

00:42:34.180 --> 00:42:37.760
this is obviously the pre-built version of Fast UI you can get,

00:42:37.760 --> 00:42:39.060
but it's actually just,

00:42:39.060 --> 00:42:41.140
it's a very simple app in terms of React.

00:42:41.480 --> 00:42:42.420
this app has one,

00:42:42.420 --> 00:42:42.800
well,

00:42:42.800 --> 00:42:43.380
two components.

00:42:43.380 --> 00:42:43.880
It has a div,

00:42:43.880 --> 00:42:46.040
which contains the Fast UI component.

00:42:46.040 --> 00:42:48.040
And then we customize it in a bunch of ways.

00:42:48.040 --> 00:42:50.460
We have a like component that we render for not found.

00:42:50.460 --> 00:42:53.060
We have a component we render for spinner and for transitioning.

00:42:53.340 --> 00:42:56.040
but then these are the two that really matter where we can customize the

00:42:56.040 --> 00:43:00.060
classes and we can customize how we render certain components.

00:43:00.060 --> 00:43:03.200
So if we come in here to have this function from Bootstrap,

00:43:03.200 --> 00:43:04.880
which is how we customize the classes,

00:43:04.880 --> 00:43:06.500
you'll see that at its core,

00:43:06.500 --> 00:43:07.720
it's just this big old switch.

00:43:07.720 --> 00:43:09.980
So this is all TypeScript,

00:43:09.980 --> 00:43:13.500
like type safe because types are very powerful in TypeScript,

00:43:13.500 --> 00:43:16.020
but like all of the props will have this type key.

00:43:16.020 --> 00:43:17.140
As I showed you earlier,

00:43:17.140 --> 00:43:21.320
when we were looking at the Python code and all the different things.

00:43:21.320 --> 00:43:21.500
Yeah.

00:43:21.500 --> 00:43:22.240
Based on the switch,

00:43:22.240 --> 00:43:22.920
we just go through,

00:43:23.040 --> 00:43:26.240
and this is all just like defining the classes we want for all of the

00:43:26.240 --> 00:43:27.500
different components.

00:43:27.500 --> 00:43:29.780
Some of them depending on the exact state of the component.

00:43:29.780 --> 00:43:31.660
So all of these form inputs,

00:43:31.660 --> 00:43:35.780
we customize them depending on which type they are and on which mode we're in,

00:43:35.780 --> 00:43:36.180
et cetera,

00:43:36.180 --> 00:43:36.520
et cetera.

00:43:36.520 --> 00:43:37.000
But it's,

00:43:37.000 --> 00:43:38.380
it's all very mechanical,

00:43:38.380 --> 00:43:41.860
just like laying out the classes we need for each and each individual case.

00:43:41.860 --> 00:43:44.260
And then we have the other way of customizing it,

00:43:44.260 --> 00:43:46.140
which is to use custom components.

00:43:46.140 --> 00:43:49.020
We basically for three in particular components,

00:43:49.020 --> 00:43:49.660
nav bar,

00:43:49.660 --> 00:43:51.400
modal and pagination,

00:43:51.400 --> 00:43:52.980
we define our own,

00:43:53.000 --> 00:43:54.580
custom react components.

00:43:54.580 --> 00:44:00.020
So here's the one for nav bar where we use a bunch of bootstrap types to render a bootstrap nav bar.

00:44:00.020 --> 00:44:08.140
So you can basically create a react component that has all the settings necessary to create a nav bar in tailwind or whatever.

00:44:08.140 --> 00:44:08.700
Right.

00:44:08.960 --> 00:44:10.300
And then just plug that stuff in.

00:44:10.300 --> 00:44:10.540
So,

00:44:10.540 --> 00:44:11.820
so if you wanted to use tailwind,

00:44:11.820 --> 00:44:13.280
what's this like 20,

00:44:13.280 --> 00:44:18.060
it's like a hundred lines of code to define all of the classes and it's pretty mechanical code,

00:44:18.060 --> 00:44:18.260
right?

00:44:18.520 --> 00:44:19.660
So it would be,

00:44:19.660 --> 00:44:20.840
it wouldn't be hard at all to go and use tailwind,

00:44:20.840 --> 00:44:21.960
it wouldn't be hard at all to go and use tailwind,

00:44:21.960 --> 00:44:22.980
tailwind CSS.

00:44:22.980 --> 00:44:26.220
And then you might want to define a few of your components specifically.

00:44:26.220 --> 00:44:26.600
Yeah.

00:44:26.600 --> 00:44:27.560
But actually modal,

00:44:27.560 --> 00:44:27.580
modal,

00:44:27.580 --> 00:44:33.380
I 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.

00:44:33.380 --> 00:44:33.720
Right.

00:44:33.720 --> 00:44:34.540
JavaScript.

00:44:34.540 --> 00:44:35.920
The page says,

00:44:35.920 --> 00:44:36.420
it's like,

00:44:36.420 --> 00:44:36.700
oh,

00:44:36.700 --> 00:44:37.020
no,

00:44:37.020 --> 00:44:38.820
the page doesn't say this isn't going to work.

00:44:38.820 --> 00:44:39.080
Yeah.

00:44:39.200 --> 00:44:39.720
So,

00:44:39.720 --> 00:44:39.880
yeah,

00:44:39.880 --> 00:44:46.640
I 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.

00:44:46.640 --> 00:44:46.820
Right.

00:44:46.820 --> 00:44:49.820
Those are really like kind of pluggable or extensible.

00:44:49.820 --> 00:44:50.940
So you don't have to,

00:44:50.940 --> 00:44:51.420
you know,

00:44:51.420 --> 00:44:53.080
get in and know too much about it.

00:44:53.080 --> 00:44:57.900
You just plug in the class name generator and the renderer for a specific one.

00:44:57.900 --> 00:44:58.460
And so,

00:44:58.460 --> 00:44:59.040
yeah,

00:44:59.040 --> 00:45:00.080
and all of the types,

00:45:00.080 --> 00:45:01.120
it's all typescripted.

00:45:01.120 --> 00:45:01.420
So you,

00:45:01.420 --> 00:45:03.500
the type should do a lot of help telling you what,

00:45:03.500 --> 00:45:04.460
what you can implement.

00:45:04.460 --> 00:45:06.660
The last thing I'll show you is,

00:45:06.660 --> 00:45:07.140
yeah,

00:45:07.140 --> 00:45:09.040
so here in the default build,

00:45:09.040 --> 00:45:09.660
as I said,

00:45:09.660 --> 00:45:09.960
we,

00:45:09.960 --> 00:45:12.880
our custom render function is not just a bootstrap one.

00:45:12.880 --> 00:45:15.340
We do one special thing,

00:45:15.340 --> 00:45:16.780
which is where we,

00:45:16.780 --> 00:45:18.380
we have this idea of a custom component,

00:45:18.380 --> 00:45:21.160
which basically all it has is a subtype,

00:45:21.160 --> 00:45:24.340
which basically you should use to render it however you like.

00:45:24.340 --> 00:45:25.160
So in our case,

00:45:25.160 --> 00:45:26.340
we hit take custom.

00:45:26.340 --> 00:45:29.060
And if the subtype is cow say,

00:45:29.060 --> 00:45:31.760
we render that as a particular block,

00:45:31.760 --> 00:45:32.820
like use this,

00:45:32.820 --> 00:45:33.880
this component here.

00:45:33.880 --> 00:45:35.480
And we print out the cow says,

00:45:35.480 --> 00:45:37.240
whatever it was that the input was from the server.

00:45:37.540 --> 00:45:39.540
And otherwise we just go back to using the bootstrap render.

00:45:39.540 --> 00:45:40.820
And so if you look at,

00:45:40.820 --> 00:45:42.420
look at that component here.

00:45:42.420 --> 00:45:42.880
Yeah.

00:45:42.880 --> 00:45:46.740
We've got this like slightly silly example of a custom component of cow say,

00:45:46.740 --> 00:45:47.680
saying something.

00:45:47.680 --> 00:45:47.940
Oh,

00:45:47.940 --> 00:45:48.360
that's fun.

00:45:48.360 --> 00:45:49.840
But yeah,

00:45:49.840 --> 00:45:51.480
it shouldn't be too difficult to customize.

00:45:51.480 --> 00:45:54.280
And then even if you're customizing to go back to using bootstrap for,

00:45:54.280 --> 00:45:55.880
for the fallback case of everything else.

00:45:55.960 --> 00:45:56.220
Okay.

00:45:56.220 --> 00:46:01.080
So you could almost just for one section that has to be really specialized to some custom,

00:46:01.080 --> 00:46:02.760
but otherwise just lean on a framework.

00:46:02.760 --> 00:46:03.040
Yeah.

00:46:03.040 --> 00:46:03.300
Okay.

00:46:03.300 --> 00:46:03.820
Yeah.

00:46:03.820 --> 00:46:07.600
This looks like something that one person could take one for the team,

00:46:07.600 --> 00:46:10.780
create a tailwind or a whatever generator,

00:46:10.780 --> 00:46:12.020
class name generator,

00:46:12.020 --> 00:46:16.580
and then put that as either a contribution or put it up on GitHub.

00:46:16.580 --> 00:46:17.380
And then you just,

00:46:17.380 --> 00:46:18.520
you're kind of good to go.

00:46:18.680 --> 00:46:18.800
Yeah.

00:46:18.800 --> 00:46:19.380
I think we might,

00:46:19.380 --> 00:46:20.360
we might actually do it.

00:46:20.360 --> 00:46:20.580
We're,

00:46:20.580 --> 00:46:23.100
we're using tailwind and radix within Pydantic.

00:46:23.100 --> 00:46:26.840
So I suspect our front end guys will at some point get annoyed with my use of bootstrap

00:46:26.840 --> 00:46:29.140
and go off and go and change it.

00:46:29.140 --> 00:46:33.060
One of the reasons I use bootstrap is that because bootstrap is completely customized via

00:46:33.060 --> 00:46:37.000
SCSS and there's SCSS compilers for Python.

00:46:37.000 --> 00:46:38.080
We have the,

00:46:38.080 --> 00:46:42.140
at least the possibility in future to allow you to customize the complete look and feel of your

00:46:42.140 --> 00:46:44.100
app without ever having to touch npm.

00:46:44.100 --> 00:46:48.240
Cause you just go change basically the color definitions as we do here.

00:46:48.380 --> 00:46:48.580
So,

00:46:48.580 --> 00:46:49.380
so the,

00:46:49.380 --> 00:46:51.220
the default version of,

00:46:51.220 --> 00:46:51.680
uh,

00:46:51.680 --> 00:46:53.400
maybe I can even change it here and as it's running,

00:46:53.400 --> 00:46:53.860
it'll change.

00:46:53.860 --> 00:46:55.040
But if I hear you see,

00:46:55.040 --> 00:46:56.620
I've set the primary color to be black.

00:46:56.620 --> 00:47:00.000
And so you'll see the buttons here are all rendered as black.

00:47:00.000 --> 00:47:01.920
If I were to change it,

00:47:01.920 --> 00:47:03.140
I haven't tried this for a bit,

00:47:03.140 --> 00:47:05.600
so I hope it works commented out primary.

00:47:05.600 --> 00:47:08.820
You'll see that the primary,

00:47:08.820 --> 00:47:09.320
uh,

00:47:09.320 --> 00:47:11.300
which is the bootstrap primary button.

00:47:11.300 --> 00:47:12.760
If I changed the,

00:47:12.760 --> 00:47:14.560
I got rid of the default font.

00:47:14.560 --> 00:47:15.460
You would see,

00:47:15.460 --> 00:47:17.340
we went back to whatever the other font was.

00:47:17.560 --> 00:47:20.780
So there's a world in future where we allow you to customize the look and feel

00:47:20.780 --> 00:47:22.820
even within bootstrap from Python code.

00:47:22.820 --> 00:47:23.060
Yeah.

00:47:23.060 --> 00:47:25.760
Tell people maybe who don't know what SCSS is.

00:47:25.760 --> 00:47:27.100
They probably know what CSS is.

00:47:27.100 --> 00:47:29.060
It's generally referred to as SAS,

00:47:29.060 --> 00:47:31.120
which is S A S S S,

00:47:31.120 --> 00:47:32.060
which was,

00:47:32.060 --> 00:47:32.440
is,

00:47:32.440 --> 00:47:32.960
is basically,

00:47:32.960 --> 00:47:33.520
uh,

00:47:33.520 --> 00:47:35.120
a more powerful version of,

00:47:35.120 --> 00:47:36.620
of CSS where you can.

00:47:36.620 --> 00:47:37.440
SAS and less.

00:47:37.440 --> 00:47:38.320
Those were the two.

00:47:38.320 --> 00:47:38.640
Yeah.

00:47:38.640 --> 00:47:39.500
there was SAS and less.

00:47:39.500 --> 00:47:41.280
And then we kind of settled on SAS,

00:47:41.280 --> 00:47:42.600
but then we had a CSS,

00:47:42.600 --> 00:47:46.060
which is SAS with more CSS syntax.

00:47:46.060 --> 00:47:49.460
It's a way to like do slightly more powerful things in,

00:47:49.460 --> 00:47:53.860
in CSS and minify it and have stuff like variables for,

00:47:53.860 --> 00:47:55.420
they were available in CSS and,

00:47:55.420 --> 00:47:56.740
and defaults.

00:47:56.740 --> 00:47:59.640
And even you can do weird stuff like map functions.

00:47:59.640 --> 00:48:01.620
And they use very heavily in bootstrap.

00:48:01.620 --> 00:48:04.940
But the nice bit is because the compiler is written in C.

00:48:04.940 --> 00:48:06.440
There's Libsass in Python,

00:48:06.440 --> 00:48:11.520
where you can get kind of a front end customization without needing the whole of

00:48:11.520 --> 00:48:12.680
node and the,

00:48:12.680 --> 00:48:14.920
the whole dog and pony show of front end development.

00:48:15.340 --> 00:48:15.540
Yeah.

00:48:15.540 --> 00:48:15.980
Excellent.

00:48:15.980 --> 00:48:17.360
It's got a lot of legs.

00:48:17.360 --> 00:48:19.800
So when I saw this and I saw,

00:48:19.800 --> 00:48:20.020
okay,

00:48:20.020 --> 00:48:20.800
this is so for,

00:48:20.800 --> 00:48:22.820
for web apps and it's kind of got this,

00:48:22.820 --> 00:48:27.200
this Python code running that defines the backend and it's got the UI and it's all

00:48:27.200 --> 00:48:28.580
a little self-contained.

00:48:28.580 --> 00:48:30.760
One of the thoughts I had was,

00:48:30.760 --> 00:48:32.720
wouldn't it be neat if there was a,

00:48:32.720 --> 00:48:36.680
got a little bundler type of thing that made this into an electron app?

00:48:36.680 --> 00:48:37.700
Would this be possible?

00:48:37.700 --> 00:48:40.080
Can we get something that you could send out?

00:48:40.080 --> 00:48:42.380
Or is this really just going to be intended to be,

00:48:42.380 --> 00:48:42.720
you know,

00:48:42.720 --> 00:48:45.680
kind of a friend of Django type of thing?

00:48:45.680 --> 00:48:48.340
I have not used electron for a very long time,

00:48:48.340 --> 00:48:49.820
so I don't pretend to be an expert.

00:48:49.820 --> 00:48:54.540
What I will say is that unlike some of the other UI libraries,

00:48:54.540 --> 00:48:58.400
we're not trying to do clever things with web sockets and do all of the,

00:48:58.400 --> 00:49:02.260
all of the rendering requiring duplex communication between the client and the

00:49:02.260 --> 00:49:02.480
server.

00:49:02.480 --> 00:49:03.500
It's pretty simple.

00:49:03.500 --> 00:49:07.520
It's like make a request and the Jason contains some information about how to

00:49:07.520 --> 00:49:07.940
render it.

00:49:07.940 --> 00:49:09.840
And then the front end goes off and renders it.

00:49:09.840 --> 00:49:10.860
So it's the result.

00:49:10.980 --> 00:49:12.400
What you get when you finish is very,

00:49:12.400 --> 00:49:14.540
in terms of a networking point of view,

00:49:14.540 --> 00:49:15.160
very,

00:49:15.160 --> 00:49:16.000
very simple,

00:49:16.000 --> 00:49:16.900
very conventional.

00:49:16.900 --> 00:49:19.180
It's like make an HTTP request,

00:49:19.180 --> 00:49:19.860
get back Jason,

00:49:19.860 --> 00:49:21.620
JavaScript knows how to render it.

00:49:21.620 --> 00:49:24.020
And so I don't see why it shouldn't,

00:49:24.020 --> 00:49:25.780
shouldn't work in electron.

00:49:25.780 --> 00:49:28.700
There's even the world in which we don't need the whole of electron.

00:49:28.700 --> 00:49:29.280
And we could,

00:49:29.280 --> 00:49:32.360
someone could go and build fast UI components for,

00:49:32.360 --> 00:49:33.540
for whatever native library.

00:49:33.540 --> 00:49:36.940
And we could get like native apps running that are based on fast drive.

00:49:36.940 --> 00:49:38.840
not saying that's necessarily a good idea,

00:49:38.840 --> 00:49:40.720
but like those possibilities exist.

00:49:40.720 --> 00:49:41.420
It is.

00:49:41.420 --> 00:49:42.160
It does exist.

00:49:42.160 --> 00:49:42.460
Okay.

00:49:42.460 --> 00:49:42.980
Yeah.

00:49:42.980 --> 00:49:43.220
Yeah.

00:49:43.220 --> 00:49:43.780
Very interesting.

00:49:43.780 --> 00:49:46.140
Another thing that is convention,

00:49:46.140 --> 00:49:46.760
I suppose.

00:49:46.760 --> 00:49:49.480
I'll see if I can pull it out here is the UI.

00:49:49.480 --> 00:49:51.380
A lot of times you'll have either just slash,

00:49:51.380 --> 00:49:54.040
you'll have slash users,

00:49:54.540 --> 00:49:56.500
but then you'll have an API that backs it.

00:49:56.500 --> 00:49:59.320
And there's this convention that if it's in the URL,

00:49:59.320 --> 00:50:00.960
if you have slash API slash,

00:50:00.960 --> 00:50:01.600
in this example,

00:50:01.600 --> 00:50:02.820
we were talking about before,

00:50:02.820 --> 00:50:04.140
it's like slash table slash cities.

00:50:04.140 --> 00:50:06.480
If you say API slash table slash,

00:50:06.480 --> 00:50:07.700
that's the data endpoint.

00:50:07.700 --> 00:50:09.400
And then if you drop the API,

00:50:09.400 --> 00:50:13.540
that's the front end that then turns around and calls the backend with the API

00:50:13.540 --> 00:50:14.000
inserted.

00:50:14.000 --> 00:50:14.320
Right.

00:50:14.320 --> 00:50:15.960
You want to talk about that convention a little bit?

00:50:15.960 --> 00:50:17.740
So people kind of see where that's going.

00:50:17.740 --> 00:50:18.640
So that's how,

00:50:18.640 --> 00:50:20.580
how I've set it up in the default app.

00:50:20.580 --> 00:50:21.360
It doesn't,

00:50:21.360 --> 00:50:22.420
you don't have to do it like that.

00:50:22.460 --> 00:50:26.440
And I think we're using a separate subdomain to avoid like path-based

00:50:26.440 --> 00:50:28.140
routing and all that fun.

00:50:28.140 --> 00:50:28.580
But yeah,

00:50:28.580 --> 00:50:28.840
the,

00:50:28.840 --> 00:50:29.000
the,

00:50:29.000 --> 00:50:32.720
the principle that the default simplest way of basically doing a,

00:50:32.720 --> 00:50:33.580
excuse me,

00:50:33.580 --> 00:50:34.880
a calculation to go from,

00:50:34.880 --> 00:50:35.620
I've got a URL.

00:50:35.620 --> 00:50:37.060
How do I get the data for it?

00:50:37.060 --> 00:50:38.380
Is as I said earlier,

00:50:38.380 --> 00:50:39.960
basically prepend slash API.

00:50:39.960 --> 00:50:43.780
So maybe a more general way to think about it is for every page,

00:50:43.780 --> 00:50:47.760
there is an endpoint that is a FastAPI endpoint or a pair of them.

00:50:47.760 --> 00:50:52.360
Maybe even one returns the HTML front end stuff that makes it run.

00:50:52.360 --> 00:50:54.940
It talks around and goes back to itself.

00:50:54.940 --> 00:50:55.180
Right.

00:50:55.180 --> 00:50:55.400
Yeah.

00:50:55.400 --> 00:50:57.620
So what we have in the default app here,

00:50:57.620 --> 00:51:00.380
what I would generally recommend is where are we?

00:51:00.380 --> 00:51:05.020
We have a bunch of routers that connect and do all of the API stuff.

00:51:05.020 --> 00:51:06.280
And I've just been implementing all,

00:51:06.280 --> 00:51:07.620
which I can show you in a minute,

00:51:07.620 --> 00:51:08.580
but that's not available.

00:51:08.580 --> 00:51:09.680
There's a PR for it,

00:51:09.680 --> 00:51:11.540
but it's not available in the demo you're looking at.

00:51:11.760 --> 00:51:14.740
But then we have this like basically catch all endpoint,

00:51:14.740 --> 00:51:16.200
which if nothing else has been hit,

00:51:16.200 --> 00:51:18.760
will render the standard HTML.

00:51:18.760 --> 00:51:23.040
And one of the nice things is that the Python library gives you this prebuilt HTML,

00:51:23.040 --> 00:51:24.640
which will basically render you some,

00:51:24.640 --> 00:51:26.580
render you the HTML that you'll get.

00:51:26.580 --> 00:51:27.200
If you,

00:51:27.200 --> 00:51:29.740
I went here and I view page source,

00:51:29.740 --> 00:51:30.400
you'll see.

00:51:30.400 --> 00:51:31.340
You just go to home page, yeah.

00:51:31.340 --> 00:51:31.880
Returning.

00:51:31.880 --> 00:51:32.540
Well,

00:51:32.540 --> 00:51:32.880
yeah.

00:51:32.880 --> 00:51:33.540
In this particular,

00:51:33.540 --> 00:51:34.840
if I went to 8,000,

00:51:34.840 --> 00:51:36.780
then it wouldn't be messed up by Vite.

00:51:36.880 --> 00:51:38.240
You just get this very simple HTML,

00:51:38.240 --> 00:51:39.480
which in turn renders the app.

00:51:39.480 --> 00:51:40.140
So yeah,

00:51:40.140 --> 00:51:41.100
there's effectively,

00:51:41.100 --> 00:51:41.440
you're right.

00:51:41.440 --> 00:51:41.880
There's two,

00:51:41.880 --> 00:51:42.260
there's two,

00:51:42.260 --> 00:51:44.080
there's like matching endpoints for,

00:51:44.080 --> 00:51:46.960
for every view you might want to have one to get,

00:51:46.960 --> 00:51:48.000
to return the Jason,

00:51:48.000 --> 00:51:48.660
the one to,

00:51:48.660 --> 00:51:49.580
to render the HTML.

00:51:49.580 --> 00:51:50.500
But you don't write,

00:51:50.500 --> 00:51:51.460
you don't write them both,

00:51:51.460 --> 00:51:51.660
right?

00:51:51.660 --> 00:51:56.880
You write the API one and then fast UI magically turns out into UI.

00:51:56.880 --> 00:51:57.200
Right.

00:51:57.200 --> 00:51:57.640
And whatever,

00:51:57.640 --> 00:51:58.560
and this would,

00:51:58.560 --> 00:51:59.660
all of most of this,

00:51:59.660 --> 00:52:02.700
with the exception of the form submission would all just work out the box with,

00:52:02.700 --> 00:52:04.440
with any Python web framework.

00:52:04.560 --> 00:52:07.340
You just need to produce your financing model,

00:52:07.340 --> 00:52:10.120
dump it to Jason and return that in a response.

00:52:10.120 --> 00:52:13.080
But one of the really nice things about the,

00:52:13.080 --> 00:52:18.380
this being the like actual data existing in Jason is that writing a test.

00:52:18.380 --> 00:52:19.400
There's quite a lot here,

00:52:19.400 --> 00:52:20.780
but you'll see most of it is,

00:52:20.780 --> 00:52:21.420
is markdown.

00:52:21.420 --> 00:52:26.360
So writing a test that our views contain what we expect them to is massively easier

00:52:26.360 --> 00:52:27.580
when we're testing against Jason,

00:52:27.580 --> 00:52:30.660
which we can convert to Python objects and tests than it would be.

00:52:30.660 --> 00:52:31.940
If we've got an HTML page,

00:52:31.980 --> 00:52:35.740
we're running a bunch of regexes for does this page contain the user's name?

00:52:35.740 --> 00:52:37.300
Does it contain the word logout?

00:52:37.300 --> 00:52:37.680
Blah,

00:52:37.680 --> 00:52:37.800
blah,

00:52:37.800 --> 00:52:38.040
blah.

00:52:38.040 --> 00:52:38.420
Yeah.

00:52:38.420 --> 00:52:42.660
By a right type of things or those types of tests.

00:52:42.660 --> 00:52:42.880
Sure.

00:52:42.880 --> 00:52:43.360
Oh yeah.

00:52:43.360 --> 00:52:44.180
Even worse.

00:52:44.180 --> 00:52:45.000
You end up with like play,

00:52:45.000 --> 00:52:45.320
right.

00:52:45.320 --> 00:52:46.080
And like play,

00:52:46.080 --> 00:52:46.240
right.

00:52:46.240 --> 00:52:49.040
That's an image of it and see if the image looks like the image used to look.

00:52:49.040 --> 00:52:49.700
And yeah,

00:52:49.700 --> 00:52:51.880
things I don't want to have to build.

00:52:51.880 --> 00:52:52.180
I mean,

00:52:52.180 --> 00:52:53.340
they have to happen occasionally,

00:52:53.500 --> 00:52:54.200
but like we're,

00:52:54.200 --> 00:52:57.780
and ironically we'll probably end up with them in fast UI to like even more

00:52:57.780 --> 00:52:59.420
certainty that our components work correctly,

00:52:59.420 --> 00:53:02.460
but hopefully that thereby avoid everyone else having to,

00:53:02.460 --> 00:53:03.400
having to go and build.

00:53:03.400 --> 00:53:08.820
Is there any concern that maybe there's unintended APIs in the sense that like

00:53:08.820 --> 00:53:09.720
all of this stuff,

00:53:09.720 --> 00:53:13.340
I'm sure this is probably true for pretty much any react site,

00:53:13.540 --> 00:53:16.700
but like a lot of the page is available also as an API,

00:53:16.700 --> 00:53:18.420
even if you don't intend it to be an API,

00:53:18.420 --> 00:53:19.360
like what's.

00:53:19.360 --> 00:53:19.720
Yeah.

00:53:19.720 --> 00:53:21.580
That's a limitation of any,

00:53:21.580 --> 00:53:22.160
I mean,

00:53:22.160 --> 00:53:24.580
in some ways the data will be slightly less nice to.

00:53:24.580 --> 00:53:24.980
Yeah.

00:53:24.980 --> 00:53:25.280
You're right.

00:53:25.280 --> 00:53:29.360
If you're a company that give people foreign exchange rates and you want them

00:53:29.360 --> 00:53:30.620
to always come to your site,

00:53:30.620 --> 00:53:32.340
you obviously can't render that with,

00:53:32.340 --> 00:53:35.000
with react because there's going to be a Jason endpoint where someone can just

00:53:35.000 --> 00:53:37.200
go scrape your exchange rates or whatever else.

00:53:37.200 --> 00:53:37.680
Right.

00:53:37.680 --> 00:53:41.700
But you can still do session based off and say you have to log in to do it.

00:53:41.700 --> 00:53:42.020
Right.

00:53:42.020 --> 00:53:43.660
It's not just that it's public.

00:53:43.660 --> 00:53:44.500
It just,

00:53:44.500 --> 00:53:46.160
there's always a Jason version,

00:53:46.160 --> 00:53:47.180
but honestly,

00:53:47.180 --> 00:53:49.980
there's so many interesting ways to pull data out of HTML.

00:53:49.980 --> 00:53:50.340
Like,

00:53:50.340 --> 00:53:50.600
yeah.

00:53:50.600 --> 00:53:52.400
If someone's that valuable,

00:53:52.400 --> 00:53:53.480
someone will do it anyway.

00:53:53.480 --> 00:53:55.020
I also think that like,

00:53:55.020 --> 00:53:55.820
in theory,

00:53:55.820 --> 00:53:59.560
if your options are build pure react or do this,

00:53:59.560 --> 00:54:00.680
and this has the,

00:54:00.680 --> 00:54:00.900
the,

00:54:00.900 --> 00:54:01.160
like,

00:54:01.160 --> 00:54:01.760
as I say,

00:54:01.760 --> 00:54:03.100
there's the realistic chance.

00:54:03.100 --> 00:54:06.620
Someone's going to come along and implement a fast UI front end that,

00:54:06.620 --> 00:54:07.560
that renders HTML.

00:54:07.560 --> 00:54:08.060
And then,

00:54:08.060 --> 00:54:09.760
and then you don't have to expose your,

00:54:10.240 --> 00:54:12.120
expose those Jason endpoints at all.

00:54:12.120 --> 00:54:12.620
And you could,

00:54:12.620 --> 00:54:14.440
you could return HTML from your server.

00:54:14.440 --> 00:54:16.320
We just haven't got around to building it yet.

00:54:16.320 --> 00:54:16.580
Yeah.

00:54:16.580 --> 00:54:20.100
I guess you could maybe do some kind of server side rendering potentially as well.

00:54:20.100 --> 00:54:20.600
Exactly.

00:54:20.600 --> 00:54:21.200
That's what I mean.

00:54:21.200 --> 00:54:22.740
Whether it's Python server side rendering,

00:54:22.740 --> 00:54:24.760
or whether it's JavaScript server side rendering,

00:54:24.760 --> 00:54:25.880
or whether it's edge rendering.

00:54:25.880 --> 00:54:30.740
I've tried to build a sort of edge rendering thing in Cloudflare years ago using Rust.

00:54:30.740 --> 00:54:31.920
And for a bunch of reasons,

00:54:31.920 --> 00:54:32.560
it didn't quite work,

00:54:32.560 --> 00:54:34.900
but there's real possibility of doing like,

00:54:34.900 --> 00:54:35.180
yeah,

00:54:35.180 --> 00:54:36.560
any number of different things in that direction.

00:54:36.560 --> 00:54:37.120
That's interesting.

00:54:37.120 --> 00:54:41.100
Some of the CDNs have pretty dynamic stuff right at the edge,

00:54:41.100 --> 00:54:42.860
where you can sort of put your last bit of code.

00:54:42.860 --> 00:54:44.560
I haven't done anything with that.

00:54:44.560 --> 00:54:46.100
That's kind of what Remix is doing,

00:54:46.100 --> 00:54:48.100
and Next.js to a lesser extent.

00:54:48.460 --> 00:54:49.020
But again,

00:54:49.020 --> 00:54:49.660
in theory,

00:54:49.660 --> 00:54:50.620
I mean,

00:54:50.620 --> 00:54:52.000
maybe I'm overblowing it,

00:54:52.000 --> 00:54:54.220
and Fast UI will remain what it is now.

00:54:54.220 --> 00:54:54.600
But like,

00:54:54.600 --> 00:54:55.200
in theory,

00:54:55.200 --> 00:55:00.600
we've set up this language of different components that hopefully is,

00:55:00.600 --> 00:55:02.580
whilst by no means universal,

00:55:02.580 --> 00:55:05.960
complete enough that you can build lots of common user interfaces with it.

00:55:05.960 --> 00:55:06.480
And then,

00:55:06.480 --> 00:55:07.780
if it really gains adoption,

00:55:07.780 --> 00:55:10.680
then people can go and build new backends and new frontends,

00:55:10.680 --> 00:55:11.300
and they all,

00:55:11.300 --> 00:55:11.900
in theory,

00:55:11.900 --> 00:55:13.840
should be able to mix and match with each other.

00:55:13.840 --> 00:55:14.900
We'll see if that happens.

00:55:14.900 --> 00:55:15.220
Yeah.

00:55:15.220 --> 00:55:16.260
And widgets too,

00:55:16.260 --> 00:55:16.560
right?

00:55:16.560 --> 00:55:17.000
Kind of like,

00:55:17.080 --> 00:55:21.060
see a Tailwind UI create a paid thing for higher order widgets,

00:55:21.060 --> 00:55:21.800
potentially.

00:55:21.800 --> 00:55:24.120
Just being React already makes that,

00:55:24.120 --> 00:55:25.200
that probably exists,

00:55:25.200 --> 00:55:25.880
and I just don't know.

00:55:25.880 --> 00:55:30.200
And there's been a number of issues of people wanting to render existing,

00:55:30.200 --> 00:55:33.100
basically build extensions to Fast UI to render their widgets.

00:55:33.100 --> 00:55:36.100
I think we will probably support the rep for HTML,

00:55:36.100 --> 00:55:39.180
that things like Pandas data frames already returned,

00:55:39.180 --> 00:55:39.880
so that you could,

00:55:39.880 --> 00:55:40.240
for example,

00:55:40.240 --> 00:55:41.160
return a data frame,

00:55:41.160 --> 00:55:42.340
and it might not be pretty,

00:55:42.340 --> 00:55:44.420
but you'll get something coming up as HTML,

00:55:44.420 --> 00:55:44.780
and,

00:55:44.780 --> 00:55:45.220
you know,

00:55:45.220 --> 00:55:46.120
start ugly,

00:55:46.220 --> 00:55:49.380
and then move on to doing those things in an even more powerful way.

00:55:49.380 --> 00:55:49.620
Sure.

00:55:49.620 --> 00:55:50.020
Yeah,

00:55:50.020 --> 00:55:51.460
I didn't even think of the data science side,

00:55:51.460 --> 00:55:57.020
but there's probably a lot of cool dashboard widgets connected to pandas and pullers that are potential out there.

00:55:57.020 --> 00:55:57.280
Yeah.

00:55:57.280 --> 00:56:00.760
And charts and visualizing data is something Pydantic is interested in.

00:56:00.760 --> 00:56:06.600
There's no reason why a lot of them couldn't be implemented as Fast UI components and then displayed.

00:56:06.780 --> 00:56:07.000
Okay.

00:56:07.000 --> 00:56:09.440
We are running pretty short on time.

00:56:09.440 --> 00:56:13.580
I feel like we should probably bring a little more Pydantic to the side.

00:56:13.580 --> 00:56:15.340
Just talk real quickly about forms,

00:56:15.340 --> 00:56:15.640
right?

00:56:15.640 --> 00:56:16.180
What do you think?

00:56:16.180 --> 00:56:16.500
Yeah,

00:56:16.500 --> 00:56:16.840
absolutely.

00:56:16.840 --> 00:56:17.960
So if you,

00:56:17.960 --> 00:56:18.900
probably easiest,

00:56:18.900 --> 00:56:19.520
if you share,

00:56:19.520 --> 00:56:20.060
let me see,

00:56:20.060 --> 00:56:20.800
share my screen.

00:56:20.800 --> 00:56:21.640
I'll do it from here,

00:56:21.640 --> 00:56:22.380
because I can also,

00:56:22.380 --> 00:56:23.560
it's like,

00:56:23.760 --> 00:56:25.200
you can show more behind the scenes.

00:56:25.200 --> 00:56:25.500
Yeah,

00:56:25.500 --> 00:56:25.720
yeah,

00:56:25.720 --> 00:56:25.980
yeah.

00:56:25.980 --> 00:56:27.680
It's probably most interesting if we,

00:56:27.680 --> 00:56:28.600
if we look at the,

00:56:28.600 --> 00:56:31.420
how the form is implemented in the code first,

00:56:31.420 --> 00:56:32.400
and then we look at what that,

00:56:32.400 --> 00:56:33.440
what that means for the UI.

00:56:33.440 --> 00:56:34.200
So this is the,

00:56:34.200 --> 00:56:35.820
the login form that Michael,

00:56:35.820 --> 00:56:37.220
you were just showing here that I can show,

00:56:37.220 --> 00:56:37.820
which is just,

00:56:37.820 --> 00:56:39.740
so there's a login form with an email address,

00:56:39.740 --> 00:56:40.220
password,

00:56:40.220 --> 00:56:41.320
some validation,

00:56:41.320 --> 00:56:42.720
basically like that.

00:56:42.720 --> 00:56:42.840
Yeah.

00:56:43.040 --> 00:56:43.980
powered entirely by,

00:56:43.980 --> 00:56:44.380
again,

00:56:44.380 --> 00:56:45.920
a completely vanilla Pydantic model.

00:56:45.920 --> 00:56:50.040
And the way that we return that is we return three things,

00:56:50.040 --> 00:56:51.020
heading,

00:56:51.020 --> 00:56:53.940
which is like just telling the person what we're looking at here in the demo.

00:56:53.940 --> 00:56:55.480
And then this third thing is the,

00:56:55.480 --> 00:56:56.520
it's the interesting bit where again,

00:56:56.520 --> 00:56:59.020
actually the model form is again,

00:56:59.020 --> 00:57:00.660
generic around the Pydantic model.

00:57:00.660 --> 00:57:02.240
And then it takes one other argument,

00:57:02.240 --> 00:57:03.340
which is the submit URL.

00:57:03.340 --> 00:57:04.820
And that's enough information.

00:57:04.820 --> 00:57:05.260
Right.

00:57:05.260 --> 00:57:10.740
So what you're returning as part of that hierarchy in Python is a model form

00:57:10.740 --> 00:57:12.580
and you give it a Pydantic model.

00:57:12.580 --> 00:57:15.100
And so it looks at the Pydantic class and says,

00:57:15.100 --> 00:57:19.480
we're going to create like an email address and a password field and so on.

00:57:19.480 --> 00:57:19.680
Right.

00:57:19.680 --> 00:57:20.340
Exactly that.

00:57:20.340 --> 00:57:20.920
Awesome.

00:57:20.920 --> 00:57:21.300
Okay.

00:57:21.300 --> 00:57:23.620
And then when you submit that form,

00:57:23.620 --> 00:57:25.760
it's submitted as form data.

00:57:25.760 --> 00:57:27.000
So is it not as,

00:57:27.000 --> 00:57:28.000
as JSON data,

00:57:28.000 --> 00:57:30.220
but as a vanilla HTML form,

00:57:30.220 --> 00:57:32.600
a standard form post type of thing.

00:57:32.600 --> 00:57:33.420
Post form.

00:57:33.420 --> 00:57:34.600
And then we have this,

00:57:34.600 --> 00:57:37.320
it's this syntax is definitely slightly funky here,

00:57:37.320 --> 00:57:37.580
but,

00:57:37.580 --> 00:57:38.940
but it's how we do it in fast.

00:57:38.940 --> 00:57:39.860
You are a FastAPI.

00:57:39.860 --> 00:57:41.240
We have form,

00:57:41.360 --> 00:57:42.940
which is annotated as a login form,

00:57:42.940 --> 00:57:45.380
but it's also got fast UI form,

00:57:45.380 --> 00:57:45.920
which in turn,

00:57:45.920 --> 00:57:47.880
which also takes login form,

00:57:47.880 --> 00:57:49.300
all of which looks a bit ugly.

00:57:49.300 --> 00:57:54.860
But what we're really doing in the background is converting form data into the Pydantic model,

00:57:54.860 --> 00:57:59.540
including flattening and deflattening the model in the case where we have nested models,

00:57:59.540 --> 00:58:00.480
which I'll show you in a minute.

00:58:00.480 --> 00:58:02.720
But the result of this is once we,

00:58:02.720 --> 00:58:03.100
in our,

00:58:03.100 --> 00:58:03.840
in our post endpoint,

00:58:03.840 --> 00:58:05.040
we get an instance of,

00:58:05.040 --> 00:58:07.420
of the login form that we can then go do stuff with.

00:58:07.420 --> 00:58:10.400
If I show you a more comprehensive or complex example,

00:58:10.400 --> 00:58:13.680
this is big model here becomes big form.

00:58:13.680 --> 00:58:14.580
And this has,

00:58:14.580 --> 00:58:15.780
has a bunch more stuff in it.

00:58:15.780 --> 00:58:17.780
So it has file inputs.

00:58:17.780 --> 00:58:20.360
Now file inputs are one of the reasons we can't just submit,

00:58:20.360 --> 00:58:21.780
submit JSON because,

00:58:21.780 --> 00:58:22.220
Yeah.

00:58:22.220 --> 00:58:25.860
Because we need a multi-part encoding and all those things.

00:58:25.860 --> 00:58:26.080
Yeah.

00:58:26.080 --> 00:58:26.940
All those things.

00:58:26.940 --> 00:58:27.440
Right.

00:58:27.440 --> 00:58:29.800
And so here we have name.

00:58:29.800 --> 00:58:31.340
We use bold again,

00:58:31.340 --> 00:58:32.480
as I have before to,

00:58:32.480 --> 00:58:33.920
to indicate required fields.

00:58:33.920 --> 00:58:35.460
So we could,

00:58:35.460 --> 00:58:35.940
I don't know,

00:58:35.940 --> 00:58:39.060
have got some Pydantic logos here that I'll use as images.

00:58:39.060 --> 00:58:41.080
This one is multiple images.

00:58:41.080 --> 00:58:43.660
So we can select multiple images,

00:58:43.660 --> 00:58:45.300
a date field in this case.

00:58:45.300 --> 00:58:46.760
I've got a calendar picker.

00:58:46.760 --> 00:58:47.300
Very nice.

00:58:47.300 --> 00:58:49.120
Is that just input type equals?

00:58:49.120 --> 00:58:50.580
That's just input type equals,

00:58:50.580 --> 00:58:51.240
equals date.

00:58:51.240 --> 00:58:51.720
Okay.

00:58:51.720 --> 00:58:52.240
We have switches.

00:58:52.240 --> 00:58:53.080
We have,

00:58:53.080 --> 00:58:53.880
and then you'll see here,

00:58:53.880 --> 00:58:57.380
we have size model arrow width and size model arrow height.

00:58:57.380 --> 00:58:57.920
And the,

00:58:57.920 --> 00:58:59.780
the point is that we're doing here,

00:58:59.780 --> 00:59:00.940
and these are integer fields,

00:59:00.940 --> 00:59:06.100
but the cool bit is that they map to a nested Pydantic model within the big

00:59:06.100 --> 00:59:06.400
model.

00:59:06.400 --> 00:59:11.060
What fast UI is doing internally is basically flattening this into,

00:59:11.060 --> 00:59:12.980
one list of form fields,

00:59:12.980 --> 00:59:14.620
which is then what we get rendered here.

00:59:14.620 --> 00:59:15.020
I see.

00:59:15.020 --> 00:59:16.720
So in your Pydantic model,

00:59:16.720 --> 00:59:18.060
you have a size object,

00:59:18.060 --> 00:59:19.080
but then in the form,

00:59:19.080 --> 00:59:21.060
it just has the width and the height,

00:59:21.060 --> 00:59:21.940
the one after another.

00:59:21.940 --> 00:59:22.240
Size width,

00:59:22.240 --> 00:59:22.720
size height.

00:59:22.720 --> 00:59:23.180
Exactly.

00:59:23.180 --> 00:59:24.280
If I put a,

00:59:24.280 --> 00:59:29.900
a requirement or a restriction like min or max onto the field in the size

00:59:29.900 --> 00:59:30.180
model,

00:59:30.180 --> 00:59:33.600
would that become a client side min and max in the form?

00:59:33.600 --> 00:59:35.680
There's an open PR to do exactly that.

00:59:35.680 --> 00:59:35.840
Yeah.

00:59:35.840 --> 00:59:36.040
Awesome.

00:59:36.040 --> 00:59:39.120
But obviously we will get server side validation as well.

00:59:39.120 --> 00:59:40.780
And then for a couple of weeks.

00:59:40.900 --> 00:59:41.720
So like it's,

00:59:41.720 --> 00:59:43.540
there's more to do,

00:59:43.540 --> 00:59:43.720
right?

00:59:43.720 --> 00:59:44.360
But that's awesome.

00:59:44.360 --> 00:59:45.020
That'll be fun.

00:59:45.020 --> 00:59:45.660
And then you'll,

00:59:45.660 --> 00:59:46.400
you'll see in uploads,

00:59:46.400 --> 00:59:47.040
we have some,

00:59:47.040 --> 00:59:48.760
some quite powerful things we can do here.

00:59:48.760 --> 00:59:51.100
So we use the upload file,

00:59:51.100 --> 00:59:52.560
which is a starlet type,

00:59:52.560 --> 00:59:55.620
but we can also annotate it with form file,

00:59:55.620 --> 00:59:56.060
file,

00:59:56.060 --> 00:59:59.620
which takes two optional arguments of what rule,

00:59:59.620 --> 01:00:00.900
what accepts to apply.

01:00:00.900 --> 01:00:02.980
So that will both in the browser,

01:00:02.980 --> 01:00:04.540
when you open the,

01:00:04.540 --> 01:00:06.580
when you choose a file browse dialogue,

01:00:06.580 --> 01:00:07.040
yeah,

01:00:07.080 --> 01:00:07.520
it'll tell you.

01:00:07.520 --> 01:00:08.200
You have a MIME.

01:00:08.200 --> 01:00:09.060
So for people listening,

01:00:09.060 --> 01:00:10.300
you have the MIME type set,

01:00:10.300 --> 01:00:11.400
not like a extension,

01:00:11.400 --> 01:00:13.240
but you have image slash star,

01:00:13.240 --> 01:00:14.000
which means,

01:00:14.000 --> 01:00:14.180
you know,

01:00:14.180 --> 01:00:15.000
image slash JPEG,

01:00:15.000 --> 01:00:15.360
PNG,

01:00:15.360 --> 01:00:16.000
WebP,

01:00:16.000 --> 01:00:16.340
et cetera.

01:00:16.340 --> 01:00:16.600
Right.

01:00:16.600 --> 01:00:18.960
And that's understood by the browser and then by the,

01:00:18.960 --> 01:00:20.160
and then by the OS to,

01:00:20.160 --> 01:00:21.300
to let you select files,

01:00:21.300 --> 01:00:23.280
but it's also validated server side.

01:00:23.280 --> 01:00:26.320
So if someone goes and edits their HTML and submits a not image,

01:00:26.320 --> 01:00:30.160
the server side validation will check at least based on the file extension

01:00:30.160 --> 01:00:30.560
that it,

01:00:30.560 --> 01:00:33.140
that it looks like an image and you get back the bytes.

01:00:33.140 --> 01:00:36.680
So you could also go do validation that the bytes are a valid image.

01:00:36.680 --> 01:00:37.040
If you,

01:00:37.040 --> 01:00:38.920
if you say you can read the bomb,

01:00:38.920 --> 01:00:39.300
the,

01:00:39.300 --> 01:00:43.180
the mark that indicates the file type that's sometimes in these different files.

01:00:43.180 --> 01:00:43.420
Yeah.

01:00:43.420 --> 01:00:44.460
If I submit this,

01:00:44.460 --> 01:00:45.000
but let's say,

01:00:45.000 --> 01:00:45.160
well,

01:00:45.160 --> 01:00:45.480
first of all,

01:00:45.480 --> 01:00:46.520
if I try and submit this,

01:00:46.520 --> 01:00:48.960
because we've got server side validation of which fields are required,

01:00:48.960 --> 01:00:52.120
it won't let me submit if this file field is not completed.

01:00:52.120 --> 01:00:56.620
And then I think if we put a name and we don't capitalize it in this case,

01:00:56.620 --> 01:00:59.560
we'll go off and do the validation and come back and we'll say,

01:00:59.560 --> 01:01:02.020
name will start with the capital because I've implemented it.

01:01:02.020 --> 01:01:03.140
Where's that validation?

01:01:03.140 --> 01:01:03.560
Oh,

01:01:03.560 --> 01:01:03.860
I see.

01:01:03.860 --> 01:01:05.520
That's a function that you write.

01:01:05.520 --> 01:01:05.760
Right.

01:01:05.760 --> 01:01:07.000
So just to prove the point,

01:01:07.000 --> 01:01:08.940
I've just written a validator in,

01:01:08.940 --> 01:01:09.520
in Pydantic,

01:01:09.520 --> 01:01:11.080
which says this must start with,

01:01:11.080 --> 01:01:11.960
with uppercase.

01:01:11.960 --> 01:01:16.400
And if I then went in here and edited that,

01:01:16.400 --> 01:01:17.500
print out form,

01:01:17.500 --> 01:01:19.360
is that going to now clear my form?

01:01:19.360 --> 01:01:19.560
No,

01:01:19.560 --> 01:01:19.980
it's not,

01:01:19.980 --> 01:01:20.800
which is magic.

01:01:20.800 --> 01:01:21.980
And if I submit that,

01:01:21.980 --> 01:01:24.880
you'll see here where I printed out the form.

01:01:24.880 --> 01:01:26.000
We got the,

01:01:26.000 --> 01:01:29.900
we got the different file objects and we got the raw data all come through as a Pydantic model.

01:01:29.900 --> 01:01:30.240
Yeah,

01:01:30.240 --> 01:01:31.020
that's really cool.

01:01:31.440 --> 01:01:35.540
And so I love how even the custom validators in Pydantic,

01:01:35.540 --> 01:01:40.080
like Python code that you wrote appears on what feels like client side,

01:01:40.080 --> 01:01:42.920
but is really server side validation run by React,

01:01:42.920 --> 01:01:43.820
right?

01:01:43.820 --> 01:01:44.060
Yeah,

01:01:44.060 --> 01:01:44.720
exactly that.

01:01:44.840 --> 01:01:49.160
so we'll do stuff like link checks and all the things you can do on an input client side as well.

01:01:49.160 --> 01:01:49.620
But of course,

01:01:49.620 --> 01:01:50.520
there'll also be,

01:01:50.520 --> 01:01:52.040
be enforced server side,

01:01:52.040 --> 01:01:55.060
which obviously if you're building anything that you're going to be exposed to the internet,

01:01:55.060 --> 01:01:55.880
you've got to do.

01:01:56.100 --> 01:01:56.220
Yeah,

01:01:56.220 --> 01:01:57.120
you should never,

01:01:57.120 --> 01:01:59.940
never trust what comes into your web app.

01:01:59.940 --> 01:02:02.720
It's just put it online for five minutes and look at the log.

01:02:02.720 --> 01:02:03.520
It's already trying.

01:02:03.520 --> 01:02:06.520
Somebody's already after WP admin.php,

01:02:06.520 --> 01:02:06.840
you know?

01:02:06.840 --> 01:02:07.160
Yeah,

01:02:07.160 --> 01:02:07.960
exactly that.

01:02:07.960 --> 01:02:09.520
And then the last thing I'll show,

01:02:09.520 --> 01:02:11.480
I know we haven't got very long at all is authentication,

01:02:11.480 --> 01:02:13.760
which I've just been working on now.

01:02:13.760 --> 01:02:14.440
This is,

01:02:14.440 --> 01:02:14.720
again,

01:02:14.720 --> 01:02:15.660
it's a simple form.

01:02:15.660 --> 01:02:17.140
I'm just going to select an email,

01:02:17.140 --> 01:02:20.420
put in a random password and I can log in.

01:02:20.420 --> 01:02:21.920
And in this case,

01:02:21.920 --> 01:02:22.320
I've logged it.

01:02:22.320 --> 01:02:24.440
It just says who I am and how many people are logged in.

01:02:24.760 --> 01:02:25.880
If I come back to this page,

01:02:25.880 --> 01:02:29.520
it'll show me logged in and I can do post requests to log out.

01:02:29.520 --> 01:02:32.340
And what it's doing internally is,

01:02:32.340 --> 01:02:32.740
and again,

01:02:32.740 --> 01:02:35.700
this is the kind of thing that would be lots and lots of work to implement if you're doing it yourself,

01:02:35.700 --> 01:02:37.860
is it's storing in session storage,

01:02:37.860 --> 01:02:38.820
the auth token,

01:02:38.820 --> 01:02:43.080
then adding it as a header where we do the fetch from the front end to the back end.

01:02:43.080 --> 01:02:45.040
So we can effectively store,

01:02:45.040 --> 01:02:46.120
store sessions that way.

01:02:46.120 --> 01:02:46.400
Oh yeah.

01:02:46.400 --> 01:02:46.840
Very cool.

01:02:46.840 --> 01:02:47.320
Yeah.

01:02:47.320 --> 01:02:50.960
That auth token's coming in as a header item or being set as a header item.

01:02:50.960 --> 01:02:51.280
Excellent.

01:02:51.280 --> 01:02:51.700
Right.

01:02:51.700 --> 01:02:52.100
Exactly.

01:02:52.100 --> 01:02:52.440
Cool.

01:02:52.440 --> 01:02:52.840
So yeah,

01:02:53.060 --> 01:02:55.860
I hope that we've done a bit of a whirlwind tour through,

01:02:55.860 --> 01:02:57.760
through fast UI and what's there now and what,

01:02:57.760 --> 01:03:01.460
what I hope is coming up and the like slightly philosophy of how,

01:03:01.460 --> 01:03:02.000
why I,

01:03:02.000 --> 01:03:02.700
why I built it.

01:03:02.700 --> 01:03:03.180
But yeah,

01:03:03.180 --> 01:03:03.820
that was interesting.

01:03:03.820 --> 01:03:04.580
It's super interesting.

01:03:04.580 --> 01:03:06.400
And it's really early days.

01:03:06.400 --> 01:03:06.720
I'm,

01:03:06.720 --> 01:03:09.880
I'm looking forward to two things to see what people go do with it,

01:03:09.880 --> 01:03:11.740
what widgets and stuff they build.

01:03:11.740 --> 01:03:12.140
So,

01:03:12.140 --> 01:03:12.460
you know,

01:03:12.460 --> 01:03:13.100
can you drop in,

01:03:13.100 --> 01:03:13.480
like you said,

01:03:13.480 --> 01:03:15.320
a calendar or something awesome like that.

01:03:15.520 --> 01:03:19.980
And I'm also looking forward to see what you all internally release in a couple months.

01:03:19.980 --> 01:03:20.620
Absolutely.

01:03:20.620 --> 01:03:21.860
Yeah.

01:03:21.860 --> 01:03:22.920
Thanks so much for,

01:03:22.920 --> 01:03:25.420
for having me and letting me witter on about,

01:03:25.420 --> 01:03:26.260
about this,

01:03:26.260 --> 01:03:27.340
this random library.

01:03:27.340 --> 01:03:27.700
Yeah,

01:03:27.700 --> 01:03:28.140
of course.

01:03:28.140 --> 01:03:28.920
Good work.

01:03:28.920 --> 01:03:30.260
It's certainly creative.

01:03:30.260 --> 01:03:32.440
Maybe just give people a sense of,

01:03:32.440 --> 01:03:32.940
you know,

01:03:32.940 --> 01:03:33.980
as we wrap it up,

01:03:33.980 --> 01:03:35.160
can they use it now?

01:03:35.160 --> 01:03:36.440
Should they use it now?

01:03:36.440 --> 01:03:37.520
Can they contribute?

01:03:37.780 --> 01:03:38.480
Maybe they're interested.

01:03:38.480 --> 01:03:39.960
What do you tell that crew?

01:03:39.960 --> 01:03:41.860
I'd love people to contribute both.

01:03:41.860 --> 01:03:42.140
I mean,

01:03:42.140 --> 01:03:43.300
almost most useful is,

01:03:43.300 --> 01:03:45.620
it's issues saying how you're using it,

01:03:45.620 --> 01:03:46.200
where it's working,

01:03:46.200 --> 01:03:46.760
where it's not.

01:03:46.760 --> 01:03:49.460
There is a bunch of people who've already submitted PRs and,

01:03:49.460 --> 01:03:50.860
and continue to do so.

01:03:50.860 --> 01:03:51.460
And yeah,

01:03:51.460 --> 01:03:58.620
I think what works works pretty rigorously and it's probably better implemented and tested than lots of like private code,

01:03:58.620 --> 01:04:01.240
but definitely within internal uses,

01:04:01.240 --> 01:04:01.780
use it now.

01:04:01.780 --> 01:04:02.480
And like I say,

01:04:02.480 --> 01:04:03.780
Pynantic is building things,

01:04:03.780 --> 01:04:04.920
building things with it now.

01:04:04.920 --> 01:04:06.180
So look,

01:04:06.180 --> 01:04:06.640
I mean,

01:04:06.640 --> 01:04:07.200
I'm not,

01:04:07.320 --> 01:04:10.260
I give the open source guarantee that it's relatively safe,

01:04:10.260 --> 01:04:12.020
which is the guarantee that means nothing.

01:04:12.020 --> 01:04:14.060
But mostly because at the end,

01:04:14.060 --> 01:04:18.660
it's just defining how you build your UI and how you implement your session authentication.

01:04:18.660 --> 01:04:20.700
It's not having strong opinions about that.

01:04:20.700 --> 01:04:21.540
So yeah,

01:04:21.540 --> 01:04:22.180
I think it's,

01:04:22.180 --> 01:04:24.940
I think it's the place where people should go and try it and give,

01:04:24.940 --> 01:04:25.520
give feedback.

01:04:25.520 --> 01:04:25.880
Excellent.

01:04:25.880 --> 01:04:26.260
All right.

01:04:26.260 --> 01:04:26.520
Well,

01:04:26.520 --> 01:04:28.100
thanks again for coming on the show.

01:04:28.100 --> 01:04:29.620
Looking forward to talking to you next week.

01:04:29.620 --> 01:04:29.780
No,

01:04:29.780 --> 01:04:30.120
just kidding.

01:04:30.120 --> 01:04:31.060
Like two in a row.

01:04:31.060 --> 01:04:31.360
I suppose.

01:04:31.360 --> 01:04:33.080
Looking forward to talking to 2024.

01:04:33.080 --> 01:04:33.880
Absolutely.

01:04:33.880 --> 01:04:34.720
Have a good Christmas.

01:04:34.720 --> 01:04:35.440
Thank you so much.

01:04:35.440 --> 01:04:35.720
Yeah.

01:04:35.720 --> 01:04:36.040
Thanks.

01:04:36.040 --> 01:04:36.260
Bye.

01:04:36.860 --> 01:04:39.440
This has been another episode of talk Python to me.

01:04:39.440 --> 01:04:41.260
Thank you to our sponsors.

01:04:41.260 --> 01:04:42.880
Be sure to check out what they're offering.

01:04:42.880 --> 01:04:44.300
It really helps support the show.

01:04:44.300 --> 01:04:49.140
Bright data is professional web scraping and a dataset marketplace.

01:04:49.140 --> 01:04:52.180
If you need data and it doesn't have an API,

01:04:52.180 --> 01:04:56.180
check out talkpython.fm/bright data today.

01:04:56.180 --> 01:04:59.640
Take some stress out of your life.

01:04:59.640 --> 01:05:05.100
Get notified immediately about errors and performance issues in your web or mobile applications with

01:05:05.100 --> 01:05:05.420
Sentry.

01:05:05.660 --> 01:05:10.420
Just visit talkpython.fm/sentry and get started for free.

01:05:10.420 --> 01:05:13.220
And be sure to use the promo code talkpython,

01:05:13.220 --> 01:05:14.020
all one word.

01:05:14.020 --> 01:05:16.460
Want to level up your Python?

01:05:16.460 --> 01:05:20.580
We have one of the largest catalogs of Python video courses over at Talk Python.

01:05:20.680 --> 01:05:25.700
Our content ranges from true beginners to deeply advanced topics like memory and async.

01:05:25.700 --> 01:05:28.360
And best of all, there's not a subscription in sight.

01:05:28.360 --> 01:05:31.260
Check it out for yourself at training.talkpython.fm.

01:05:31.260 --> 01:05:33.340
Be sure to subscribe to the show.

01:05:33.340 --> 01:05:36.120
Open your favorite podcast app and search for Python.

01:05:36.120 --> 01:05:37.440
We should be right at the top.

01:05:37.540 --> 01:05:40.380
You can also find the iTunes feed at /itunes,

01:05:40.380 --> 01:05:42.580
the Google Play feed at /play,

01:05:42.580 --> 01:05:46.780
and the direct RSS feed at /rss on talkpython.fm.

01:05:46.780 --> 01:05:49.740
We're live streaming most of our recordings these days.

01:05:49.740 --> 01:05:53.160
If you want to be part of the show and have your comments featured on the air,

01:05:53.160 --> 01:05:57.580
be sure to subscribe to our YouTube channel at talkpython.fm/youtube.

01:05:57.580 --> 01:05:59.640
This is your host, Michael Kennedy.

01:05:59.640 --> 01:06:00.940
Thanks so much for listening.

01:06:00.940 --> 01:06:02.100
I really appreciate it.

01:06:02.100 --> 01:06:04.000
Now get out there and write some Python code.

01:06:04.000 --> 01:06:24.880
I'll see you next time.