Latest / Talk Python To Me / #299: Personal search engine with datasette and dogsheep
Transcript
- 0:00In this episode, we'll be discussing two powerful tools for data reporting and exploration,
- 0:05Dataset and Dogsheep.
- 0:06Dataset helps people take data of any size or shape, analyze and explore it, and publish
- 0:12it as an interactive website and an accompanying API.
- 0:14Dogsheep is a collection of tools for personal analytics using SQLite and Dataset.
- 0:20Imagine a unified search engine for everything personal in your life, such as Twitter, photos,
- 0:25Google Docs, Todoist, Goodreads, and more, all in one place and outside of the cloud companies.
- 0:30On this episode, we talk with Simon Willison, who created both of these projects.
- 0:34He's also one of the co-creators of Django, and will discuss some of the early Django history.
- 0:39This is Talk By The Nome, episode 299, recorded November 18th, 2020.
- 0:44Welcome to Talk Python To Me, a weekly podcast on Python, the language, the libraries, the
- 1:02ecosystem, and the personalities.
- 1:03This is your host, Michael Kennedy.
- 1:05Follow me on Twitter, where I'm @mkennedy, and keep up with the show and listen to past
- 1:09episodes at talkpython.fm, and follow the show on Twitter via at Talk Python.
- 1:14This episode is brought to you by Linode and Talk Python Training.
- 1:18Please check out the offers during their segments.
- 1:20It really helps support the show.
- 1:22Simon, welcome to Talk Python To Me.
- 1:24Hi, great to be here.
- 1:25Hey, it's great to have you here.
- 1:26We're going to talk about some really interesting projects that you've been working on, some
- 1:31that are extremely broad and far-reaching, and anybody who touches Python or maybe even
- 1:36knows about it, and then another, which I feel is such a personal project.
- 1:40It's for everybody, but it reveals so much data about you, you know?
- 1:44Absolutely, yeah.
- 1:45We're going to talk about Django a little bit, which you were part of creating.
- 1:49We're going to talk about data set, which is a way to interact, basically put a UI on
- 1:55top of any database in a friendly way that lets you explore it and treat it as an API.
- 1:59And then Dog Sheep, which has a funny name, nice story around the name, that allows you
- 2:05to basically take all of the data about you and turn it into your own Google.
- 2:10Right.
- 2:10It's your personal data warehouse, I've started calling it.
- 2:13I'm fascinated by where that could go.
- 2:15Now, before we get to all three of those cool things, let's just start with your story.
- 2:18How did you get into programming into Python?
- 2:20I learned to program with my dad on a Commodore 64 back in the 80s, and then kind of moved on
- 2:27to early Windows and DOS, where you didn't really get to program anything from QBasic.
- 2:31But I got really into programming when actually during the first dot-com boom, like even like
- 2:37Web 1.0, 1999, 2000, when I was working in London for a online gaming company, a company
- 2:45called Gameplay.com, which was doing like selling boxed games where you mail ordered them, but
- 2:50also running online gaming servers for like Team Fortress Classic and Half-Life and Quake and
- 2:55all of those kinds of things.
- 2:56Oh, yeah.
- 2:56Team Fortress and Counter-Strike.
- 2:58I love that stuff.
- 2:59That was so fun.
- 3:00Oh, absolutely.
- 3:01And so I was working for their online gaming division for a year and a half before the
- 3:06dot-com crash and everyone got laid off and it all collapsed.
- 3:09But during that time, I started the company as the downloads editor, so responsible for
- 3:14the section of the website where you download plugins and patches and mods and so forth.
- 3:19And I essentially taught myself web development as part of that and as part of some other gaming
- 3:24related side projects I had.
- 3:25And so, yeah, I'm a veteran of the first round of dot-coms back when no one had a slight
- 3:31idea what we were doing.
- 3:32Yeah, yeah.
- 3:32Everyone was just making it up on the spot, right?
- 3:34Oh, totally.
- 3:35So when you were working on that web development stuff, it probably wasn't Python, I'm guessing.
- 3:39Certainly wasn't Django because Django was what, 2005?
- 3:422003, 2004 when we built it.
- 3:45I think it was open sourced in 2005.
- 3:47Yeah.
- 3:47Right, right.
- 3:48Okay, so what were you programming then?
- 3:49Oh, so Gameplay.com was running on a vastly expensive content management system called Media
- 3:55Surface, which was a combination of Perl for templates, Java and Oracle under the hood and
- 4:01insanely expensive and very, very tricky to get things done with.
- 4:06And then I had side projects which were classic PHP and MySQL.
- 4:09Right.
- 4:09So I was very much the sort of the classic PHP programmer.
- 4:13And actually, I mean, this is where Django came from is Adrian Holabati and I were working
- 4:18together at this local newspaper in Lawrence, Kansas.
- 4:20And we were both PHP developers and we saw the siren call of Python and wanted to figure out
- 4:26how we could build websites using this.
- 4:28We felt much more exciting programming language.
- 4:31Oh, that's awesome.
- 4:31It's definitely more exciting.
- 4:33But I do want to ask you, it's such a different world, right?
- 4:36We can go to the cloud providers and pay $5 a month and probably get better infrastructure
- 4:42than you guys had.
- 4:43I mean, who knows how much, right?
- 4:44Enormously.
- 4:45I mean, back then, a content management system, because you could spend a million dollars on
- 4:49your content management system.
- 4:50And they were terrible because nobody knew what a good content management system looked like.
- 4:55This was back before things like WordPress as well.
- 4:57Like your only option was to spend huge amounts of money on these like giant enterprise systems
- 5:03and then cross your fingers and hope that they could work for you.
- 5:05Yeah.
- 5:06So how did you feel when you worked, you go to work, you work in this kind of like ultra
- 5:11expensive, clunky environment and then go home.
- 5:13And even though it was PHP, still like do PHP and MySQL and kind of like, I paid nothing
- 5:17for this.
- 5:18It maybe felt as good as what this crazy online system you guys are working with.
- 5:21What was that back and forth like?
- 5:23I don't think it did feel nearly as good, to be honest, because there was no open source
- 5:26was still just starting up.
- 5:27So if you wanted to build something in MySQL, you wrote everything.
- 5:31Oh my goodness.
- 5:33You would start with the authentication system and work on it from there.
- 5:36So to be honest, I feel like today, like open source for me has solved the whole code
- 5:42reuse problem.
- 5:43How do we stop wasting our time to rebuilding the same things over and over again?
- 5:46But yet, you know, 20 years ago, you just built everything from scratch and everything
- 5:51took months to do.
- 5:52It's really interesting because I started out in C++ and I felt like a lot of the stuff
- 5:57I built was extremely low level, not just because it was C++, but because of this sort of difference
- 6:02that you're talking about.
- 6:03And throughout the years, I've seen it just get like what used to be really hard is now
- 6:09just grab this library and plug it in.
- 6:10That other thing used to be hard, grab this library and plug it in.
- 6:12And it just seems like the natural consequence would be, well, we need fewer developers because
- 6:17they used to have to build this.
- 6:18Now they plug it together.
- 6:19And yet all we've done is decided to solve more ambitious problems.
- 6:22Absolutely.
- 6:23In more interesting ways, right?
- 6:24It amazes me the quality of software that we build these days, you know, like 10, 15 years
- 6:30ago, we weren't writing tests for everything.
- 6:32You know, the quality of the stuff we wrote was just abysmal.
- 6:34And today we've got continuous integration and continuous deployment.
- 6:38And it's really quite, it's really easy to get out there and analyze like 15 different
- 6:42options and pick the one that's most, the one that is the highest quality.
- 6:46Not only do you have CI/CD, you've got it for free in the cloud on demand, you know, on actions
- 6:52that trigger it, right?
- 6:53It's just, it's such a cool place, a cool time to be doing this stuff.
- 6:55Definitely.
- 6:56Yeah.
- 6:56Yeah.
- 6:57So before we get to Django, how about now?
- 6:59What are you up to these days?
- 7:00So these days I spent the last year at Stanford University doing a fellowship.
- 7:05There's a fellowship program called JSK and it's journalism fellowships.
- 7:10The idea is to get sort of journalists from around the world together at Stanford for a year,
- 7:14thinking about problems facing journalism.
- 7:17And I managed to make my own to it as a sort of computer scientist with journalism leanings.
- 7:22And basically thinking about, okay, what are the open source tools that I can build that
- 7:27can help make data journalism more powerful, more widely accessible?
- 7:31And so a lot of the data set project was really accelerated by doing that.
- 7:36It finished a few months ago.
- 7:38The problem I'm having is that at Stanford, I was essentially paid to tinker on my own
- 7:43projects and go after whatever I thought was interesting.
- 7:46That sounds good.
- 7:46And it's great, but I'm having real trouble stopping.
- 7:48So now I'm not getting paid, but I'm tinkering on my own projects, going after things I find
- 7:53interesting.
- 7:53So I'm calling myself a consultant and I am available for consulting opportunities, especially
- 7:59around the sort of set of tools that I've been building.
- 8:02But mainly, yeah, I'm focusing on continuing to build out this ecosystem of tooling for
- 8:07data journalism and related projects.
- 8:09Yeah.
- 8:09Well, we're going to get to those.
- 8:11And they're definitely super interesting, the ones.
- 8:13And like I said, this personal aspect, I think that could help a lot of people, not just journalists
- 8:17for sure.
- 8:18But let's talk a little bit about Django.
- 8:20You mentioned that it came out of, what was it?
- 8:22Journal Lawrence?
- 8:23Lawrence Journal World or something like that?
- 8:25Journal World.
- 8:26Yeah, it's a tiny newspaper in Lawrence, Kansas, a town I'd never even heard of.
- 8:31And this was back in 2002, 2003.
- 8:34I was a blogger.
- 8:35I had a blog about web development and about 100 other people had blogs about web development.
- 8:40So we all read each other's blogs.
- 8:41And Adrian Holovaty, who was a journalism and programmer, posted a job ad on his blog saying,
- 8:48hey, I want somebody to come and join me in Lawrence, Kansas, building websites for local
- 8:51newspapers.
- 8:52And it coincided with my university course, giving me the option to spend a year in industry,
- 8:57which is something that UK degrees do quite often.
- 9:00So I could take a year out, get a student visa, which means I could track traveling, work in
- 9:06different countries, spend a year working, and then go back and finish my degree.
- 9:09And so the opportunities sort of aligned themselves.
- 9:12And I had huge respect from Adrian, just based on what I'd seen that he'd been doing.
- 9:16And it felt like a pretty interesting adventure to run off to Kansas.
- 9:19Yeah, yeah.
- 9:20That's a cool adventure.
- 9:21And yes, so I did that.
- 9:22So essentially, it was a year long, almost a paid internship.
- 9:26But it was in Lawrence, Kansas at this little newspaper.
- 9:29And it was a fascinating place because the family that owned the newspaper had laid fiber optic
- 9:35cable around a bunch of states like a bunch of years beforehand, when everyone thought they
- 9:39were crazy, and then sold the whole lot to maybe Comcast, one of these big companies.
- 9:44So financially, they were very secure, which meant they could invest huge resources in their
- 9:49local newspaper for this little town.
- 9:51And so this newspaper, despite serving a town with a population of like 100,000 people,
- 9:55it had way, way more resources than you would expect any local newspaper to have.
- 9:59They had their own software engineering team who were building out the websites for things.
- 10:03And because the family owned the local cable company for the town.
- 10:06So everyone in the town of Lawrence, Kansas had broadband internet in 2003.
- 10:12And that meant that the news websites could have like online videos and stuff, which no one else was doing, because what newspaper had an audience who could actually watch that kind of stuff.
- 10:20So it was a really exciting place to be inventing like things around online news.
- 10:26And we also had a very ambitious boss, this chap called Rob Curley, who basically wanted us to act like we were the New York Times, even though we were like six nerds in a basement somewhere.
- 10:39This little local newspaper.
- 10:40We had things like the local, there was a softball league where all of the local kids in softball teams competing against each other.
- 10:48And it turns out this is an amazing thing for a local newspaper to cover, because if you have good coverage of the softball league, everyone who knows a child in your town will buy your newspaper.
- 10:56So we went all in on kids softball and we ended up building a website for them that treated them.
- 11:02The idea was to treat them like the New York Yankees.
- 11:04So we had like player profiles and match reports and photo galleries.
- 11:08And then we sent two interns out to take 360 degree photographs of every softball pitch in town.
- 11:15And we had those on the website.
- 11:17And this was like quick VR or something.
- 11:19It was absolutely astonishing.
- 11:21That's so, so neat in the early days.
- 11:23Like, I'm sure the kids felt so special as well.
- 11:25I bet they still have like saved copies of their time.
- 11:29The best website we worked on was there was a local entertainment portal for the town of Lawrence, Kansas.
- 11:34And it was basically a website that had the events calendar.
- 11:37It had band profiles.
- 11:38It had restaurant reviews.
- 11:40It was like sort of a super hyper local version of Yelp crossed with music magazines,
- 11:46crossed with an events website just for this one little town.
- 11:49And we had features like there was a downloads page where you could download MP3s of bands who were playing in town that week.
- 11:58Because we had the MP3s for all of the local bands, again, in like 2003.
- 12:02And a little radio widget that you could click play on and stuff.
- 12:05It was astonishing.
- 12:06I have never seen an entertainment website since that was as good as this one that we were building back in Lawrence, Kansas.
- 12:15This portion of Talk Python To Me is sponsored by Linode.
- 12:17Simplify your infrastructure and cut your cloud bills in half with Linode's Linux virtual machines.
- 12:21Develop, deploy, and scale your modern applications faster and easier.
- 12:25Whether you're developing a personal project or managing large workloads,
- 12:29you deserve simple, affordable, and accessible cloud computing solutions.
- 12:33As listeners of Talk Python To Me, you'll get a $100 free credit.
- 12:37You can find all the details at talkpython.fm/Linode.
- 12:41Linode has data centers around the world with the same simple and consistent pricing regardless of location.
- 12:47Just choose the data center that's nearest to your users.
- 12:50You'll also receive 24-7-365 human support with no tiers or handoffs regardless of your plan size.
- 12:56You can choose shared and dedicated compute instances,
- 13:00or you can use your $100 in credit on S3-compatible object storage,
- 13:04managed Kubernetes clusters, and more.
- 13:07If it runs on Linux, it runs on Linode.
- 13:09Visit talkpython.fm/Linode or click the link in your show notes,
- 13:14then click that create free account button to get started.
- 13:18I have a history with Lawrence.
- 13:20I actually went to college there and got my math degree at University of Kansas.
- 13:24No way!
- 13:24I love that town.
- 13:25I love it.
- 13:26The Mass Street little downtown with Mass Street Brewery and all that was such a beautiful place.
- 13:31I really enjoyed my time there.
- 13:33Yeah, it's a great town.
- 13:34I think when I was there, I'd never been to anywhere else in America, basically.
- 13:38So it felt like a cool town, but I didn't really understand how cool it was until 20 years later.
- 13:43I've now lived in America, and I've been to lots of towns, and Lawrence is special.
- 13:47It's a very special.
- 13:49It definitely is.
- 13:50But what I never knew was how cool this newspaper was.
- 13:54I mean, I was just like a kid in college.
- 13:56I didn't read the newspaper a lot and whatnot.
- 13:58So this is a really interesting cradle from which Django sprung.
- 14:02So tell us about Django and how it fits into this world.
- 14:06Sure.
- 14:06So basically, Adrian and I, Adrian had built Lawrence.com, this amazing assignments website, in PHP.
- 14:11And both Adrian and I had hit that point in our PHP careers where it was straining under the size and complexity of the things that we wanted to do with it.
- 14:20This was like before PHP 4 even.
- 14:22So classes were very new, and the PHP language was pretty primitive compared to what you have today.
- 14:29And meanwhile, Python was exploding in popularity.
- 14:31We were both huge fans of Mark Pilgrim's Dive Into Python and Mark Pilgrim's blog where he talked about this.
- 14:37And so we decided that we really wanted to be working with Python for building these websites.
- 14:41But the web options back then were not particularly – the main thing was Zope.
- 14:46And Zope was pretty good, but it didn't match the way Adrian and I thought about the web.
- 14:51We cleared about things like designing our URLs carefully and separating our CSS from our HTML.
- 14:56The sort of modern MVC framework that people almost take for granted now, right?
- 15:00Exactly.
- 15:01But there weren't really any great options for that in Python.
- 15:04So we were looking at ModPython, the Apache module, as the way that we would put Python on the Internet.
- 15:10And we were a little bit worried about it because ModPython wasn't being used very widely.
- 15:14And we're like, okay, what happens if we bet the newspaper on ModPython and it turns out not to work, right?
- 15:20That would be –
- 15:21Yeah, yeah, yeah, yeah.
- 15:22So we said, okay, what we'll do, we'll have a very thin abstraction layer between us and ModPython so that if we have to swap ModPython for something else, we can do so.
- 15:29And that basically is what – well, that was the initial seed to Django.
- 15:33We wanted a request and response object, a basic way of doing templating, basic URL routing.
- 15:38And so we built that out.
- 15:39And we never thought it was a framework.
- 15:41We called it the CMS, right?
- 15:43It was the CMS of the newspaper.
- 15:45And it kept on evolving these additional little bits and pieces.
- 15:48Django admin was something which I went away to the South by Southwest Festival for like four days.
- 15:54And when I came back, Adrian had written a code generator for admin websites that was churning out all of this stuff.
- 16:00We just kept on building these extra bits out.
- 16:03And then I went back to England.
- 16:04My year in Kansas ended.
- 16:06And about six months later, they open-sourced Django.
- 16:09At the time I was working, it wasn't called Django.
- 16:11There were various ideas for names, which are truly terrible.
- 16:14But yeah, Jacob Kaplan Moss had joined the team at that point.
- 16:18And yeah, they made the case to the newspaper that they should open-source this thing.
- 16:21That's early days for that, right?
- 16:23Like it's not – like now it would be easy sell.
- 16:25But back then that was weird, right?
- 16:26Well, yeah.
- 16:27I asked them about this.
- 16:28And apparently one of the arguments they used is Ruby on Rails had just come out and was just exploding in popularity.
- 16:34And they could see that this company that released Rails was hiring people left, right, and center and was doing really well out of it.
- 16:39So they went to the newspaper and said, hey, look, if we open-source this, it's a great way for us to get talent and get free fixes and all of that sort of thing.
- 16:47And it worked.
- 16:48Like you and I are sitting here talking about this small newspaper in Lawrence right now, right?
- 16:52I mean, we wouldn't be doing this otherwise.
- 16:54That's true.
- 16:54But the argument that worked is they said to the newspaper owners, we've been building on open-source, right?
- 17:00The newspaper – we run Linux and we run Apache and Perl and Python and we've used all of this open-source stuff.
- 17:05This is a way of us giving back.
- 17:07And that's the argument that apparently resonated with them.
- 17:08They said, no, that completely makes sense.
- 17:10We can give back in that way.
- 17:12And yeah, and so Django open-sourced and it's been – that was 15 years ago, I think.
- 17:16And it's just been growing in it ever since.
- 17:18Yeah.
- 17:19Did you predict – like you look around now, it's just ubiquitous.
- 17:22Like does it blow you away what's happened?
- 17:24Completely blows me away.
- 17:25The thing that really amuses me is that I keep on seeing people talking about Django as the boring option.
- 17:31And like Django and Rails, yeah, those are the safe, boring options for things.
- 17:34And I actually saw someone on Twitter the other day say, well, nobody ever got fired for choosing Django.
- 17:39And I was like – I actually – I direct messaged Adrian and Jacob with that quote.
- 17:44I'm like, can you believe this?
- 17:45That we are now – no one ever got fired for choosing IBM option for web framework.
- 17:49Exactly.
- 17:50Exactly.
- 17:50Amazing.
- 17:51Yeah.
- 17:52I think there's definitely some truth to that.
- 17:54Quite interesting.
- 17:54It seems like it's got a ton of momentum.
- 17:57It's really starting to embrace the async and await world.
- 18:00It looks strong.
- 18:01Yeah.
- 18:02So a lot of my projects these days don't use Django, but they do use ASCII.
- 18:07I am really into the whole – the ASCII ecosystem that's growing up is so exciting.
- 18:12And Django is getting better at ASCII itself, so I'm going to be able to merge a bunch of my ASCII projects back into my Django projects pretty soon, which is super exciting.
- 18:20Yeah, that's exciting.
- 18:21I'm super excited about FastAPI, and it's one of those that fits really well in that world.
- 18:26Yeah.
- 18:26I mean, I haven't really done FastAPI, but I love Starlet, which is the framework.
- 18:30Yes, that's the foundation.
- 18:31Yeah.
- 18:31Yeah.
- 18:32Yeah, super cool.
- 18:33All right.
- 18:33Well, congratulations on Django to you and everyone who worked on it.
- 18:37I do think it's really interesting.
- 18:39If you look at the timing, Ruby on Rails came out of 37 Signals, now Basecamp, and was extracted from – they were using inside, right?
- 18:48Yeah.
- 18:48And they built it for them and extracted it.
- 18:50You guys built it at the newspaper and said, this thing we can pull out of and make it something else.
- 18:56I think it's really interesting that it was sort of polished and proven in this real place, right?
- 19:01I think the way I see it is Rails was extracted from Basecamp, right?
- 19:05They built Basecamp up.
- 19:06They pulled a framework out of it.
- 19:07Django, the goal was always Lawrence.com.
- 19:10We had this entertainment website and PHP and MySQL, and we knew that we wanted the thing we were building to power that.
- 19:16So Django was actually – there was an existing target, and we evolved the functionality of the framework until it could run a very high-quality newspaper, entertainment, listings, website.
- 19:27And so it's almost – it's like one was extracted and one was evolved in the direction of supporting this one site.
- 19:34Yeah.
- 19:34It's neat to see.
- 19:35I think they both came out quite successful from those experiences.
- 19:39All right.
- 19:39Let's start at the foundation of this recent work you've been doing.
- 19:43And in some sense, it's sort of a natural progression, right?
- 19:47It's in the journalism side of things is where the origin came from.
- 19:50So tell us about Dataset.
- 19:52So Dataset is – on its website, I call it an open-source multi-tool for exploring and publishing data.
- 19:59Basically, it's a web application which you can point at a SQLite relational database, and it gives you pages where you can browse the tables and run queries.
- 20:08It lets you type in custom SQL queries and run them against that database.
- 20:13It lets you custom templates and how things turn.
- 20:15It lets you get everything back out as JSON or CSV so you can use it for API integrations.
- 20:20And it lets you publish the whole thing on the internet really easily.
- 20:23So it's a lot.
- 20:24Yeah.
- 20:25And one of the biggest challenges I've had is how do I turn this into a bite-sized description that really helps people understand what the software does.
- 20:33I'm at a point now where if I can get somebody on a video chat, I can do a 15-minute demo, and at the end of it, they come out going, I totally get this.
- 20:40This is amazing.
- 20:41But that's not explaining software.
- 20:44It doesn't scale particularly well.
- 20:46Yeah.
- 20:47Yeah.
- 20:47Well, let me see if I can, with my limited exposure to it and knowing somewhat where we're going, you have this data source that's pretty ubiquitous or can become ubiquitous in terms of like some sort of ETL with SQLite, right?
- 21:00SQLite is everywhere.
- 21:02What's beautiful about it is there's no, please set up the server and make it not run as root and then put it on your network and so on.
- 21:08Yeah.
- 21:09Right?
- 21:09It's the magic of SQLite.
- 21:10SQLite, it boasts it's the most widely distributed database in the world, which it is because it runs on every phone.
- 21:17My watch has SQLite tracking my steps.
- 21:19Every iPhone app, every Android app, every laptop, they're all running these.
- 21:24Yeah.
- 21:24Yeah.
- 21:24Your phone.
- 21:25That's crazy.
- 21:25It's a file format, right?
- 21:27It's a SQLite database is a single .db binary file on disk, which like you said, makes it so convenient because I don't have to ask a sysadmin to set me up a Postgres schema or anything like that.
- 21:39I just create a file on my laptop and that's my new database.
- 21:42Yeah.
- 21:43And it's even built into Python, right?
- 21:44It just comes with Python.
- 21:46Yeah.
- 21:46It ships in the standard library.
- 21:48Yeah, exactly.
- 21:48So that's super cool.
- 21:50And it's great that we have this data format that if we either have data in there or you could do like an API call and then jam the data in there, right?
- 21:59Like something to get it into that format, which is great.
- 22:02But you can explore that with like Beekeeper Studio or some data visualization, SQL Management Studio.
- 22:09But that doesn't work for journalists.
- 22:11That doesn't work for getting it on the internet.
- 22:14That doesn't give you like the transformations.
- 22:16In some sense, I kind of see it almost like as a really advanced web-based like data IDE, but user-friendly.
- 22:25Kind of.
- 22:25Yeah.
- 22:26But the emphasis is absolutely on publishing.
- 22:29It's on getting it online.
- 22:30And then it's on being web native.
- 22:32Like everything in dataset can be got out as JSON as well as HTML.
- 22:35It can all get beat.
- 22:36It can return CSV to you.
- 22:38It uses you pass the SQL query in a get in a query string so you can bookmark queries, all of that kind of stuff.
- 22:45Yeah.
- 22:45I think the key, that's really the key idea.
- 22:47It's how do you take relational databases and make them as web native as possible and as cheap and inexpensive to host and to run as possible.
- 22:55So you can take any data that fits in a SQLite database, which is almost everything, and stick it online in a way that people can both explore it and start like integrating with it as well.
- 23:06And another key idea in dataset is dataset has a plugin system.
- 23:10I've actually written over 50 plugins for it now that add all sorts of different things, different output formats to get your database out as an Atom feed or an iCal feed.
- 23:19I've got plugins for visualizations that plot your data on a map or give you charts and line graphs and so on.
- 23:25I just this morning released a authentication plugin that supports the IndieAuth authentication mechanism.
- 23:31So you can use IndieAuth login to password protect your data, all of these different things.
- 23:37And honestly, having a plugin system is so much fun because I can come up with a terrible idea for a feature and I can build it to plugin.
- 23:44And it doesn't matter that that's just an awful idea that nobody should ever have implemented because I'm not causing any harm to that core project.
- 23:53It's a super interesting idea.
- 23:54I also think it might be a way to encourage others to contribute because they don't have to understand the whole system and be afraid of breaking it.
- 24:01They just have to understand, like, here's the three functions I implement to make this happen.
- 24:05Real dream there is when people contribute to open source, that's more work for me because I have to review their pull requests and figure it out and so on.
- 24:11If you write a plugin, you can release that plugin to the Python package index and I don't even have to know about it.
- 24:17Like, I can wake up one day and my software has new features because somebody built a plugin and shipped it, which I think is fantastic.
- 24:24It's fantastic.
- 24:25And they don't have to go through you as a gatekeeper, even if you might be super friendly and whatnot.
- 24:29They just don't have to have that interaction, right, which is pretty cool.
- 24:32Yeah.
- 24:33So one of the things that's interesting about Dataset is the way you get your stuff online is you basically just run Dataset against a SQLite database.
- 24:41And now you have this website that lets you explore it like you described.
- 24:44So you say Dataset space, path to a SQLite file, and now you have a web app running, right?
- 24:50So you type Dataset, name a file, hit enter, and it runs on your local laptop and you can start browsing it and exploring it.
- 24:55But then if you want to put it online, I've been building out integrations with a bunch of different hosting providers
- 25:00where you can, from the command line type, Dataset space, publish space, pick your provider, say, say Google Cloud Run, Dataset publish Cloud Run, name of database, enter.
- 25:10And it'll upload that database to the internet, wrap it in the application itself, and give it a URL and start serving.
- 25:17So it's like a one-liner for publishing data online with a URL that other people can start using.
- 25:22And that's basically, that's enabled by all of these fascinating serverless hosting providers.
- 25:28And that was actually one of the original inspirations for Dataset.
- 25:32So I was looking at server hosting and saying, okay, what can I build with this that I couldn't have built beforehand?
- 25:37And the limitation of serverless host is that they generally don't let you run databases.
- 25:41They're like, you can run like a sort of stateless application that does stuff, it's fine.
- 25:46But if you need to store data in the database, you're going to have to pay extra or get an RDS.
- 25:50Right.
- 25:51The only real option you have is please subscribe to our managed database service of some sort, which turns you into a DB admin and all sorts of stuff you don't want to be.
- 26:00The realization I had is, hold on a second, that makes sense if you have to write to your database.
- 26:04But if it's read-only, if you're publishing like interesting data sets throughout the world, which aren't going to change, why not just stick that data in SQLite and then put that .db file in as an asset as part of your source code?
- 26:17Like basically bundle it in with the application.
- 26:19Right.
- 26:20It gets loaded in AWS Lambda or whatever, just like it's right there.
- 26:24Yeah.
- 26:24It's basically a giant loophole that lets you abuse serverless host providers, which are really cheap to serve interesting relational data.
- 26:31As long as you don't need to accept rights, it just works, which I think it's kind of devious and it works incredibly well.
- 26:36Yeah.
- 26:36It's really interesting.
- 26:37One of the things that I heard you say in a talk that we'll get to in a little bit is, you know, coming from Django, Django has the beautiful Django ORM, right?
- 26:46Which is a really nice way to talk to data and manage it.
- 26:49It's not so good for completely dynamic, unknown schemas, but it's good if you know it.
- 26:54One of the cool things about ORMs that I really like is it makes it very hard to do to write bad code that has SQL injection.
- 27:01Absolutely.
- 27:02Yeah.
- 27:02Right.
- 27:03And yet what you said to me is, here's the thing on the internet.
- 27:05I can go to it and then I can type in, edit the SQL directly.
- 27:09Yeah.
- 27:10This seems a little bobby tables all over the place.
- 27:12Totally.
- 27:12It's SQL injection as a core feature of the application.
- 27:16And the reason it's okay to do that is that it's read only.
- 27:19Like the data is read only.
- 27:20I open the SQLite database file in read only mode and so forth.
- 27:24And so the only damage you can cause by putting in an evil SQL query is you could try and write one that uses up too many resources.
- 27:30But I've got a time limit on those.
- 27:32So if your SQL query takes a second to execute, I'll cut it off and I'll return an error.
- 27:36And yeah, it means that SQL is the API language itself, which is kind of fascinating.
- 27:42People have been very excited about GraphQL over the past few years because it's a language that you can use to define exactly what you get back from an API.
- 27:51SQL has been doing that since the 1970s.
- 27:53So Dataset essentially gives you a JSON API that you can feed SQL queries to and get back the results in JSON.
- 28:01Yeah.
- 28:01It's really interesting.
- 28:02The other problem that you can run into a SQL injection is exposing private data, right?
- 28:08So if I want to say show, do a query that shows just my orders, but I'm allowed to get a or true into the query, I get all the orders, right?
- 28:16But the whole point of Dataset is to say we're going to create just an explorer of all the data.
- 28:22So there's no private data and it's read only.
- 28:24So you're good to go.
- 28:25Exactly.
- 28:25And so suddenly SQL injection becomes this really powerful feature.
- 28:29I've done some work where I've written JavaScript applications where the JavaScript, it creates a SQL query in the JavaScript and then it sticks it in the query string and runs it against Dataset and pulls back the results.
- 28:40And the first time I did that, it was genuinely meant as a joke.
- 28:43I was trying to troll my coworkers by saying, ha ha ha, look, I've got JavaScript that's injecting SQL statements into this thing.
- 28:50It turned out it took me a couple of hours to build quite a sophisticated internal search engine for our documentation.
- 28:56And it feels like running SQL in your JavaScript is a terrible idea.
- 29:01But actually, for prototyping, it's really good.
- 29:04Like you end up with about 20 lines of JavaScript that do something very sophisticated and let you build an interactive UI on the top of it.
- 29:11Yeah, it's a pretty simple way to expose a searchable sort of REST API, read only REST API on top of just a data schema.
- 29:19Exactly, yeah.
- 29:20Yeah, but you have the ability to edit.
- 29:24You go in there and you write some more SQL and you work with it.
- 29:26And then you can say, give me the URL for this result, which I think is also a pretty neat thing, like deep linking into it.
- 29:33The way I think about that is I've written applications, which is a SQL query.
- 29:38Like it's a SQL query that is a great example.
- 29:40I've got a database of all of my GitHub issues and issue comments across all of my projects.
- 29:46And I wrote a SQL query which finds me GitHub issues which were created by someone who's not me and when none of the replies are from me.
- 29:54So it's issues in my repos where I have not replied to them yet.
- 29:57You basically somehow missed them potentially.
- 29:59Exactly.
- 30:00And so I've got a query for that and now I've bookmarked it and now I've got an application which is the here are the GitHub issues that you should go and look at application.
- 30:08So an entire application ends up being a URL that you can bookmark.
- 30:12And that's really interesting.
- 30:14That's a really, again, a very web native way of thinking about the problem domain.
- 30:17You know, you were talking about starting out working in the first dot com boom.
- 30:22And one of the things that was all the rage back then were mashups.
- 30:26Do you remember like Yahoo mashups and all that kind of stuff?
- 30:29Absolutely.
- 30:30Yep.
- 30:32Talk Python To Me is partially supported by our training courses.
- 30:35Python's async and parallel programming support is highly underrated.
- 30:39Have you shied away from the amazing new async and await keywords because you've heard it's way too complicated or that it's just not worth the effort?
- 30:47With the right workloads, a hundred times speed up is totally possible with minor changes to your code.
- 30:53But you do need to understand the internals.
- 30:55And that's why our course, Async Techniques and Examples in Python, show you how to write async code successfully as well as how it works.
- 31:03Get started with async and await today with our course at talkpython.fm/async.
- 31:09So it sounds to me like what you can almost build here is like a super interesting mashup.
- 31:15So you can like extract the data from GitHub.
- 31:18You can extract it from over here and you put it together in this new form.
- 31:21And then now you've got this API on top of it, right?
- 31:25A massive realization I've had working on this stuff is lots of websites have APIs.
- 31:29And the APIs sometimes have a lot of features like the GitHub API can do some pretty powerful stuff.
- 31:33But I can always think of something the API can't do that they didn't predict I'd won.
- 31:38If I can get all of my data out of that API and into a SQLite database, then there are no limits.
- 31:43And any question I can think to ask, I can apply against that thing.
- 31:49So I've basically sort of given the only thing I use APIs for now is to give get everything.
- 31:53Just give everything.
- 31:54It's here.
- 31:55Download it and sync.
- 31:56Get everything into a database.
- 31:57And now I can start introspecting my data and building this.
- 32:00Yeah.
- 32:00I think where it gets interesting, as we'll see as we get on to like the final dog sheep side of things,
- 32:05is it's great that GitHub has an API.
- 32:07It's great that Twitter has an API.
- 32:09It's great that Gmail has IMAP.
- 32:11And all these different things have rich, deep ways to talk to them.
- 32:15But if you want to talk to all of it at the same time and say, I want to know about what I've tweeted, emailed, or whatever else I've done about it.
- 32:22Like, you don't want to try to build that integration of all those APIs.
- 32:26Then it gets super gnarly.
- 32:27But if you get it into some kind of SQLite database, all of a sudden it becomes an option.
- 32:32Right.
- 32:32It's this personal data warehouse idea.
- 32:34And it's not just a personal data.
- 32:36Like, as a company, if you're a company with 50 different Git repositories, which lots of companies have,
- 32:42getting all of that metadata from all 50 of those repos into one place,
- 32:46and I've got tooling that will let you do exactly that, is crazy useful.
- 32:49It lets you build stuff across all of your issues and all of your comments.
- 32:52It lets you talk about, like, here is what our software team as a company has accomplished,
- 32:57or how many, like, that kind of stuff, right?
- 32:59Which is still super hard, even if you go to GitHub and do that.
- 33:02So I want to talk through a few examples that maybe we could mention really quickly.
- 33:06You gave a talk that covered both Dataset and Dogsheep at PyCon AU online this year, right?
- 33:13Was it this year or last year?
- 33:14Yes.
- 33:15Yes, I did.
- 33:16It was this year.
- 33:17Yeah.
- 33:18So in there, you talked about all sorts of interesting things.
- 33:20So I want to cover some of the examples there,
- 33:21because they kind of, like, really made this stuff connect for me.
- 33:24Cool.
- 33:24Okay.
- 33:24Yeah.
- 33:25So the first one was, you said, let me just say,
- 33:27we just search for random SQLite databases on my Mac.
- 33:32And you said, oh, look, here, we randomly found one in the photos library.
- 33:35Let's look at that, right?
- 33:37You just pointed Dataset at that, like, search for it.
- 33:39What do you do, like a .db or something like that in Spotlight?
- 33:42Yeah, there's a Spotlight command that you can run,
- 33:44which will show you every SQLite database on your Mac,
- 33:47and it's fascinating.
- 33:48Oh, my goodness.
- 33:49The number of weird little databases that you already have,
- 33:53your Firefox history, your Chrome history on there,
- 33:56Evernote uses SQLite.
- 33:57There was quite a few databases I found where I still don't quite know what they are,
- 34:01but they've got things like places that I've been over the past couple of years.
- 34:05I just sat there in a SQLite database somewhere, which is super interesting.
- 34:09Yeah, for sure.
- 34:10So in this demo, what you did is you used that command to find the SQLite database back in your photos library,
- 34:16and then said, well, let's just pull that up and poke around, right?
- 34:20Tell us about that.
- 34:20Yeah, so the photos, this was always one of my sort of white whale was, I want my photos data.
- 34:27I've taken 40,000 photos.
- 34:28They've got timestamps and latitudes and longitudes and all of this.
- 34:31How can I get that metadata into a SQLite database so I can run queries against my life in photos?
- 34:37And I've tried getting this to work with things like Google Photos in the past.
- 34:41Google Photos doesn't give you access to latitudes and longitudes, I think, for privacy reasons.
- 34:45But anyway, the big realization I had was that the Apple Photos on your phone and on your laptop uses SQLite.
- 34:51There's a little SQLite.
- 34:52They've already done it for you.
- 34:54You just got to go find it.
- 34:55It's probably huge.
- 34:56Yeah.
- 34:56800 megabytes of data in one SQLite database file.
- 35:00And it's not very easy to query because it's not designed for people to use it from outside.
- 35:05But if you jump through a bunch of hoops, you can get that data back out again.
- 35:08And then you start finding some really interesting things.
- 35:11So obviously, they've got a record for each of your photos with when it was taken in the latitude and longitude.
- 35:16They've reversed geocoded those locations.
- 35:18They can actually tell you in the database, this was in San Francisco.
- 35:21This was in the Mission District, those kinds of things.
- 35:23But then the coolest thing is Apple use machine learning to identify what your photos are of.
- 35:29So is it a dog or a cat or a pelican?
- 35:31Right, because you can go to your photos app and search for that.
- 35:33But like, show me cars and like some insane way cars come up.
- 35:37Exactly.
- 35:37But the beautiful thing about that is it turns out they run the models on your laptop.
- 35:41Like Google and Facebook will upload your photos to the internet and put them in a data center somewhere.
- 35:45Apple downloads these big binary machine learning model, like weights files onto your device.
- 35:52They actually run it on your phone overnight.
- 35:53And they use those to identify what's in your photos.
- 35:56So from a privacy point of view, this is perfect because you're not uploading your photos somewhere for some creepy machine learning model to run against.
- 36:03It's all happening on devices that you control.
- 36:05And the results of that go in a SQLite database.
- 36:08So they go into data set.
- 36:09And yes, so I can get them out and get them into data set.
- 36:11So yeah, I have a data.
- 36:12I have an example query that shows me photographs I've taken of pelicans based on Apple's machine learning labeling, labeling my photos of pelicans.
- 36:20And I can visualize those on a map because they've got lattes and longitudes with them and so on.
- 36:24And then the really fun thing is there's this there are various clues in the photos app that they're doing quality evaluations.
- 36:31Like if they show you all of your photos for a month, they'll pick a good photo to show us the sort of title of that album or whatever.
- 36:38That's machine learning as well.
- 36:39It's running on your device and it's based on these scores.
- 36:42And the scores are sat there in the database and they have names like Z overall aesthetic score and Z pleasant camera tilt score and Z harmonious color score.
- 36:52So you can say things like show me my pelican photograph with the most harmonious colors, with the most pleasant camera tilts and just get things back that way.
- 37:00You could even set up like a walking tour of show me where I've taken aesthetic photos of pelicans, starting with the best one and then the next and then the next.
- 37:10That is such a good idea.
- 37:11Yeah, that's just a SQL query.
- 37:13Yeah, yeah, yeah.
- 37:14Order by aesthetic descending or something.
- 37:16Yeah.
- 37:17And there's also facial recognition, which again is trained by you and runs on your device.
- 37:21So it's the least creepy version of it.
- 37:23So I go on a SQL query saying, show me photographs of my wife, Natalie, and my friend, Andrew, and show me the one with the most pleasant camera tilt that was taken outdoors.
- 37:33And this stuff all just works.
- 37:35It's baffling and really super fun.
- 37:38So one piece that we probably should connect for folks, if they tried to follow along, they find that SQLite database and then they throw a dataset at it, they're going to end up with like binary blobs where this data lives, right?
- 37:49Oh, totally.
- 37:50Yeah.
- 37:50I think Apple's SQLite format uses like binary plists in some of the columns.
- 37:55And also, it's actually quite hard to even open it because it'll crash and tell you that you don't have that custom something extension running.
- 38:03So the way I've addressed that, I wrote this, I found this software on GitHub called OSX Photos, which is someone's open source library for talking to the OSX SQLite database and working around some of these weird issues.
- 38:16And then I built my own tool on top of that tool called Dog Sheep Photos, which basically both pulls out the metadata for your photos into a nicer format, including getting the machine learning labels and stuff.
- 38:27But it's also got a tool for uploading the photo files themselves to an S3 bucket.
- 38:31Because if you want to really take control of your photos, you need them to have URLs so that you can embed them in pages and link to them and so on.
- 38:38So I've got a whole tool chain for uploading all of my photographs to S3 and extracting the metadata into a separate database and then publishing that database with data sets somewhere so that I can run queries against it.
- 38:49Yeah.
- 38:49Yeah, super cool.
- 38:50All right.
- 38:50Well, I think that probably is a good transition over to Data Sheep.
- 38:54So we have these different sources of data.
- 38:57Like it's nearly unbounded at this point, right?
- 38:59Of where data on the internet might live about that could be for you.
- 39:03There was this firebrand of a character that you mentioned around Wolfram Alpha.
- 39:08And he does some crazy, crazy, weird stuff.
- 39:13But he also had this idea that inspired you to sort of try to bring those together and build it on top of the data set.
- 39:19So like maybe start it with that story and we can tell people what Dog Sheep is.
- 39:22Okay.
- 39:22So there's this chap called Stephen Wolfram who is, he created Mathematica and Wolfram Alpha.
- 39:29And he's the CEO of a thousand person company, which it turns out he's a remote CEO, runs the entire company from home, which is kind of fascinating.
- 39:38Yeah.
- 39:38And he has been for a while, right?
- 39:39Like before it was cool.
- 39:41Yeah.
- 39:41No, absolutely.
- 39:42He's been doing the COVID thing for years and years and years.
- 39:44And so in February of last year, he published an essay called Seeking the Productive Life, Some Details of My Personal Infrastructure.
- 39:52And this thing, I would thoroughly recommend everyone take a look just to marvel at quite how long it is.
- 39:57He has spent 40 years optimizing every single inch of his personal and professional life.
- 40:03And he wrote about all of it in one place.
- 40:04Like he scanned every document he's worked on since he was 11 years old and got them OCR'd.
- 40:09And he's got a green screen in his basement for giving remote talks.
- 40:13And his heart rate monitor showed him that his heart rate is better when he's – so he had a standing desk.
- 40:18But his heart rate monitor showed him that walking outside is better for his heart.
- 40:21So he rigged up a sort of little tray mechanism so he could use his laptop while walking in the woods.
- 40:26And it's just astonishing.
- 40:28And I read through this essay thinking this is a lot.
- 40:32Like this is not –
- 40:34This is next level.
- 40:35Right.
- 40:35Totally next level.
- 40:36But there was this one little bit in it that caught my eye.
- 40:40He talked about how he has a personal search engine, something he calls his meta searcher.
- 40:44And so he's got his own private search engine that searches everything, every email he's sent, every paper he's written, everyone he knows who might know things about it, everything he's read, all of the files on his machine, all in one place.
- 40:57And I thought, well, that's something I'd like.
- 40:58Like I would love to have one place with as much of my personal data from different sources in one place where I can query it.
- 41:05Like I know I was talking to this person, but was it on iMessage?
- 41:09Was it an email?
- 41:10Was it over Slack?
- 41:11Like where the heck did I tell them this thing that I need to get back?
- 41:14Absolutely.
- 41:15And combine that with, you know, your bookmarks and your GitHub issues and, yeah, messages and all of these –
- 41:20Your tweets.
- 41:20Oh, yeah.
- 41:22And it felt like there was something interesting there.
- 41:24And so I then – I'll be honest, the best idea I've had in all of this is I thought, well, it's inspired by Stephen Wolfram, but it's not as good as what he's done.
- 41:33So if he's Wolfram, maybe I should be doing something called Dog Sheep, like as the less alpha versions of those animals.
- 41:40And then I thought, well, he's got a search engine called Wolfram Alpha.
- 41:44I could build a search engine called Dog Sheep Beta.
- 41:46And that joke stuck in my head.
- 41:49And I enjoyed it so much that I spent like 12 months on and off thinking with –
- 41:52Yeah, I have to build this.
- 41:54It must exist now that it's so good.
- 41:56I have to put it.
- 41:57Yeah.
- 41:58So this entire project is basically – it's pun-driven development.
- 42:01It's driven out of this pun that I came up with a year and a half ago.
- 42:04And, yeah, so that's what I've been building.
- 42:06And so the idea with Dog Sheep, it's basically an umbrella project for a whole bunch of tools around this idea of personal analytics.
- 42:13Like what data is there about me in the world?
- 42:16How can I get that data out of lots of different sources and get it into SQLite databases?
- 42:20Because once it's in SQLite, I can run data set on top of it.
- 42:23And now I've got this personal data warehouse of my data from all of these different sources.
- 42:28And then on top of that, I can build a search engine, which I've now built, which ties all of this stuff together again.
- 42:33And so, yeah, so I've been tinkering around with all sorts of tools in this category for, yeah, just over a year now.
- 42:40And I've got – so right now I've got data in my personal Dog Sheep from Twitter.
- 42:45I've got all of my tweets, but also all of the tweets that I've favorited.
- 42:48And I've favorited like 30,000 tweets, but I can search those and see who I've favorited the most from and so on.
- 42:54I've got all of my photos, as we discussed earlier.
- 42:57I've got my health kit data from my Apple Watch, which means I can tell you my heart rate going back the last three years or something.
- 43:03How do you get it off the Apple Watch?
- 43:05So, again, Apple are really good for this kind of stuff.
- 43:08They don't publish it to the – they don't upload it somewhere.
- 43:10They keep it on your phone and on your watch.
- 43:13But there's an export button.
- 43:14In the health app on the iPhone, there's a button that says export my data.
- 43:18And it actually creates a zip file full of XML on your phone and then gives you the option to like airdrop it to your laptop.
- 43:25So I do that and I get a 300 megabyte zip file full of XML.
- 43:29And then I write a script which reads that XML in terms of SQLite.
- 43:32And so, yeah, so I've got all of that data.
- 43:34The best thing about that is anytime you record an outdoor workout, like if you go for a run or even if you go for a walk, it records your latitude and longitude every few seconds.
- 43:43And that's available in the data.
- 43:44So I've got – so, like, within 10-meter maps of every walk I've taken for the past year, which is super fun.
- 43:50I mentioned GitHub.
- 43:51I've got all of the data from all of my GitHub projects.
- 43:54I've got over 400 repositories now.
- 43:55So that's actually quite a lot of stuff.
- 43:57I use Foursquare Swarm and check-in to places.
- 44:00So I've got 4,000 swarm check-ins.
- 44:03Oh, you have Google Takeout, which is insane.
- 44:05Right.
- 44:05I've only done a little bit of work with Google Takeout.
- 44:08That's one of the least developed tools.
- 44:09But, yeah, you can get Google's version of your location history, which is – like, for me, it's like 250,000 latitude, longitude points that they've – I don't even know where they got that stuff from.
- 44:19Yeah.
- 44:20I recently did a Google Takeout, and I think it was probably zipped.
- 44:23I think it was 61 gigabytes or something.
- 44:26I mean, it's a lot of data.
- 44:27It's a lot of data.
- 44:28And a lot of that is, like, photographs and document files and stuff.
- 44:31But there's just a ton of very detailed JSON data about you as well.
- 44:35With those exports, it's always fun to look for the ad targeting stuff because you'll find out that you have been assigned the role of a, like, middle-aged tech executive or something.
- 44:47And you can see what they're targeting ads are actually based on.
- 44:49I've got Evernote.
- 44:51I've got, like, 600 notes from Evernote.
- 44:53My Goodreads data on books that I've read, which is synced from my Kindle.
- 44:56Oh, and then the most fun one is I've got a copy of my genome.
- 45:00Because I did 23andMe a few years ago.
- 45:02And I found out they've got an export button.
- 45:04And you can get back a CSV file of 600,000, like, gene pairs from your genome, which I can now run SQL queries against.
- 45:12So I have a SQL query that tells me what color my eyes are based on interrogating my own copy of my genome, which delights me.
- 45:18That is pretty amazing.
- 45:19That's just insane.
- 45:21Yeah, so that's a ton of data, right?
- 45:23This is a lot of stuff.
- 45:24And I'm barely even scratching the surface of what I could be doing into this system.
- 45:27Right.
- 45:28Well, and these are all, like, plugins or other types.
- 45:30So it's wherever the data lives.
- 45:32If there's an API or web scraping, you can have it.
- 45:34Right.
- 45:35And it's some, the tools are all called things like Twitter to SQLite or GitHub to SQLite or I think I've got genome to SQLite somewhere.
- 45:43That's just the naming convention that I use.
- 45:45But, yeah, the core idea is you knock out a quick Python command line tool, which either takes a zip file you got from somewhere or hits an API with API credentials.
- 45:53And it slurps down as much data as it can, wallops it in a SQLite database, and that's all it does.
- 45:58And then it's up to you to run data set against it and start doing the, like, doing fun querying some things.
- 46:04That's cool.
- 46:04So I think maybe it would be good to connect this, maybe tell a story or an example, again, what you did at PyCon and you talk about your dog and figuring out using Twitter to graph the weight of your dog over time and Twitter to map where your dog likes to go on walks.
- 46:20Absolutely.
- 46:20So my dog is called Cleo.
- 46:21First of all, tell me how dog and Twitter go together.
- 46:24Not dog sheep, but just like your dog.
- 46:26So Cleo has a Twitter account because, I mean, to be honest, most dogs have Instagram these days, but Cleo is a bit more old fashioned.
- 46:32So Cleo is on Twitter.
- 46:34She's more on the tech side, less on the young influencer side.
- 46:36Yeah, exactly.
- 46:37Got it.
- 46:37Cleo, C-L-E-O-P-A-W-S.
- 46:41Cleo pause on Twitter.
- 46:42And she tweets about things.
- 46:44She tweets selfies and like things that she likes and so on.
- 46:47And every time we go to the vet, she tweets a selfie of herself at the vet and they weigh her and she tweets how much she weighs.
- 46:53She tweets, I weigh 49.3 pounds.
- 46:56I grew more dog.
- 46:57And there's a selfie.
- 46:58And one of the things I've done with dog sheep is I've imported all of her tweets.
- 47:02And so now I can run a SQL query that just pulls up the tweets where it contains LB for pounds and or weigh.
- 47:08So I can pull back just the tweets where she said how much she weighs.
- 47:12And then I've got a regular expression extension for data that adds a custom SQL function that can do regular expressions because that's a useful thing to have.
- 47:20So I can pull out her weight with a regular expression into a separate column.
- 47:23And then I've got a charting plugin that can chart something against something.
- 47:27So I can chart date against weight and see a chart of how much she weighs based on her self-reported weight in the selfies that she's posted on Twitter, which is clearly a...
- 47:38That's a killer act right there.
- 47:39That is a useful thing.
- 47:41It's absolutely frivolous.
- 47:43But what I think it shows is so interesting is what you can do if you can put these pieces of data together, right?
- 47:49If all of a sudden I can just do arbitrary queries and apply some special filtering, but to these other data sources you never expected to be able to, all of a sudden you have a graph that you never knew you were keeping about the weight of your dog or some other thing you're interested in.
- 48:03This is just a SQL query.
- 48:05The SQL query goes in a bookmark.
- 48:07So the entire application, the show me a chart of my dog's weight based on her selfies is a bookmark.
- 48:12It's just a bookmark that I've got.
- 48:14It's actually super useful.
- 48:17Super cool.
- 48:18Now, how do you get a map of where your dog is from Twitter?
- 48:21So that one, I mentioned I use Foursquare Swarm and I check in places.
- 48:24Every time the dog's with me, I use the wolf emoji in the check-in message, which looks a little bit like her.
- 48:30And it turns out SQL does emoji these days.
- 48:33So you can run a SQL query where you look for things like percentage wolf emoji percentage.
- 48:38Right.
- 48:38It's just a character that's unique.
- 48:40Exactly.
- 48:40So then you get back the check-ins where my dog was there.
- 48:44And then because I've got a latitude and longitude in that query, I get them on a map.
- 48:48So I've got a map of places my dog likes to go based on the wolf emoji in my swarm check-ins.
- 48:54And again, it's just a bookmark.
- 48:55It's these custom applications that's a bookmark.
- 48:58I think those two examples really bring home the unexpected power of what you kind of unleash when you get this stuff.
- 49:04Completely.
- 49:04There's a project I should mention that relates to this.
- 49:07So I've been writing a lot of these tools that create SQLite databases.
- 49:10All of these dog sheep tools pull something from somewhere and turn it into SQLite.
- 49:14And the way I do that is using a Python library that I've been building called SQLite hyphen utils.
- 49:20SQLite utils is a bunch of utility functions to make it really productive to create new SQLite databases.
- 49:26So the core idea is, say you've got array of JSON objects.
- 49:30You can say dot insert bracket array of JSON objects.
- 49:33And it will create a SQLite table with the schema that's needed to match those JSON objects.
- 49:38Wow.
- 49:39So it just looks and says, these are the top level keys.
- 49:41So we're going to make those columns, something like that.
- 49:43These ones are integers.
- 49:44These ones float.
- 49:44This is a text.
- 49:45And it creates the table automatically.
- 49:48Which means if you're working with an API that's well designed, like the GitHub API returns lists of JSON objects.
- 49:53So it's a Python one-liner to turn those into a SQLite table with the correct columns.
- 49:58And you can say, oh, and make the ID one the primary key and set these up as foreign keys and those kinds of things.
- 50:03And that's been crucial because it means that I didn't have to come up with a database schema for Swarm and Twitter and GitHub and Apple Photos and all of that.
- 50:12I just had to get the data into a list of objects and the schema was created for me.
- 50:16No, it's got a little bit of a NoSQL feel in SQL.
- 50:19Exactly.
- 50:20And SQLite, it turns out, can deal with JSON as well.
- 50:22So you can stick a JSON document in a SQLite column.
- 50:25And then there are SQLite functions for pulling out the first key of it and that kind of thing.
- 50:30But yeah, it means it's all super productive.
- 50:32SQLite utils also comes with a command line tool.
- 50:36So for simple things, you don't have to write any Python at all.
- 50:39You can W get a JSON blob, pipe it into the SQLite utils command line tool and tell it to insert it into a table.
- 50:46And it will create a database file on disk and populate the table.
- 50:49And then you can do stuff like configure full text search against it or set up extra foreign keys or whatever it is.
- 50:55Oh, that's super neat.
- 50:56So all of these different integrations that you built, it sounds to me like they could potentially just be useful for people listening and go, you know, I'd really love to get four square swarm data as a SQLite database.
- 51:06And they don't necessarily want to use dogsheet.
- 51:07Like it sounds like these plug in pieces might be cool building blocks.
- 51:11If you can get yourself a OAuth token for your swarm account, which I've got an online tool that will do that for you.
- 51:17You pip install swarm to SQLite and you type swarm hyphen to hyphen SQLite swarm dot DB --token equals that and hit enter.
- 51:25And that's it.
- 51:25That's it's like a one line on the terminal.
- 51:27And that will give you a SQLite database with all of your swarm check ins in it.
- 51:31Wow.
- 51:32I'm pretty fascinated by the idea of like I could go to one place and just search everything about me.
- 51:37Absolutely.
- 51:37So that feature, because I had this stuff in like hundreds, dozens of different databases and tables.
- 51:42I actually built the dog sheep beta search engine just a couple of months ago.
- 51:47And basically the way that works is you give it SQL queries to run against all of your other tables.
- 51:52So you say for the GitHub one, select title from issues and create a date and so forth.
- 51:57For the Twitter one, select this, select that.
- 51:59And you run a script and it will run those SQL queries against all of your like 20 different databases,
- 52:05load the results into a new database table and set up full text search on it.
- 52:09So it's kind of like using something like elastic search where you have to query your data from lots of different sources into one index.
- 52:16And in this case, the index is just another SQLite table.
- 52:18And then that gives you a fasted search index on the top that lets you search across all of the different things that you've ingested into it.
- 52:24Right.
- 52:25If you do an index, it'll be nice and fast.
- 52:26And then you just say, well, you've got to go back to these five tables and get these various things.
- 52:30Right.
- 52:30Yeah.
- 52:30And that's actually part of the tool is you can then set up a SQL query for each type of content that says, oh, and to display it, run this SQL query to grab these details, stick them in this Jinja template and stick that on the page.
- 52:43So when you display the results, it can use all of the rich data that's come back.
- 52:47But the actual index underneath it is basically title content and the date and that's it.
- 52:51Yeah.
- 52:51Wow.
- 52:52Okay.
- 52:52Pretty interesting.
- 52:53What about email?
- 52:54I don't see in this list like connect to email, although there's Google takeout.
- 52:58That's not exactly necessarily the same.
- 53:00I will admit I have not done email yet because I am terrible at email and I'm almost a little terrified what will happen if I start running SQL queries against 10 years of mostly unread emails.
- 53:10But I'm sort of transitioning into doing freelancing and consulting.
- 53:14One of the most important aspects for consultants is that they're on top of that email.
- 53:17So I think that's probably the next task that I'll have to take on is getting good at email and then ingesting that into the dog sheepers.
- 53:25Yeah.
- 53:25I mean, it's kind of like this open plugin type of architecture.
- 53:28So someone else could create it as well if they're listening and they just want it to exist, right?
- 53:31Absolutely.
- 53:32I mean, honestly, like, you know, the email standards are good enough now that writing a tool that turns your email archive into a SQLite database is pretty trivial.
- 53:40Apple mail.app uses SQLite anyway.
- 53:43So I've actually done a little bit of poking around just looking at that database.
- 53:47Okay.
- 53:47Interesting.
- 53:48Yeah.
- 53:48I just haven't got to it.
- 53:49You could probably point it at an Outlook PST file if, you know, the world has cursed you and like you have to work in Outlook.
- 53:55Or you just use IMAP or POP3 or something like that, right?
- 53:58There's a very solid Python library for reading Outlook mailboxes.
- 54:03So you could totally use that.
- 54:04Okay.
- 54:05And then it would be a very thin layer of code on top to turn that into a list of JSON objects and pipe them into the SQLite library.
- 54:11Yeah.
- 54:11All right.
- 54:12Super cool, Simon.
- 54:13This is like a bunch of levels building on top of each other.
- 54:16I like it.
- 54:16And also thank you for the history of Django.
- 54:19It was really cool to hear how you experienced as it came to existence.
- 54:23That was neat.
- 54:24Cool.
- 54:24Yeah.
- 54:25Could talk about a bunch more, but I don't want to take all of your time.
- 54:28So let me just ask you the final two questions here.
- 54:30I always ask.
- 54:31So if you're going to write some Python code, what editor are you using these days?
- 54:34And these days I'm all about VS Code.
- 54:36Especially the most recent version of their Python integration, which is controversial because it's the one bit of it that's not open source.
- 54:43But that thing is just miraculous.
- 54:45Nice.
- 54:46PyLance, right?
- 54:46I think so.
- 54:47Yeah.
- 54:47It's showing me, hey, this variable hasn't been used yet and this import wasn't working and all of that kind of stuff.
- 54:52See, I'm all into VS Code now.
- 54:54Yeah, okay.
- 54:55That's definitely one that seems to be coming along and catching a lot of traction.
- 54:58Cool, cool.
- 54:59Notable PyPI package.
- 55:01Something you've run across that you're like, oh, this thing is cool.
- 55:03You should really know about it.
- 55:04This is great because I get to answer this using dog sheep.
- 55:06Because I've got all of my starred GitHub repos are pulled into my database, into dog sheep.
- 55:11And I can actually run a dog sheep, a beta search and say, show me everything I've starred or sorted by most recent.
- 55:17So the most recent Python one I started, I just started Astor, A-S-T-O-R.
- 55:22I've heard of that.
- 55:23I forgot what it is, though.
- 55:24Yeah, it works with the Python abstract syntax tree.
- 55:27So it's for building software on top of Python.
- 55:30And the reason I found it is that I found this tool called Flint, which re-does all of your .format calls and turns them into Python 3.6 format strings.
- 55:39Yes.
- 55:40And I was like, oh, how does that work?
- 55:41And it turns out it uses Astor under the hood.
- 55:43I was actually going to give a shout out to Flint.
- 55:46The reason was on Dataset, I just saw the last commit at the time of the recording was use f-strings in place of format.
- 55:53And you can just point Flint at the entire, just the top level directory and it just fixes it.
- 55:59That's why I started.
- 56:00I was playing around with that.
- 56:01And then the other, I mean, the other one, it's not a recent favorite, but I'm going to promote HTTPX.
- 56:06Oh, yeah.
- 56:06I'm a big fan of that one as well.
- 56:08You talked about the ASCII side.
- 56:10This is like consuming services from inside an ASGI server.
- 56:14Yeah.
- 56:14One way to look at it, it's the new requests, right?
- 56:16It's essentially, it was almost, I think, called requests three at one point in its history, but it's basically the modern version of requests with full async support.
- 56:25So you can use it synchronously and you can use it asynchronously.
- 56:28But the killer feature from my point of view is you can instantiate a HTTPX client and you can point it at a Python ASCII or WSGI object and then start running requests through it.
- 56:39So it's an amazing test harness.
- 56:40Oh, yeah.
- 56:41All of the dataset tests and every dataset plugin that I've written, they're actually, they're using HTTPX.
- 56:47So it's like being able to do HTTP testing.
- 56:49You don't even have to spin up a local host server.
- 56:51It's all happening in memory.
- 56:53And that's just extraordinary.
- 56:54Oh, that sounds fantastic.
- 56:56Like that's such a good product of writing unit tests against things.
- 56:59Yeah, I've never tried it.
- 57:00But a lot of times you can create, you'd like install the web test and then wrap it in a test framework.
- 57:05Or, you know, maybe you've got to even run it, like fire it up and run it and then talk to it.
- 57:10But this is just like connect the two pieces in code and skip the network and go.
- 57:14And I've got a really nerdy thing that I've just started doing with it.
- 57:17So dataset has plugins and dataset plugins can do a bunch of different things.
- 57:22But I realized that dataset itself is an API.
- 57:25The whole point is that it gives you a JSON API that you can use to interrogate your tables and run queries and so on.
- 57:31And I wanted my plugins to be able to use that API.
- 57:34But I didn't really want them to be making outbound HTTP requests against themselves and so on.
- 57:39So I just a couple of weeks ago added a feature to dataset where it gives you an internal call.
- 57:45They can say client.get brackets and then feed it a URL.
- 57:48And that's actually using HTTPX and ASCII under the hood.
- 57:51So the idea here is that any feature of dataset that is an external JSON API is now also an internal API that plugins can use.
- 57:59And I've started building plugins against that.
- 58:01The Dogsheep beta plugin actually runs internal searches against the dataset search API for things like adding faceted search and so on.
- 58:10Dataset GraphQL is a plugin I'm writing that adds a GraphQL API on top of dataset.
- 58:16And that's going to be using this client as well.
- 58:18So you'll run a GraphQL query which gets turned internally into an internal JSON query and runs over this ASCII mechanism.
- 58:25It's cool.
- 58:26I hadn't really thought about that with HTTPX.
- 58:28I've always used it to just like I'm doing some async methods.
- 58:31So here's a good choice for a client.
- 58:33Yeah.
- 58:33The deep integration with ASCII I think is really exciting.
- 58:36Yeah.
- 58:36Super neat.
- 58:37All right.
- 58:37Well, those are all good recommendations.
- 58:39Now, final call to action.
- 58:40People are interested in dataset.
- 58:42Dogsheep.
- 58:43First, I just want to throw out you should really go watch the 25 minute or whatever it was talk that you did at PyCon AU.
- 58:49That'll connect a ton of things for people.
- 58:50I'll throw in another recommendation.
- 58:52Yeah, go for it.
- 58:52I gave a talk last week, the GitHub Octo Speaker Series, which I think is the best talk I've given about dataset and Dogsheep.
- 59:00It's got a lot of very recent demos in.
- 59:01And that's linked to on my blog.
- 59:03It's a talk about building personal data warehouses.
- 59:05But yeah, that's got dataset and Dogsheep demos.
- 59:08Yeah, very neat.
- 59:09And also, you actually, this is somewhat unusual for an open source project, but I think cool because promoting open source projects is always like, you know, why do they take off or don't?
- 59:17You have a dataset weekly newsletter.
- 59:18Yes, I do.
- 59:19It's not quite weekly.
- 59:20Maybe I should have picked a different name.
- 59:22But yeah, I've got a newsletter which goes out every week or so with the latest from the dataset ecosystem.
- 59:28So that's dataset.substack.com.
- 59:31My blog, Simon Willison.net, I update at least once a week with all sorts of bits and pieces.
- 59:35And then if you're interested in the Dogsheep stuff, I would love it if people started building these themselves.
- 59:41There is quite a bit of assembly required.
- 59:43All of the code that I've written is open source, but you have to track down your authentication tokens and run cron jobs and find somewhere to host it.
- 59:50And so it's not easy to get up and running.
- 59:52But if you do get it up and running, I would love to hear from you about what kind of things you managed to do with it.
- 59:58And if people want to build tools that are part of this ecosystem, I'd be absolutely thrilled.
- 1:00:02Yeah, that'd be awesome.
- 1:00:02If they want to build a star to SQLite, whatever star is, let you know, right?
- 1:00:07Well, congratulations on this project.
- 1:00:09I think it's super neat.
- 1:00:10And thanks for coming on to share with everyone.
- 1:00:12Awesome.
- 1:00:12Thanks a lot for having me.
- 1:00:13You bet.
- 1:00:14Bye.
- 1:00:16This has been another episode of Talk Python To Me.
- 1:00:18Our guest on this episode was Simon Willison, and it's been brought to you by Linode and us over at Talk Python Training.
- 1:00:25Simplify your infrastructure and cut your cloud bills in half with Linode's Linux virtual machines.
- 1:00:30Develop, deploy, and scale your modern applications faster and easier.
- 1:00:33Visit talkpython.fm/linode and click the create free account button to get started.
- 1:00:38Want to level up your Python?
- 1:00:40If you're just getting started, try my Python Jumpstart by Building 10 Apps course.
- 1:00:45Or 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.
- 1:00:53And of course, if you're interested in more than one of these, be sure to check out our Everything Bundle.
- 1:00:58It's like a subscription that never expires.
- 1:01:00Be sure to subscribe to the show.
- 1:01:02Open your favorite podcatcher and search for Python.
- 1:01:04We should be right at the top.
- 1:01:05You can also find the iTunes feed at /itunes, the Google Play feed at /play, and the direct RSS feed at /rss on talkpython.fm.
- 1:01:15This is your host, Michael Kennedy.
- 1:01:16Thanks so much for listening.
- 1:01:18I really appreciate it.
- 1:01:19Now get out there and write some Python code.
- 1:01:21I'll see you next time.
- 1:01:21Bye.
- 1:01:22Bye.
- 1:01:22Bye.
- 1:01:22Bye.
- 1:01:22Bye.
- 1:01:22Bye.
- 1:01:23Bye.
- 1:01:24Bye.
- 1:01:25Bye.
- 1:01:26Bye.
- 1:01:27Bye.
- 1:01:28Bye.
- 1:01:29Bye.
- 1:01:30Bye.
- 1:01:31Bye.
- 1:01:32Bye.
- 1:01:33Bye.
- 1:01:34Bye.
- 1:01:35Bye.
- 1:01:36Bye.
- 1:01:37Bye.
- 1:01:38you
- 1:01:38you
- 1:01:39Thank you.