If you work on the data science or data visualization side of Python, you may have come to it from a
scripting side of things, writing just a little Python using its magical libraries with little
structure or formalism to build a powerful analysis tool that runs in the terminal or
maybe even in a Jupyter notebook. What if you could take that same code, sprinkle in a bit of
a simple API and turn it into a fast and dynamic single page web application that allows your users
to dive into the visualizations right there in the app? Well, that's basically what the folks over at
Streamlit created, and we're going to dive into it with one of the creators, Adrian Truel.
This is Talk Python to Me, episode 260, recorded April 9th, 2020.
Welcome to Talk Python to Me, a weekly podcast on Python, the language, the libraries, the ecosystem,
and the personalities. This is your host, Michael Kennedy. Follow me on Twitter where I'm at,
mkennedy. Keep up with the show and listen to past episodes at talkpython.fm, and follow the show on
Twitter via at Talk Python. This episode is sponsored by Linode and Reuven Lerner's Ace Python interviews
course. Please check out what they're both offering during their segments. It really helps support the
show. Adrian, welcome to Talk Python to Me. Hey, Mike. So excited to be here. Thanks a lot for
inviting me on the show. Hey, it's super happy to have you here on the show. A ton of people reached
out to me when Streamlit was initially launched saying, there's this new thing. It has changed my
world. You have to talk to the people behind it. And so now I'm excited to talk to the people behind it.
Yeah, totally. It's awesome to hear that. And, you know, definitely for someone who's spent a lot of
time, you know, in a room programming alone, it's really cool to have made something and hear people
say, this is awesome. This, this, you know, really changed my life and my work. So that's great to hear.
Yeah, it's a super cool product. And I think it's going to be fun to talk about. It really enables
data scientists to get certain types of computation out there in a way that people can interact with.
So I'm very excited to talk about it, where it came from, some of the technology inside of it and
whatnot. But let's get started with your story. How'd you get into programming in Python?
My story is that it's never too late to become a programmer. I actually went to college to study
international relations. I was, came from a bilingual family and I, you know, I figured out I should do
politics or something like that. Right. Leverage your bilingualism, right? What languages did you,
do you speak? Well, okay. So my dad's French. So I grew up speaking French and English and we were,
and then, you know, being, you know, growing up in the U S I'm surprising that I took Spanish.
And then actually when I got to college, I took Chinese. So, you know, I didn't come from a family
that really respected like programming and that kind of thing. And so it wasn't part of my world. And I
feel kind of envious of kids who grew up, you know, went to science high schools and stuff,
because in retrospect, that's really who I was. But it wasn't until I got to college and about a
year and a half into studying international relations, I was like, this is not for me.
Actually, I always thought college might not be for me. And then this professor of economics remembered
me because I had blue hair. And he was like, you know, he said, Adrian, how are you doing? And I said,
well, you know, not so well, I'm not even sure if I should be here. And he said,
what you need to do is, he said, you're misallocated, which is a very economic way.
That's a very economic way to describe your situation.
Yeah, exactly. And so he was like, what you need to do is you need to study math and science. And I was,
you know, anyway, I thought that that was ridiculous, literally, but I took him up on his offer.
And it calc one, my sophomore year of college took intro to programming, was like blown away. It was
like, these are my people, this is my work. And I'm just so grateful. I found it. Oh, my God. I mean,
wow, what a fun job to have. And what a fun world to be in. And also, this is back in the late 90s.
It wasn't 100% as obvious as it is today that this is like, generally, generationally changing for all
of culture. And obviously, it is everyone sees that now. And so I feel really lucky to have gotten in.
Yeah, how lucky that you had that interaction. And you found your place because I think a lot of people,
they don't find their place in the world, they find a place that they're comfortable with,
and they end up in a place that's okay.
Absolutely.
They don't wake up going, wow, I get to do this.
Yeah. And I really think, you know, being able to figuring out taking time to figure out like,
what you really would enjoy doing and trying a lot of different things. I just can't think of
anything more valuable. I really actually think the whole world is a little bit misallocated
to a certain extent. And if everyone can sort of play musical chairs and, you know, get the right job,
for a better job, we can just unleash like massive new economic potential. So,
you know, that's true for my life. It's also been part of actually a theme of my professional life as
well. So I can talk about that. But anyway, yeah, figuring out what you love to do is I think so
valuable. And I'm so grateful for that professor.
That's amazing. I do think there's a little bit, I don't know how to solve this. But I do think there's
a little bit of a mismatch, where people tell you, you have to find something that you're passionate
about, or you're not going to be happy in your career. I think that you find something that connects
with you. And you didn't even know that it was going to connect with you. And then you polish that
skill. And then you become very passionate and excited about it. So when you, I think when young
people hear advice, like you have to do what you're passionate about, like when you're young, and you
haven't had that exposure, like imagine you hadn't taken that math class, like, you weren't passionate
about math. It's not like you're like, well, get out of my way, you know, languages, I'm going to math,
right? There's a sort of chicken and egg thing. And I think it's really hard to unlock that potential
for a lot of people in general. I don't know. I don't know what to give people advice about that.
But it's it's I think it's interesting that it's important to do what you're passionate about. But like,
you got to somehow explore to get that figured out.
I agree. And I also think there may be different, there are different kinds of people, of course. And
I don't think necessarily being passionate about what you do is as important to other people as it
turns out it is to me. I don't want to over extrapolate either. But I do feel really grateful
for, you know, have been given that advice. And it's actually come up in a couple other ways in my life.
I created a game called Foldit that allowed hundreds of thousands of people to solve protein
folding problems when I was doing my PhD. I think I've heard of that. Yeah, I'm pretty sure I did hear
that. Yeah. So it was the gamification of trying to solve a protein folding problem. It wasn't like
SETI at home where it was like just grid computing, right? It was leveraging human creativity, not
distributed computing, right? Exactly. And that had sort of that theme. One of the coolest things about
that project was that a lot of people found out, hey, this is something that I love doing. And they
were able to contribute to society in like a new way that they've never experienced before. And so I
think for a lot of people, it sort of unlocked a little bit this, you know, new skill. Yeah.
And then coming to Streamlit, you know, what we are doing is building software that lets data
scientists and machine learning engineers, like productize their work without the need of anyone else to
help them so they can build apps that others can use. And again, I feel like for our users,
we're giving them like a new form of impact in the world and in their companies. And I think that's
where the passion comes from. So in a funny way, it does seem like a theme, both in my life personally,
and also in the products that I've been creating.
Yeah, absolutely. And so you went from not sure you should be at college to studying some math to
being a professor at Carnegie Mellon. That's a big, big U-turn.
Yeah, yeah, yeah, yeah, yeah. But you know, actually, in a funny way, the I don't think the
quest ended there. Because when I was a professor at Carnegie Mellon, there were some things that I
really loved about it. But I felt that I wasn't directly affecting the world the way I do now at
Streamlit. So and in a sense, we were doing super fascinating, very mathematical, big data stuff.
And it was from an intellectual standpoint, I mean, heaven to the power of heaven.
But I was missing that that other aspect of things, which is really, you know, having an audience beyond
a couple hundred experts in the world in some way. Both are totally valid and extremely important
forms of impact each in their own way. So I am a huge believer in academia, and it's important in
society. I personally wanted a little bit more direct connection to the, you know, the quote,
unquote, the user. And that has taken me through a variety of different jobs at Google X, working on
self-driving cars at Zoox, and then finally starting Streamlit. And for the first time since I created
Foldit, I'm hearing people say, wow, this is really changing my life. And that's so exciting to have
created a product that has that property. It's amazing you've done it twice, right?
And with this, you've made something that's made a big impact for a lot of people.
It is really gratifying. And I think, you know, the gratifying part is to, first of all, it gets to,
you know, build cool things and work on cool ideas, but also just have other people feel like their jobs
are more interesting and more fun, and they're having more impact because of some piece of technology that
we've pulled out. And so I think that's just great. I think that's just so exciting.
I agree. So today, day to day, you're working at Streamlit with Thiago and Amanda, your co-founders,
and I'm guessing some other folks on the team. What kind of work are you doing there?
Okay, so we're about nine people, and we're about 18, including contractors, and we are hiring a lot
all across the United States. And we are basically building two products, one of which is Streamlit,
and the other of which is Streamlit for Teams, which allows people to build data apps really
quickly in Python. Streamlit for Teams allows them to deploy it really easily, and so that others can
use it. And then my day is pretty much, well, my dream day is pretty much I'm chatting with the
engineers and working on design docs and thinking about cool problems. Somehow that's like very rarely
my actual day. I don't know how it happens, but my actual day is often just like meetings,
meetings, meetings, meetings, meetings, talking with investors. I don't know, thinking about
payroll stuff and not sure how, despite my effort over years to make that not be the case, that is
still the case, but that is still the case.
Here you find yourself, but you know, that's kind of what it takes to get some of the stuff going,
right? So yeah, totally, totally. Yeah. And I think, you know, ultimately what has made Streamlit
great has not actually been my ideas per se, but really actually the ideas of the community
and also of the engineers working on it. And so I try to remember that even though I have a dream job
of working on every aspect of the product, probably for everyone else's benefit, I should just get out of
the way and let them do the magic. Yeah. That sometimes is how it is, right? It's just let
let the people do the work, even though it would be very fun. Now I want to get into some of the
origins and whatnot, but I also just want to set the stage as people are listening, because this was
something I was not entirely clear about as well. Yeah. So you spoke about Streamlit, the tool for
building interactive UIs around data science, and you spoke about Streamlit for teams, talked about hiring
people. So obviously this is a business venture. Yeah. The status, which is great. I'm super supportive
of you guys. That's awesome. But I just want people to realize that Streamlit, the tooling in the library
is an open source thing that you can use. And the teams thing is like a cloud computing service that is
part of the business. Is that, am I understanding that right? Yeah, that's exactly right. And speaking of
the origin story, it wasn't actually meant to be a business. It was really a side project and it was
going to just be an open source project. But what happened was a bunch of people at really big companies
like Stitch Fix started using it. And then we realized, hey, there is actually a business model
here. And so the picture started, in a sense, it all kind of snowballed from what was really first,
just a personal project, me at home, coding all day long. And my mom saying, hey, you need to figure out a way
to make money off this thing. You're going to work on it so much. And then it sort of has evolved into a business.
And so, yeah, there's actually a very simple breakdown in terms of the open source and the business part,
which is open source is lets you build data apps super quickly and easily. It's free, always will be free.
Apache 2 license. It's a real open source project. Everything's up on GitHub. The community contributes a lot.
We build it a lot and maintain it. So that's the open source part of the project.
The closed source part of the project lets you take your streamlit apps and deploy them really easily on our cloud.
You're certainly welcome to just deploy it for free, however you'd want. And there's tons of guides online about how to do that.
And we totally support that aspect of the community. So there will always be a way to create and deploy streamlit apps
for free using only open source tools. But we also recognize that a lot of our users and especially corporate users
are asking for a simpler solution to that side of things, the deployment, not the app building.
Well, I think it makes a lot of sense because the goal of the tool is to make converting like data science ideas and libraries
and problem solving into an interactive web app really easy. And so the last thing you probably want to do is like,
well, that was cool. Now you need to figure out Nginx. You need to figure out SSL. You need to figure out cache.
You need to figure out Linux maintenance, et cetera, et cetera.
Exactly.
I think it's a reasonable thing to do for sure.
Yeah. I think that the experience that our users have is they download Streamlit. So pip install Streamlit,
follow the tutorial, literally within 30 seconds, they have an app that they're playing around with. Within
five minutes, they've created their own and there's a little button or something. And I think that what we
hope for is delight. But then it comes to, I want to share this with others.
And you go into the, you search around on Google and it's literally starts to become,
you know, create a GCP instance, copy your SSH keys into it. I'll tell you, that's a nerve wracking
experience to actually try to put something on the web and have it secure and everything. So we want
to bring that delight to the deploy as well. And that's kind of the picture.
This portion of Talk Python to Me is brought to you by Linode. Whether you're working on a personal
project or managing your enterprise's infrastructure, Linode has the pricing, support, and scale that you
need to take your project to the next level. With 11 data centers worldwide, including their newest
data center in Sydney, Australia, enterprise grade hardware, S3 compatible storage, and the next
generation network, Linode delivers the performance that you expect at a price that you don't.
Get started on Linode today with a $20 credit and you get access to native SSD storage, a 40 gigabit
network, industry leading processors, their revamped cloud manager at cloud.linode.com,
root access to your server, along with their newest API and a Python CLI. Just visit talkpython.fm
slash Linode when creating a new Linode account, and you'll automatically get $20 credit for your next
project. Oh, and one last thing, they're hiring. Go to linode.com slash careers to find out more.
Let them know that we sent you.
I haven't interacted with the deployment side of things, but I can tell you that the web app side,
it's got a little bit of magic. So let's get into that, but let's start at maybe the predecessor,
right? A lot of people are coming into Python these days. This is my assessment of looking out at the
world. They're coming into Python for a little bit of computational scripting. I hate to call it
scripting because when people say, Oh, Python's a scripting language. It's like,
yeah, but you also, it's a programming language that supports scripting, right? Like it's,
there are a lot of people who they don't care about computer science. They definitely don't think of
themselves as programmers. They think of themselves as economists, biologists, whatever. But they're like,
I know I got it. This data is too much for me to do on my own. I Excel or whatever. So I'm going to
throw it into this. I've learned that if I use Jupyter, I type these five lines using this library,
no functions in sight, you know, no unit tests, none of that. Just like I do these,
these five or 10 lines in order. Then I have this really cool power. And then they get sucked into
Python, right? Like, yeah, they could do a little more and a little more. And like, eventually they look
back and like, wait, I'm programming. How did I become a programmer? Which is great. But I think
like where you guys are aiming is that audience a little bit, right? The people who are like,
I can put this together in kind of a top to bottom flow of computation and generate results,
but I need more than that, but I'm not a programmer. Would you say that's fair?
Yeah, that's exactly right. So we really embrace Python as a scripting language. That's the core of
Streamlit. And we embrace the ethos of let's write code from top to bottom that does something simple,
that's easy to understand and read. And that really gives you a huge amount of power for,
you know, a huge amount of bang for your buck. I mean, that's what Python is, right? You know,
how do I, how do I download some information off the web requests package, boom, boom, boom,
all of a sudden it's happening. And I think actually Python programmers, myself very much included,
are like shocked when you go to another programming language and you're like, oh, I, yeah, totally.
You know, we just, you do, you know, do all these things. And then you're like, oh my God,
this is impossibly difficult. How are these people doing this? You know? So there is still,
I mean, it's an old, it's getting to be an old language and yet there's this magic to it. And
there's this bang for the buck that it's just unparalleled. And, and Streamlit is grounded in
that observation and in that ethos, which is let's write script and let's extend Python in a new
direction, which is really being able to write web apps, especially data web apps that capture something
about what you've done as a data scientist or a machine learning engineer and allows lots of people to play with it
use it and understand it and actually become part of business processes. And,
yeah.
And we've seen, you know, become part of the fabric of your company or of your group or of the world.
People are creating lots of COVID apps, for example, both to teach other people about coronavirus,
but also in some cases, the University of Penn hospitals released a Streamlit app to allow
other hospitals to predict how many beds they need.
Yeah. That's very useful, right? That's taking the models and applying them for,
you're going to need to get five more or something like that. Right. Very concrete.
Exactly. Exactly. Very concrete. And very much sort of the next step in data science beyond just,
you know, I've created a graph once for, to paste into a, you know, spreadsheet or into a presentation.
It's like, well, what happens when I need to do this repeatedly and when a lot of people need to interact with it and play with it?
I use it, I should say. And then, and then how can we do that without embracing this scripting ethos?
We want to make app creation as easy as writing scripts in Python. And that's really the core sort of philosophy that motivates Streamlit.
And I think the capturing that magic is what has caused so many people to get excited by it.
Yeah, I think you're right. And I think it's an interesting blend between notebooks and more proper programming, but just a little bit.
So we'll talk about some of the examples and whatnot you have that are really cool, but they are Python files and they do have functions in them,
but they're not, not like super advanced. Right. So it feels like they're almost kind of organized,
like someone might organize a notebook for scripting, but it's a little bit more formal than a tiny bit more formal than that.
But what you gain on the other side is like tons of interactivity, which is pretty cool.
So when you look at the Streamlit, you guys talk about it, you say, basically the goal is to bring three things together.
The Python scripting, which we talked about. The next one is interaction to basically make this an interactive thing for users,
more or less the productization of that stuff. Right. So users can play with it, not just developers.
And the final bit is deployment that we've kind of touched on, but we haven't talked very much about the interactive bit,
which I think is also some of the magic because honestly, I look at this and I don't necessarily fully understand it
because I've written a lot of GUI applications. I've written 3D simulators and whatnot.
And I, you know, I wasn't super great at it, but I know what the code looks like.
I've done tons of GUI apps with, with callbacks and whatnot.
Yeah.
You seem to have been able to achieve those types of things without loops and without explicit,
how this button event wires up to this callback and all that async kind of stuff that's so common around UI.
So maybe we should talk about the interaction bit.
That's exactly right. The ethos of scripting is basically, I'm going to write a script that,
you know, loads some data, transforms it, does some other stuff, and then it's done.
The ethos of app development is totally different. It's, I'm going to declare a bunch of widgets on the screen.
I'm going to wire them up with callbacks. I'm going to have state that changes over time.
I'm going to be interacting with the web and have premises and stuff.
It is a truly different form of programming fundamentally and typically requires a lot of time to do even fairly small things.
I mean, that's, you know, it's not easy to build an app actually.
At a minimum, it takes a different way of thinking about programming that is not just like these 10 lines, right?
That's exactly right. It's a different way of thinking about programming.
And we really tried to ask ourselves, how could we make writing an app as simple as writing a script?
And so we give the Streamlit programmer a very, very simple to understand paradigm,
which is basically like sort of a cross between just a fancy print statement.
So, you know, in Python, you can always just say print, blah, blah, blah.
And then that gives you an ability to see what's going on and understand.
Right. If you want to level it up, you put some colorama in there and like make it.
Yeah, exactly. Yeah, exactly. Or, you know, if you're in Jupyter, you can say, like, let's look at the graph or, you know,
you can start doing some visual output.
So we basically give you that as a basic primitive.
It's called S-T Streamlit dot write, R-I-T-E.
And then you can just plop anything you want in there and it pops up on your web browser in order.
And then we say, hey, and if you want any interaction at any point, you can just say S-T dot and then just give it.
We've got a whole bunch of widgets, you know, sliders, text boxes and whatnot.
And that pops up on the screen.
And then we wire it all together so that if the user types or changes anything on the web browser,
that gets reflected back in your code instantly without having to do any work.
And so the model is just so simple to understand and therefore so productive.
And we want to bring that Python simplicity and that Python magic to the app building process
and make it so that others can just build apps really easily.
Probably the best way to give people a sense of this is maybe to walk through an example.
You guys have a couple of example bits of code out there.
And right at the beginning, you go to the Streamlit website, Streamlit dot IO.
You can go down a little bit.
There's like a get started, just pip install Streamlit and a few other things.
And then there's an example that you can just run that comes with it.
And this has to do with stealth driving cars, which you and your co-founders have a lot of background in self-driving cars.
Yeah, yeah.
Which is kind of cool, right?
Totally.
So the idea is there's a lot of image processing that goes on around identifying people, other cars, bikers,
certain tolerances of whether or not that is a biker or not, and so on.
And so you can basically get this demo and explore those.
You say, I'd like to have up to five, but no more than six pedestrians on the screen.
And then I want to test like parameters around it and stuff, right?
Yeah, that's exactly right.
So this is a problem that comes up in the self-driving car industry.
Really, it comes up in all machine learning and all data science.
In my experience, I've seen this again and again across groups at Google,
self-driving cars, companies across the country, which are now using Streamlit and telling us what their challenges are.
And so it's really a perfect example of a simple Streamlit app, which is I have a whole bunch of data, domain specific,
and I need a way to be able to browse through it and understand what's going on.
And I might need to look through it.
I might need to maybe run some models on it and or blend a couple of different data sets together.
And Streamlit makes those kinds of tasks really easy by just taking the basic elements of Python and adding a tiny little bit on top to make it a map.
So in this case, the challenge was something that we saw when building self-driving cars is that you drive your cars all around the city and you're collecting like all this data.
And at a certain point, even understanding all the data that you have becomes really complicated.
And lots of people need to be able to see it, not just the engineers, but technical program managers and executives and everyone needs to be able to see what's going on.
And so you eventually build an app to allow many different stakeholders to see and understand this data.
And so we built this app to illustrate how that can be done in Streamlit.
It uses the Udacity self-driving car data set as an underlying data set, lets you visualize where there are pedestrians and cars.
It even lets you run a neural net in real time.
And the entire app is built in 300 lines of Streamlit from top to bottom.
There's also like 50 lines of comments.
So I would say.
Yeah, yeah, yeah.
Yeah, it's 300 lines.
And it's not even like we're not even trying to be super, you know, we're not playing like code golf or anything.
Like the 300 lines includes like a huge like Apache 2 license and a lot of comments.
And yeah.
So in fact, I think there's only like 20 some odd function calls, Streamlit function calls in the entire program.
So everything else, basically, this very, very rich app is created in.
20 function calls and everything else or let's call it 25.
Everything else is just pure data.
So that's kind of a glimpse, hopefully for the listeners of just like this fact, which is that like you can just do a lot with a little, which is just a great thing to have.
Yeah.
So let me do two things.
Let me describe a little bit of what this app looks like when it's running so people get a sense.
So when you run the app, you get a web page that is running on its own little local Streamlit server.
And on the left, you get a sidebar that lets you basically do the user interaction, right?
Like I can say, what type of object am I looking for?
And then how many of those objects and depending on what you get, you can have like different types of confidence and whatnot.
So there's this sort of cool interactive slider thing on the left.
And then on the right and the main pane, there's kind of output from that, like pictures with selected characters in the picture from the neural net or graphs or whatever.
Right.
That's exactly right.
Yeah.
And so, you know, it's all the basic elements of Streamlit are there.
So you get some user input.
Right.
And so if I change like the dropdown or I change the slider as a user, talk about the user input, right?
Then that automatically is reflected back in the changing views of the graphs or the detection of the picture.
So that's a super cool type of dynamic interactive web app.
It's not posting back the page.
It's like a JavaScript spa type of application you would expect.
That's exactly right.
Yeah.
And, you know, it actually, this is just, this is trying to show what's possible in 300 lines of code with a 20 some odd Streamlit call.
But some of our users, especially corporate users, build really intricate, not just single page applications, but, you know, multi page applications with different levels of authentication for different users.
And, you know, interactions with databases and, you know, interactions with databases and they go both ways.
So it's really the sky's the sky's the limit.
It is actually possible to build, you know, production quality apps used by many people fully in Streamlit.
And, you know, and in fact, to do so really as a data scientist or as a machine learning engineer without having to learn and then wield a pretty complicated and, you know, quote unquote pro tech stack.
Like, you know, Flask and then CSS, JavaScript, HTML, React, whatever it is.
That we love those tools.
For that matter, we wrote Streamlit in those tools.
So we really love them.
But we recognize that for a lot of people, even if they do know them, it's a big lift to start building an app in that way.
And it's really fun to not have to.
And you can do a lot.
Yeah, that's cool.
The other thing that's interesting and that's where that's notable, I guess, is a lot of these types of tooling that try to make things more accessible or more productive.
They say, OK, well, what you're going to do is you're going to work with our little widgets and our little libraries.
And the reason it's simple, because you don't need to learn about databases.
So you use our data library and it magically does data magic.
Right.
Yeah.
But right at the top you have of this example, you have import Altair, import Pandas, import NumPy, import OpenCV.
Right.
That's right.
I guess what I'm pointing out is like these are the tools that data scientists are already using.
They already know how to use and they're already like very effective and polished.
So it's not like, well, you can give up your Altair or your Bokeh and your Pandas and you could use our style.
Right.
That doesn't seem to be the story you're telling.
Yeah, that's right.
I think that there is a really interesting balance between simplicity, power and accessibility in regards to using other existing open source frameworks.
And one of the sort of strategies that some people have tried is we will be the platform.
We will define everything and you will live in our walled garden.
And that's how we'll make things quote unquote simple.
That's not really the ethos of open source.
Really, the ethos of open source is more like we're going to do one thing really, really well.
We're going to be modest in a sense in what we provide, but we're going to provide a great version of it that then you can mix and match with other open source tools.
And that's the ethos of Streamlit.
We do one thing, which is let you build apps.
We try to do it the best in the world, of course.
And then we get out of the way and we say, use everything that you know about existing graphing tools, just Python, all of the, you know, Snowflake, Pandas, NumPy, Scikit, Learn.
The entire Python ecosystem is just directly available to you.
Yeah, that's really cool.
It also means you're not like super tied to Streamlit if you decide actually no or whatever, right?
Totally.
Exactly.
You could say we could do it in Notebook or we could try it in Streamlit and or not, right?
Like it's, I really appreciate about that, about what you built.
This portion of Talk Python to Me is sponsored by me, Reuben Lerner, and my free video course, Ace Python Interviews.
You know, one of the most stressful parts of a job interview is when they ask you to explain a concept
or to solve a problem with Python.
Ace Python Interviews contains six hours of screencasts solving 50 beginner, intermediate, and advanced Python problems.
You can even download the Jupyter Notebooks used in the screencasts.
Give yourself an edge when you next apply for a job.
Check out Ace Python Interviews for free at talkpython.fm/ace.
I still don't fully understand how the magic works.
So I want to talk people through it.
And then maybe you can tell me like, oh, here's where the magic is.
Yeah, for sure.
All right.
So let me talk through some of the code.
I just pulled out a few little examples of things that are interesting as you go through
that self-driving demo.
So let me run past you.
Yeah.
So first of all, like I already talked about this.
You have functions.
You've got a main function at the top.
And then you've got other functions like download the files, like go and get those self-driving car model
datas and the images and whatnot.
And you've got other functions for like showing what are some of them or like running one to like run the app,
one to select different parts of the UI, one.
Yeah.
And whatnot.
So you have this broken down like a well-structured script, I guess you would say.
Like it's all self-contained in this file.
It's not like a notebook exactly.
But it is broken to function.
So I appreciate that.
I also like the fact that you put the main method at the top and then it functions below.
I always see that in mind because here's the summary of what's happening.
Here's the details, right?
It always seems to be reversed a lot of times.
That drives me crazy.
Yeah.
But so first thing is like you want to have some message on the screen that is the UI of the web app.
And the way you do that is load a markdown file and parse it and render it using like one line,
like st.markdown.
Boom.
Give it a file name.
And then that's part like a portion of the UI is that, right?
Yeah, that's right.
There's a couple of cool things to note about that.
First of all, we do let you write well-structured code, quote unquote, well-structured code if you want.
Using names, functions and stuff is great.
You also don't have to.
It literally is just a Python script.
So you could get rid of all these function calls and just write it as a script from top to bottom.
And that works too.
And you get all the interaction and everything.
But we think it's cool that you get to write some function calls and structure your code that way.
And if nothing else, it actually mostly just helps describe what's going on to the user.
Which is one of the great properties of functions.
Then the other thing that you pointed out, which is true too, is that we've did in one line of code,
we've put a giant markdown file right on your browser.
And that's the instructions for how to use the app.
And that's pretty cool.
Yeah.
It's pretty simple.
And it does exactly what you expect.
And then later on, we say, hey, if you, a couple lines down, we say, once they select which mode they want, we just get rid of that, those instructions.
And that's pretty simple also.
So it's a pretty cool little, yeah, it's a pretty simple little way to do things.
Yeah.
So that doesn't take over the whole screen.
That kind of just goes up there as like part of the UI.
And then you say, probably when you run it first, you don't have these files.
And they're like 400 megs, which is not a ton to download.
But they're not on a super fast server.
So they do take a little while to get down, actually.
Yeah, yeah.
And so what's really cool is you, you're just using requests and standard file IO to read and write them.
But as you're looping through that, reading off the stream, you have two simple lines.
You have a progress bar.
Yeah.
And you have like a text box area.
And you say progress bar dot progress.
And you give it like how far it is in the download.
And then you say the weights area.
You can say we're downloading this amount, you know, like five of 10, five of 400 megs.
Or whatever.
Yeah, yeah, yeah.
5.1, 5.2.
And as you're looping, you're changing those values.
And that is just dynamically changing the web app.
Yeah, yeah, yeah.
That's part of the magic right there for me, I think.
Oh, my God.
I'm so excited that you've been reading the code at this level.
I mean, what delight to talk about this.
Yeah.
So that's the next bit of magic, which is you can think of it as like a sort of, you know, magical print statement.
Yeah.
Instead of saying print blah, you say st dot write blah.
And then you can just pop things on the web browser screen from top to bottom.
Markdown, data frames, graphs, anything you want.
But the next bit of magic is that those things that you put on the screen are not just stuck there.
You can reach out to any one of them and say, hey, I want to change you.
And for example, I want to take this progress bar and move it from 51% to 52%.
Or I want to take this text and I want to change it from foo to bar.
That ability to reach into the web page that you just created in pure Python and just update things is animation.
And then you throw that into a loop and all of a sudden you have progress bars going from left to right and download information.
And it's really no more complicated than just writing a script.
Yeah.
And it looks to me like the visual layout story here is like kind of a column layout on the main screen.
So I just throw stuff into the UI.
Like I say, I want to dial, I want a text area.
So I just create a like a warning text area or whatever.
And I create a progress bar.
I just say I'm creating one and it just, it piles, it sort of visually piles up like one after another vertically.
Right.
So you don't, there's not a lot of position this at X, Y here, or like set this to like dock this style.
It's kind of, you put them, there doesn't feel like I'm doing UI.
It kind of just figures it out.
I guess what I'm talking about.
Yeah, exactly.
The paradigm is just like a print statement.
It's just from top to bottom.
And this is a, you know, I think that's the right default behavior.
It's worth pointing out that the community has been saying for months, we want horizontal layout.
We want more control.
Yeah, yeah, no.
I just want to put something to the right or something else, not just below it.
And I want to say to all you programmers out there, we totally hear you.
We are super excited about horizontal layout.
It's coming.
It's in the lab.
We're working on some other really cool stuff like custom components
that lets you insert your own custom widgets into the, into the streamlet page.
Those are coming first.
We're still a small team.
We're also really trying to hire as fast as possible, but, but, you know, great programmers.
So all of these, we feel a lot of pressure to get things out and we really hear you and we're getting it out.
Please give us some time.
And if you're, if you feel like you're the right person for the job, come join us and we'll work with you too that way.
Yeah.
Very cool.
It's awesome that you're hiring.
One other thing.
So I guess that I can see how that works.
So I have a progress bar.
I call progress.
It kicks off some asynchronous JavaScript event.
That's going to go over and tell that progress bar to update.
But the other part that this is where I was thinking more of the magic is like, if I want, say a slider that people can interact with, I can go over there and I can say, go and put a slider on the sidebar and then just ask some questions about it.
And I don't see anywhere, some kind of callback for when the slider changes.
I'm just getting that information.
Yeah.
And yeah, it's really interesting how the user interaction kind of comes back into the script.
Yeah.
Maybe tell me how that kind of works because I don't totally see like where the user interaction response starts versus like setting up things and so on.
Yeah.
First of all, I'll point out that this was just a suggestion by a user.
And so this is an example of our user community really just having being the source of the best ideas in Streamlit.
And he said, hey, you just you should have a checkbox that should just be like, you know, the answer equals checkbox.
And that's how it should work.
That's blocking.
What am I going to do?
Like, that's impossible.
There's no way to do that.
But we then went back to the, you know, the whiteboard, basically, and we asked ourselves, how can we do just that?
And so the way it works is that if you ever want to have an interactive element in your app, you basically just say the answer equals and then the widget type.
So the widget type could be a checkbox and then the answer will be true or false.
It could be a text input and then the answer will be a string.
It could be a number input or a slider and you'll get numbers and so on and so forth.
You can even have file inputs.
You can get, we're working on a color clicker.
So there's a lot of cool stuff you can do.
Okay.
But this really simple model, no callbacks, just it's like at this moment, I want to materialize this variable and I want to let the user select it.
It's similar to like, if you had done like print, which of these three options do you want?
Input, parse it as an integer, right?
Like it's the blocking, it looks like blocking calls.
It looks like a blocking call.
Yeah.
And in fact, the goal is that you could just, is that you can just say, you know, this is a very typical thing when you're scripting is you say like, you know, number of iterations equals 50.
And then you just keep coding, coding, coding, coding, coding.
And then you say to yourself, you know, hey, it would be really nice if someone could select the number of iterations.
I don't have to keep editing this text file.
So then you just go to that one line of code and you say number of iterations equals st.number input.
Default equals 50.
And then boom, in your app, suddenly there's a place where the user can select that.
And if they do change it, what happens is the app runs from top to bottom.
And at that exact moment when that call happens, we substitute 50 for whatever number the user typed in.
I see.
So the function is basically rerun.
That's right.
It's sort of been seeded to say, if they ask, tell them it was this.
Okay.
That's exactly right.
So the script is rerun.
And so as a result of that, it is helpful if your scripts run quickly.
And so we...
It's a true statement, but if you're going to rerun it a lot, it's really helpful.
Exactly.
And so we provide a bunch of primitives that help you sort of reuse bits of your script
so that from the previous run, so that it does run quickly.
Yeah.
I did notice that from the code there, that there's a lot of caching type of things, but I didn't
realize that it was to facilitate what you're talking about here.
Yeah.
So you can go to a lot of these functions and you can put a decorator, a cache decorator,
and you can even say show spinner true, show spinner false.
Here's the hashing function to determine if the input is the same or not the same.
It feels a little bit like the functools LRU cache last recent, yeah, the LRU cache.
Yeah.
To basically just say, look at the arguments.
If the input's the same, then when you already have the output just here.
Yeah, that's right.
That's exactly right.
So it is very, it is exactly that idea, which for CS nerds out there is also called memoization.
And it really, it comes down to a super simple idea, which is you write a little function
and it takes some arc inputs and it gives you back some outputs.
And then you decorate it with this little Python decorator.
And then lo and behold, if you run it again on the same inputs, it just returns the same
output without actually doing the computation.
And that's a very useful thing in general.
And it's a very useful thing in particular in Streamlit because it lets you write these
much more performant apps.
It's also, I would say, one of the greatest sources of confusion about how Streamlit works.
You know, as people who are really trying to create easy and simple to understand tools,
it is a source of some degree of chagrin and embarrassment for us that this part of Streamlit
is a little bit complicated.
And so we have been working on a bunch of other simpler abstractions that we're going to release
that will hopefully make this easier to understand.
Cool.
Yeah.
So maybe that's a good place to talk about the future.
You wrote, you published a roadmap for 2020.
Yeah.
Yeah, yeah, yeah, yeah.
There's two basic things that we're working on.
So one of them is Streamlit for Teams.
And so that is the sort of auto deploy version of Streamlit.
And that lets you basically just check, you know, your apps into GitHub and then deploy
them instantly.
And in fact, we are planning to release a version such that if your app is open source on GitHub,
you get some amount of free hosting, which we're just super, super excited about.
Yeah.
So you're basically trying to leverage GitHub's actions and notifications to just do continuous
deployment.
All they're going to do is just commit it, right?
That's right.
Yeah.
We're really excited about that.
It's, there's a lot of sort of community apps that people put out there for the benefit
of others.
And we just feel like this is going to just totally unblock that workflow and make it really
simple.
Yeah.
You're really trying to sneak in some of these like proper CS ideas for non-TSP.
Yeah.
You could just do simple scripts, but you're going to have to set up a GitHub repo and you
have to use service control.
Oh, you can just like put whatever, but you probably should have a few functions, right?
Yeah.
Nudge, nudge.
It's cool.
Hey, I love, I love that you say that.
I think that's, I think that there's a very much element of truth to that.
But, you know, it goes both ways too.
We talk to, so, so, so Streamlitz really caught on in the, in like the enterprise, basically
much, you know, in some ways to our surprise how fast.
And so we've, we've talked to the data science teams from like 7-Eleven, Caterpillar and all
these companies.
And one of the things that we asked them is like, do you guys use source control?
And often basically the answer is yes, or it's no, but we want to.
So in a sense, I don't think we view this prescriptively so much as we think this is really where
things are going anyway.
And also we want to use the best tools out there and we want to weave them together.
That's, I think all the, you know, basically if you look through the GitHub, I mean, if
you look through the Streamlitz source code, it's almost like a roadmap of the coolest tools
in Python and then out there in the world.
And so React and all this stuff.
So we want to weave those together, you know, using the best possible tools in 2020.
And from our perspective, Git, which is not just GitHub, it's also GitLab.
And, you know, there's many incarnations is these are amazing, amazing tools that hugely
make people more productive, actually, once you understand them.
So being able to embrace them and not reinvent the wheel, but rather be sort of get out of
the way and let them do their magic is totally part of the Streamlitz.
Yeah, that's cool.
Other stuff you got on the roadmap, improved caching, which you just spoke a little bit
about some plugins, layout.
You've talked a little bit about that as well.
Yeah, yeah.
And then user programmable state is in for multi-page apps.
All those things sound very useful.
So I think right now, the experience that people have of Streamlit is this thing is awesome.
If I have this specific use case, which is an app with sliders, and you know, I don't care too much about the layout.
And if that's what you want to do, then Streamlit is just super cool.
But there are limits to that framework.
There are in terms of what's possible.
And we believe that we can sort of relax those limits to the point that Streamlit is really the best general purpose app framework for machine learning and data science.
But in order to do that, we need to think really carefully about how to introduce new sort of app abstractions like state into Streamlit really carefully so that it maintains that simplicity that people like, but gives you a little bit more power.
So the goal for 2020 is to roll out sort of the zeros of each one of these pieces of the puzzle so that by the end of the year, people can say with some degree of confidence, hey, you know, I can build this app.
It's going to go all the way.
Sure.
That's a great mission.
What's the story on authorization, authentication?
Oh, yeah.
I would like somebody to interact with this app, but I wanted to remember for them what they did or something like that.
That is part of the paid product.
People who want to create it themselves in an open source, purely open source way are welcome to do that.
But we're going to basically create really simple deployment that gives you that functionality sort of with a couple of clicks.
So you can say scope it to these people or scope it to my company or use this existing identity provider, SAML or whatnot.
And then basically create an app that is scoped to a certain number of users, both in terms of accessing the source code and also in terms of who can use the app.
Sure.
Okay, cool.
Well, Adrian, we're getting long on time here, but this has been really fun to talk about.
There's two quick things I just want to touch on before we move on.
One is we were talking a little bit before we hit record and how, like many companies, you guys are finding yourself reinventing yourself as a remote company.
Yeah.
How's that going?
I have to say that it has been a really interesting and instructive experience.
And as much as I find the whole COVID-19 very scary and I worry about my parents and my fiance's parents and all of our...
And we're getting a little stir crazy being at home all day long.
It's also a silver lining is that we've had to really think about how to build a company that works asynchronously.
We use Notion all the time, which is like the coolest app of all time.
We use Streamlitz to coordinate things.
And it's been an amazing experience.
And I think we're going to...
We've actually made a decision to start hiring anywhere in the US now instead of just in San Francisco.
I'm just so excited about that.
I mean, we recognize that there's so much talent everywhere.
And we really just assumed that we all had to be in the same room.
And I think that these past couple of weeks have kind of shattered that assumption, which is kind of mind-blowing.
Yeah.
Boy, it's a tough time in a lot of ways.
But it's also, I think, shaken up everybody's assumptions about reality for work, for family, for even simple stuff like food.
Right?
We used to get takeout a lot and whatnot.
And we're like, all right, well, we're just going to have to start making more interesting food.
So I cooked a really good dinner last night.
Totally.
But it's like...
Totally.
It's just all these different stages or parts of our life are just like, shake, shake, shake.
Let's see what, you know, shakes out what we really need or what really is the right fit.
And so it's really cool to hear that you guys are finding a silver lining in it.
Yeah.
One other one is that my son, who's eight, now he has like literally three playdates a day over like Google Hangouts.
Like he plays like, you know, Fortnite and then he plays Minecraft.
And it's like, he has a whole new social life that he never had before.
And he actually told me the other day, he's like, I'm sad.
I'm going to be sad when COVID is done because I want to have all these playdates over Hangouts with all my friends.
And I was like, you know what?
You still can.
That's never going to go away.
We just, we just figured out how to do that and you'll have it forever.
Yeah.
That's really cool.
My daughter's definitely been doing that as well.
Like she'll sit down at the Xbox with her friend and like prop up, you know, an iPad next to her.
You see, I'm feeding this character and they're doing the same.
And you know, it's like, it's, it's pretty neat in that regard.
The other thing I want to touch on, something I'm a big fan of, and I just learned about reading your bio that you were involved in,
is the Lo and Behold documentary by Van Rietzog.
Yeah.
For people who have not seen Lo and Behold, it is an incredible documentary on the history of the internet and technology in that era.
Yeah.
What was your involvement there?
That sounds fun.
I was interviewed as one of the sort of like internet pioneers because of my work with Foldit.
I was probably like the least famous person by far that day because it was like Elon Musk and all these people.
So I'm sure that they, when they watched it, they were like, who's this, you know, who's this guy?
But it was because I folded.
And you know, one of the coolest things for me was being able to meet Werner Herzog, who's just like, you know, he has a sort of shamanistic way of being in the world.
And so, you know, he gave me advice like, Adrian, if you want to understand some part of the world, you must walk through it on two feet.
How cool.
Stuff like that.
So I was like, it was really cool meeting him.
And obviously it's a legendary filmmaker.
Yeah.
Oh, how cool.
I just, if you were looking to watch something interesting, lo and behold, it's a fantastic option there.
Yeah.
All right.
Well, final two questions before I let you out of here.
If you're going to work on Streamlit or other Python code, what editor do you use?
Oh, VS Code all the way.
All right.
Right on.
Although, although I've tried in COVID, one of my little side projects has been to try to figure out how to code on my iPad.
Oh, yeah.
And so now I'm, and if anyone knows like how to do this, like tweet me your secrets, because I'm like really trying to figure this out just kind of for fun.
But on the iPad, there is no VS Code.
So I would love if there were VS Code and please someone make that happen.
I'll give you two things that you can play with that I know about.
I'm sure listeners, they can put it at the bottom of the show notes, the comments on the episode page and we'll make sure you get those as well.
Yeah.
But one is Carnet, C-A-R-N-E-T-S.
Oh.
It's local Jupyter Notebooks for iOS, like no network everything, which is, if you're willing to do notebooks, it's JupyterLab on your iPad.
That's awesome.
It's pretty cool.
I think it might even be open source.
I'm not sure.
And then you can set up Visual Studio Code online.
So Visual Studio online.
And then run that.
I think you can run that in your web browser and basically get VS Code.
I've been trying to do that and I cannot get it to work.
Is it working?
Yeah.
I can.
It doesn't.
The iPad browser just doesn't quite like have it.
It's missing a couple of things that.
So I've been, that's been my, I've been trying to do that.
And maybe I'm getting something wrong.
So anyway.
Maybe.
I do feel like that's actually one of the big mistakes that Apple has made is not allowing any innovation on web browsers on their platform.
Totally.
That's just bizarre to me.
So anyway.
Yeah.
Cool.
All right.
And then notable PyPI package.
Something, some Python package that you're like, maybe it's not the most popular, but like, wow, people should know about this.
And I mean, obviously, if it's all streamlet is one option, but if it's anything else that comes to mind, I guess, I don't know how I'm famous.
This is.
I think it's semi-famous, but I would really get tell people that I want to shout out to Altair.
Basically, you know, a lot of people know Matplotlib.
A lot of people know Plotly.
A lot of people know Bokeh.
I think Altair is a little less famous.
The short story is they took D3, which is this legendary thing.
They simplified it into a declarative JSON language called Vega, but that was way too complicated.
So they simplified that into an even simpler language called Vega Lite.
And then someone created, at Google, created Python bindings for that, and it's called Altair.
And this thing, it's its own philosophy, man.
But when you learn it, it is so cool and creates beautiful graphs and they're interactive and they just look great and they're easy to create.
And I just think Altair is great.
Awesome.
Yeah, I've definitely heard good things from Altair.
Yeah.
About Altair.
So a good recommendation.
All right, Adrian.
Final call to action.
People are excited about Streamlit.
Want to check it out.
Do more with it.
What do you say?
Go for it.
Super fun.
Streamlit.io or just pip install Streamlit.
And then type Streamlit that hello on the command line and you'll be playing with interactive stuff in minutes.
Well, thanks for being on the show.
It's been really great to talk to you about your project.
Yeah.
Thanks so much, Mike.
I really appreciate it.
You're welcome.
Bye-bye.
All right.
Take care.
Bye.
This has been another episode of Talk Python to Me.
Our guest on this episode is Adrian Troiel.
And it's been brought to you by Linode and Reuven Lerner's Ace Python Interviews course.
Start your next Python project on Linode's state-of-the-art cloud service.
Just visit talkpython.fm/Linode.
L-I-N-O-D-E.
You'll automatically get a $20 credit when you create a new account.
Ace that Python interview.
Let Reuven Lerner's course help you get that next Python job.
Just visit talkpython.fm/ace to take his free course.
Want to level up your Python?
If you're just getting started, try my Python Jumpstart by Building 10 Apps course.
Or if you're looking for something more advanced, check out our new async course that digs into all the different types of async programming you can do in Python.
And of course, if you're interested in more than one of these, be sure to check out our Everything Bundle.
It's like a subscription that never expires.
Be sure to subscribe to the show.
Open your favorite podcatcher and search for Python.
We should be right at the top.
You can also find the iTunes feed at /itunes, the Google Play feed at /play, and the direct RSS feed at /rss on talkpython.fm.
This is your host, Michael Kennedy.
Thanks so much for listening.
I really appreciate it.
Now get out there and write some Python code.
I really appreciate it.