- Podcasts
- Python Bytes
- #212 SQLite as a file format (like docx)
About this episodeTopics covered in this episode: pytest 6.2 is out SQLite as a file format (like docx) A Day in Code: Python – A picture book written in…
- pytest 6.2 is out
- SQLite as a file format (like docx)
- A Day in Code: Python – A picture book written in code
- PythonLabs is now hosted by Azure. and “Yes, Barry, there is a PythonLabs”
- Extra, extra, extra, extra, extra, extra, hear all about it
- OpenMV
- Extras
- Joke
Transcript
From the publisherThis transcript comes from the podcast’s own feed, shown as the publisher wrote it.
#212 SQLite as a file format (like docx)
Yay, we have a guest. Yes, welcome Sherry. Yeah, it's great to have you here. Thanks for coming. Thank you so much for having me. Great to be here. Yeah, you got some cool projects and you wrote to us and said, hey, here's a project I'm working on. And we're like, well, why don't you just come on the show and tell people about it?
So we'll get to that later and it'll be a lot of fun. Yeah. Brian, you should do something with pytest. I heard it's popular. Yeah. So, yeah, it might not be a surprise. I am a fan of pytest. But I wanted to shout out because the people at pytest have been working pretty hard at making things better.
And they've got so right now we've got Python 6.2. I think I think we're at 6.2.1 now. But 6.2 came up recently. Oh, neat. Look, changelog. Cool. So there's a few things that I really like that came up with the 6.2 release. So pytester, there used to be, I mean, plug-in authors are going to be the only ones that really care about this, maybe.
And now you can just turn it into verb. If you pass verbose mode, you get those reasons out. That's pretty cool. And the last one I wanted to highlight, last feature that came up, is a change to the monkey patch. So monkey patch is a way, it's kind of like mocking. It's a little kind of like a way to easily mock.
So that's pretty neat. How does that compare to, like, the patching with context block? Well, yeah, it's exactly like that. So you could use a with block to patch it. So... Fantastic. Cool. I think this is great. Like, it's cool to see pytest moving along. And, you know, there aren't really that many challengers these days, right?
There's just that... You're not convinced. Well, I mean, how many projects don't have dependencies? Yeah, that's true. The other bit... I kind of like it being outside of Python because you can... Like, let's say you upgrade your Python. You don't... I don't think you really want to upgrade your test runner at the same time you're upgrading...
Well, and also you get a lot higher velocity, right? Like, the reason they didn't bring requests in to replace the internal URL HTTP stuff in Python was, like, it's going to slow requests down. Yeah. Yeah. So, it would slow pytest down, too. And then I got a ping kind of on a related note from somebody that was using a plugin I wrote called pytest-check and said, hey, I'm having trouble running this with pytest 6.
It's just the file. And it's embedded into your application. So, it's in process, which actually makes it incredibly fast, right? SQLite ships with Python. So, you don't have to have any dependencies even to use it. You just connect to it. You probably do want to have dependencies like, say, SQLAlchemy or something like that.
And the idea is that we so often, if we have some kind of custom file format for our application, whether it's a command line tool or a GUI or maybe even a website, although those often default to databases anyway, you have to think about, how am I going to store this file? Should we put it in JSON?
And we could use some XML, Brian. Does that sound good? No. No, no, no. XML. But, you know, JSON is super popular, right? But even with JSON, you've got to figure out, okay, well, these are the blocks and here's how you read it. And if some other application wants to talk to it, they need to work with it.
And there's all these really interesting advantages of saying, well, let's just have a single binary file that is a SQLite database. And just that's our file format. Much like docx has it, you know, is the file format for Word or xlsx for Excel or, you know, you name it, right? All these different apps have their own file format.
So multiple things can be working with it concurrently. If you make changes to it, you could do like three changes and something goes wrong. There's an exception. Just rolls it back. These things are all pretty cool, right? Yeah. Yeah. So let's see. Incremental updates. This is another one that's interesting is with, say, something like a JSON file.
You'd have to load the whole thing up unless you're doing something really intense. You would change something small about the file, then you'd write the whole thing back. But the way SQLite works is you just make changes to little spots in the binary file as you insert stuff. So writes are a lot simpler.
And also, finally, documentation. Like you want to document how your file format works. You just describe what the tables are and what the columns mean. And that's it. What do you think? I actually really like using single file database styles like SQLite for persistence layers because you don't really have to think about it at this point.
So I'm. Well, honestly, me too. I looked at it and I was like, well, of course I know I can use SQLite, but I just hadn't really put it together. Like, well, this is actually a really cool use of a file format that other people can use. Yeah. Yeah. Yeah. Yeah. There's also a really cool project called Dataset.
D-A-T-A-S-E-T-T-E or something like that. And another one related to it called Dog Sheep, which is a really interesting project that takes all these SQLite and SQL oriented data inputs and allows you to bring them together and do reporting and analysis on them. So I did an interview recently with Simon, the guy behind the project over on Talk Python.
It's not out yet, but it's already recorded and it will be out. And there's just all these interesting things you can do once data gets into these common formats. So this just is another example. And he also pointed out that there's all these different SQLite databases already on your machine, like the photos library for macOS.
That's a SQLite file. Wow. Yeah. So there's like hundreds of these on your computer and you just didn't know it. So anyway, this is hopefully solve some problems for people trying to create, you know, what are we going to do for our app format? You know, our equivalent of Doc X. What's that going to be?
Well, it definitely could be one of these. Yeah. That's pretty cool. Yeah, definitely. Yeah. Yeah. All right. Next up, Sherry, tell us about your project. This is the one I mentioned before. Yeah. So I'll start off by saying I noticed that kids' programming books are either really abstract or they don't teach the reader how to write a simple program or they're too, it's either that or they're too intensive in the format of a textbook or a book made up of a lot of tutorials with step-by-step instructions.
It tells a story using Python programs that describe real-life situations in the code. And so for each two-page spread in the story, there's a code page that has a complete Python program that describes a situation in the story and a full-page illustration next to it that shows the scene that's being described.
So in that way, the book is presenting Python code examples in a continuous story, and the code is explained below each program. And each program presents a new Python concept. And so you might be wondering, like, why did I choose a picture book? And so there's a few main reasons why I thought of doing that.
And I also wanted the book to be compact and show code examples conveniently. So as a beginner, you don't need to dig through a big book looking for basic code examples. And also, by having nice full-page illustrations, my aim is that the reader and kids especially will enjoy the book in the same way as a normal picture book that is flipped through again and again.
And while they're enjoying the pictures, they'll be looking at the code too. And their understanding of the programming concepts will be reinforced. And so this book will be in the same format as my first book, A Day in Code, which is written in the C programming language. And that book was actually released a few weeks ago on Amazon, and I had previously launched a Kickstarter campaign for it.
And after delivering the book, I got a great response from kids to college students to adults. So it's really for all ages. And so now I'm focused on creating a Python version of that book. And you can pre-order it in code. Yeah, I think a Python book makes a lot of sense because it's the most popular learning programming language these days, right?
Yeah, it's definitely been gaining in popularity. Yeah, very popular. It's everywhere. I like the idea of just sort of letting it wash over kids, right? Maybe the goal isn't necessarily, it might not be to teach them programming and have them come out the other side of interacting with the book, actually writing code.
But kind of seeing the examples and just making code something that you kind of talk about, like reading or like writing or like history or anything. So it's a cool format. What do you think, Brian? I think this is great. So do you have like a target age in mind? So that's why I say like, well, of course, being a picture book, it's great for kids.
But I've also gotten a lot of people, adults who say that they enjoy it too. And it's just a fun format for anyone to enjoy starting to learn programming or even just looking at it as a reference. Even if you're experienced in programming or maybe you want to refresh your memory, it's just a convenient way to look back at simple code examples that go over all the basics of Python.
Yeah. So once you get it funded, when do they come out? So right now, the estimated delivery time is in April. And it'll be a special edition book. So I'm actually getting it printed at a U.S.-based facility that allows me to print with glossy paper, 100-pound paper, and have a feature of having printed end sheets at the front and back of the book.
And so these features aren't available once the book goes on Amazon. Cool. Yeah. Great project. Happy to see it gaining some traction. Hopefully people can make it happen because it'll be neat. Yeah. Thank you so much. Yeah, absolutely. So Brian, before we move on to the next one, speaking of books, maybe tell people about what we're up to so they can support us if they wish.
And then if they want to learn some more about all sorts of types of Python, they should probably check out training. They should. Like, we've got a couple of new courses. I just released the FastAPI course a couple weeks ago, and that is such a neat framework. We also have our Excel to Python and the Python Memory Management Tips Deep Dive course.
I'm assuming it's Barry Warsaw. Yeah, I would guess. Asked the question, what is Python Labs now? Or is there a Python Labs now? I don't know. Guido owns the domain name, which is probably the biggest claim to Python lab hood there is. And then Tim Peters replies with a very, yes, Virginia, there is a Santa Claus-esque answer.
And I just encourage people to go read it. It's hilarious. There's stuff like, Barry, your little friends are wrong. They've been affected by the skepticism of a skeptical age. Yes, Barry, there is a Python Labs. It exists as certainly as love and generosity and devotion exist. Alas, how dreary would be a world with no Python Labs.
So it goes on like that. And it's pretty funny. So I encourage people to check it out. How funny. Have you seen this before? I've never seen this. And apparently it's from 2004 originally. But now it's on Microsoft Azure. And I'm wondering if this has anything to do with Peter Van Rossum moving over to Microsoft.
Yeah, I assume so. I was going to try to look at where I found this. And I think just somebody mentioned that it moved to Azure a couple months ago or recently. Yeah, yeah, funny. You know, another piece of news I caught that was not officially on the radar. But a friend of the show and our friend, Anthony Shaw, he is headed towards Guido as well.
You hear that? I did. Yeah, he joined Microsoft as some kind of Python specialist. I'm not sure. So I hope they throw some money on him to try to move him to the Northwest. That would be cool. That would be cool. Yeah, that we could hang out with him more. He's far away. He's in Australia, which is a long way.
Yeah. And we change color. Then we come out. All right. Let's see. What's the next one here? I think. Yeah. So remember, Brian, I did an extra, extra, extra, extra the other day. Yeah. That was fun. Do more of that. Because I had so much stuff. Well, let's do an extra, extra, extra, extra, extra, extra this time.
Because, oh my goodness, there is so much stuff. I'm not just going to turn this into another element here of the show. So first of all, we spoke about NumPy in installing. I think it was on Big Sur. It was having some problems. It wouldn't install correctly. I don't remember if it was Windows or Linux or macOS.
I think it felt like it was macOS. But anyway, it was a problem with one of the platforms. But what was interesting is I got a message from Grice that, hey, quick follow up on episode 208. Did you know? I didn't know. Did you know that in your requirements TXT file, you can say like NumPy equal equal one dot 19 dot three semicolon and then platform.
So you can say platform underscore system equal equal Windows. Then another different version of NumPy platform equals Linux. Another one platform equals Darwin. Isn't that cool? Yeah. I had no idea. You could kind of split the requirements file to say the Windows install gets this and the Linux install gets that.
Oh, that's cool. Yeah. Yeah. I had never seen this. But the problem was NumPy was not. Oh, it was Windows update that broke NumPy. That's what it was. And so here's a way to pin the Windows version to an older NumPy, but let the other stuff be newer. That's what it was. So here's a really simple way to fix that, huh?
Yeah. I hope I never need this trick. Yes, exactly. And then I got another message from William Silva. And he said, hey, check this thing out. There's, you probably heard of material design, the way that Google styles some of their apps and so on. And we've all heard of probably the best way to build cross-platform apps with sort of native widgets.
Yeah. So often these cross-platform apps, they just look, boy, I don't know. They just look like they're standing out weird, but this looks really nice here. I totally like it. So I'll put that in the show notes. People can check that out. Number three, I just announced this. I thought it was pretty neat.
I wrote a blog post that talked Python hit 20 million downloads and is the number two developer podcast out there. I just found out. I wrote a blog post just sort of celebrating that. That's very impressive. Yeah. Good job. That's crazy. Yeah. Thanks. Thanks. And by the way, Python bytes is around 6 million and going.
So Pyramid 2 is looking solid. Not too much change, but it's good to see how it's going. Oh, Python 3.9.1 is out with 282 changes from, that's a lot. Well, let's go through them all. Yeah. Okay. Well, I'm going to say it like 10, 10, 10 X speed, if you don't mind. Now, the other notable thing, almost the reason I'm bringing this out is that the Python on macOS also ships as a universal binary, which means it has an Intel version and an Apple M1 version.
Oh, nice. Which leads to all sorts of interesting weirdness when you pip install things that expect Intel. But nonetheless, it's out there and people can start playing with it. I actually did a stream, live stream number six with Paul Everitt from JetBrains. So we're exploring what's the Python experience on the Apple M1 Mac mini.
So that's like an hour long video he and I did last Friday. And I will link to that. You can check it out. Well, what's the punchline though? The punchline is almost everything works, but we couldn't get JupyterLab to work for some reason. Oh, okay. But everything else seemed to be pretty much fine.
But the trick is you kind of need a lot of times you're going to work with something that maybe doesn't have an M1 version of the package or the wheel. But if you go to the terminal and you create a copy of it and then you tell it to run under Rosetta, every Python command you issue becomes a Intel Python command.
Okay. Anyway, we did a ton of that with stuff. Sherry, do you have an M1 Mac? Are you on? No, actually. I'm not on a Mac. I'm not on that. What's your OS of choice? Well, Microsoft. Yeah, Windows? Yeah. Awesome. Yeah. Yeah, they're doing good stuff. Like there's a ton of Python things happening over there.
And it's called OpenMV cam. And it's called OpenMV cam. And it's the latest one. It's a microcontroller development board with an onboard camera that runs machine vision algorithms with MicroPython. The OpenMV IDE and libraries make it really easy to run complex machine vision algorithms with simple Python code for things like color tracking, face detection, eye tracking.
One particular application that I really like, which I did, is detecting April tags, which are like QR codes in that there are 2D binary pattern squares, but they encode a much smaller amount of bits between 4 and 12 bits rather than a QR code, which can store up to 3 kilobytes. And so by storing encoding a smaller amount of data, it makes them easier to detect and be able to be robustly detected with variations in the camera viewing angle and the lighting conditions.
And they can be detected from a longer distance. And so it's just so convenient because the OpenMV IDE has an April tag generator. So you can easily create the tags and print them out. And it has an April tag MicroPython library. So you can easily implement the algorithm and the code will return the rotation and the ID code, among other information about it.
And the company OpenMV has said they want to be the Arduino of machine vision because they have such an Arduino-like user interface. And you can view the output of the camera in the IDE. And they actually just announced a few weeks ago that they're now partnered with Arduino to support computer vision on a new wireless Arduino board called Portenta 8.
7 with OpenMV firmware and the OpenMV IDE programmed in MicroPython. So it's really cool to be able to easily implement these complex machine vision algorithms with just a few lines of Python code on a plug and play STM32 microcontroller board. Yeah. Do you know what it costs? The latest one, I think it's, I got it, it's like 60, around $60.
And it's interesting to see how it compares to QR codes and they're more robust in detecting. Yeah. Okay. Yeah. And they have a little code example here that's quite straightforward, right? You just set the pixel format, how many frames, and then take a snapshot and run things like image.findblobs and like magic happens on that line.
Yeah. Yeah. That's super cool. So one of the things that I've always wanted to do, and I don't know if I'll ever do, but I want to create an IoT course. And I would like the final exercise of the course to be setting up a camera so you can have a multiplayer or a computer against human game, but have the computer do it through computer vision.
So over like a checkers board or a tic-tac-toe, like you draw on it, the computer looks at it and says, I want to go there. That would be so fun. It looks like this might be something I could use to make that happen. Yeah, definitely. I read that you can run TensorFlow Lite on it too, so you can train AI.
You should get into robotics also and have it just move it. The claw comes out, grabs it. How about Settlers of Catan? Come on. If we could automate Settlers of Catan. And your would be even better, actually, would be not just have the computer play, but in this whole weird social distancing, bizarro world we live in.
You could set it up so you and your friends just play and both have a board and the thing just tells you, oh, your friend moved here. You got to move that over. That'd be great. I've never even got through the instructions on Settlers of Catan yet. One of my daughters loves it and one of them hates it.
Well, what else have we got? I don't have any extras, Brian. I've already gone through my six extras. You got any extras? I just have one shout out to, I guess, the Python community on Twitter. I just want to say, I don't know. I'm getting a little cheesy today near Christmas. But this is a sort of a silly thing.
But I saw there was a discussion on Twitter. It happened last night and today. There was somebody named Nicole Carlson that started this question of, do you say for K-W-A-R-G-S, do you pronounce that keyword arguments or do you pronounce it quarks? Oh, my gosh. And I had never considered pronouncing it quarks before.
How about you, Michael? I think I did. I think I do say quarks. No, no. I say K-W-R-G-S. That's what I say. Okay. Yeah. So that was brought up by a couple of people that they use that. Yeah. K-W-R-G. That's what I say. And so I just, I'd never even consider, I like quarks. I'm going to start using that now.
Sounds like it comes from Star Trek. But, yeah. A Klingon word. I don't know. Or, yeah, or quark from Deep Space Nine. Yeah. So Vicky Boykas said, I've never even considered not saying quarks. And a whole bunch of other people had different comments. And I just wanted to bring this up because it reminded me of like a conversation we'd have over beer or something at PyCon.
Right? Like some people say PyPy and some people say IPI and so on. Right? I'm on the PyPI side. But it's just, you know, sometimes you don't have to pronounce it. But sometimes you do. Yeah. I'm not sure what side to take on this issue. Yeah. This changed my life though. I'm going to, it quarks all the time now.
Why? Tell us. Because bugs are attracted to light. Oh, yes. Awesome. I heard this on Twitter. It's terrible. And I told my family. It's one of those, sometimes some jokes you tell your family and they just stare at you. Yeah. Yeah. They don't get it. All right. Really quick. I want to follow up with one comment from the live stream.
And if you're not listening, you're not interested, you don't know about yet the live stream. We're also streaming this onto YouTube now. So check out pythonbytes.fm/YouTube and you can subscribe to the upcoming live streams. But Brian, there's a question here. When's your second edition coming out?
