- Podcasts
- Python Bytes
- #324 JSON in My DB?
About this episodeTopics covered in this episode: Use TOML for .env files? Pydantic gets serious funding f-strings with pandas and Jupyter keyboard…
- Use TOML for .env files?
- Pydantic gets serious funding
- f-strings with pandas and Jupyter keyboard shortcuts
- BioGPT
- Extras
- Joke
Transcript
From the publisherThis transcript comes from the podcast’s own feed, shown as the publisher wrote it.
#324 JSON in My DB?
I currently work at Energy Solutions as a code base lead on a Django project there, which means that I write and review a lot of Django and Python code on a day-to-day basis. Energy Solutions, where I work, is an energy consulting company that's mission-driven to protect the environment through different energy things.
All the wasted energy and bad insulation and other things like that. That's really cool. Yeah. That's good work. Really quickly, before we dive into Brian's item here, how are you feeling about Django and the recent changes? I feel like it's picked up a lot of momentum lately. It's picked up some new features like async stuff.
So what these are often is you've got settings for your application. And there's an idea of a 12-factor app design, which I kind of like read about many years ago and forgot about. But one of the ideas is you don't want to like have too many differences between your development environment and your live environment.
And so the question really is, what's the format of this? So, and I kind of never really thought about it before. And basically the problem is it's not defined. And it's in... There exists a text file that has secrets. Yeah. So with that. Yeah. And it says it's kind of like Bash-ish files or something.
It's by the... It's a format that's not formally specified and improves over time according to the Python.env readme. But that's not really... What does that mean? It kind of means it's your application so that you can define it however you want, right? But maybe we should have some standardization.
So Brett was looking further into this. And one of the solutions that Adafruit came up with was let's not use .env, but actually just do a settings.toml. And it's used for the same thing, to store secrets such as passwords and API keys. So they're using Toml. And then basically kind of when you just do a normal simple Toml file, it looks pretty much like a normal any other .env file that people have used.
So like in the VS Code code base, they're talking about like using categories and specific table to hit. You'd have multiple tables in there instead of just the global one. But I think that's a cool idea. I like the ability to have multiple things like test and maybe dev or like a connection string to a database or something.
Well, Michael, should we switch to Pydantic? I have some, I have some crazy news for you. Yeah, let's do it. First, huge, huge congrats over to Samuel Colvin. And I've had him on the show to talk about Pydantic before. Pydantic is one of the more exciting libraries, I think, especially in the API space.
But also Python Bytes itself is powered by Beanie, the MongoDB, ORM or ODM. And that is, uses Pydantic models as its validation in an exchange. Like the things that are mapped to MongoDB are Pydantic classes. So here's the news. The Sequoia, like one of the biggest VC firms in California, in the world probably, backs open source data validation Pydantic to commercialize with cloud services.
That's crazy, huh? Yeah. We are a long way from the buy me a coffee, donate PayPal button that you see on various projects in this. And I think it's just a sign of the open source space finding its way to support really successful projects and to support people whose time and energy and contributions to the world would be better spent to create, further this library than say potentially like, well, how can we get like 1% of 1% increase on ad clicks by using my library or something like that?
Wow. Yeah. That's big coffee. That is a lot of coffee. That's like coffee for life. Some of that fancy kind, you know, the weird variations and stuff. Yeah. Anyway, so it's not just Sequoia. It's Peratech, it's Irregular Expressions, it's Zapier co-founder Brian Helmig, who's also been on Talk Python before, and some other folks, co-founder of Sentry, David Kramer, so on.
So let me see. I wrote down some of the highlights of this whole article that I wanted to hit on. First of all, also this comes from Mark Little, who was a guest on show 285 and also a friend of mine. So thanks, Mark, for sending that in. The new, the whole, like, so you might be wondering, okay, well, $4.7 million is amazing.
But something a little bit akin to a platform as a service, something a little bit like a Heroku, where you can push Python code to production in simple ways. But using the validation and the data exchange and the understanding that Pydantic has for data as part of this. So final thing, then I'll get your thoughts on this, is you're going to start with an initial team of six.
Yeah. Yeah. How's this sit with you? Does this surprise you? No, it's cool. It's very cool. I mean, I'm just Googling it because I didn't research it ahead of this talk. But, yeah, it sounds like it can be used with any Python-based framework. Yeah, it came out of Fast. Yeah, it came out of FastAPI.
And it plays many important roles in FastAPI. It's the data validation. It's also the type hints that does the automatic data conversion. But it also drives the Swagger, OpenAPI documentation, and all those things. But it's been used way, way more places, for example, like Beanie, which I mentioned, or SQL Model, and plenty of others.
And it's just starting to gain a ton of momentum as a really solid data exchange for Python that's not directly talking to databases. So, yeah, it should be good to see it grow. What does that mean, not directly talking to databases? Meaning it just reads what comes back from the API and validates that?
Yeah, it basically will take any JSON. Or if you could take a Toml document and you could turn it into a Python dictionary, then you could pass that on and have it validated. So you could say things like, this class has a list, which is a list of orders. And there can be no more than three orders in the list.
And they have to be orders. And this thing has to be a number. And just all that kind of logic gets expressed in the model there. Yeah. Yeah, it's cool. So one, just, I guess, a random thing. So it's a team of six, first three engineers based in Montana, Chicago, or Berlin. I wonder who's in Montana.
Yeah. I mean, I do love the theaters in Chicago. The theaters in Chicago are beautiful. I do too. But I'm thinking of motorcycle riding for days in Montana and the cities and all that stuff in Berlin. Erin, where would you live? Man, between those, that's really a hard choice. I moved to North Carolina for shorter winters, so it seems like Chicago would be out for that reason.
Yeah. All right. Awesome. Well, over to you. What's your first topic? Okay, cool. Yeah, and I just wanted to go back to the Tommel topic because I kind of froze on that one. So we are using a YAML file for local settings, not a Tommel file. I haven't actually seen Tommel before. I don't really know how different looking it is.
I'm really interested in the topic of normalization and denormalization and specifically how JSON fields are basically denormalized and mutable data that's probably living in an otherwise normalized database. So I was interested in this topic and I searched to see if I could find it anywhere online.
And yeah, so what we're showing here is this was a talk given by David Stokes at PHP UK in 2019 called How Denormalizing Your Data with JSON Can Boost Query Performance. I always mispronounce. Do you guys pronounce it JSON or JSON? And I'm sure you've talked about this before. I guess, I hadn't really thought, I'd say JSON, like on top.
And it stands for JavaScript Objects Notation. But yeah, I think my filly comes out because I'm always saying JSON. So, yeah. So David Stokes gave this talk. He is a technology evangelist. And a lot of the talk was about MySQL as a backend in particular. But the parts of the talk that I found really interesting are the history lesson.
And normalized data, just a quick definition is like, or example, is like taking an address and breaking it down into parts. So experts, you know, had been saying for years at this point, like normalizing data is the way to go. You want to normalize your data. And then during this history talk, you mentioned, and then no SQL came in and shook things up.
And after that, SQL added JSON data types or a mutable data type. So you don't have to define and normalize your whole database. You can kind of have these mutable fields. So, okay. So anyway, the history lesson, I just found that super interesting as a data person. Do you guys find that interesting at all?
I do. I do. Yeah. I think that this concept of mutable schema, not mutable data per se, but that the schema itself doesn't have to be as controlled and as strictly guarded by a DBA that goes through some giant process to figure out what you do, can add a ton of flexibility to the way that you evolve your app.
Right. So there doesn't necessarily have to be a DBA. It could be like, well, how, how are we going to schedule the downtime so that we can do the schema migration as we roll out this new feature? Right. Like those kinds of things can get challenged, challenging. If you roll out the code first, then, and it's some kind of relational thing, you're using SQLAlchemy or something like that.
It's going to crash saying that the code doesn't match the database. You roll out the database first, you know, it may no longer match what the code that's running is. And like, there's always this, well, what do I do? And having some of this more mutable schema, in this case, they're talking about MySQL.
Yeah. And not only flexibility, but also quicker querying. So yeah, so I really liked starting around minute 14, which is, this is what I was kind of looking for when I was looking for this topic. So I really liked that he gave this talk about it. He goes over an example of a music store and you have these items in a music store, like guitars, and you don't want to have to add field every time there's a new guitar feature, right?
So you have these, these JSON fields in your database. And like you said, they're available in lots of different backends. We use Postgres and yeah, we use JSON fields all over the place. So, and he has this really cool diagram where he shows, you know, reducing database dives and many too many joins where you're diving from, you know, you know, one index into another, into another to just to get at the data that you can get at the top level if you have it in this JSON field.
Right. You don't have to do a multi-way, many to many join when it's just in there directly, right? Because you have more flexibility. It doesn't have to be tabular. Yeah. Yeah. So I found it really cool. We use JSON fields in one of our big Django projects quite a bit. And yeah, our data is totally, our schemas are normalized.
But we, we find it really helpful for also for reporting, making reporting really, really fast because of that database dive that you don't need to do. And also for tracking snapshots of data. So something happened on this date and then the relational record changed, but the JSON gives you the snapshot of, of what the user did on that date.
So that's really useful too. Because if the snapshot doesn't match the current schema, well then how are you going to store it? Like that gets to be a problem, but just JSON is JSON. That's right. Yeah. Yeah. I guess I've taken this kind of to the far extreme in my world. So I'm a huge advocate, but doing, I do almost all my work on MongoDB, which means it's, it's all JSON all the way down.
All right. So, but I think it's absolutely fabulous way to work. I love it. The operational side of not doing massive migrations all the time. It's really, really good. Yeah. And I'm actually working on a blog, a blog article about it because I couldn't find what I specifically wanted to talk about today.
So I'm, I'm writing up a blog article. It's not published. It won't, it'll be published next month. But yeah, I'll share it later with you guys. Yeah. Yeah. Please do. And I think that's, I think that's a great, actually a great thing for people to do is just, there's a discussion of something and it does, if you can't find an article that expresses what you want to express, then write one.
It's great. Yep. Indeed. All right, Brian, how about I tell everyone about our sponsor before we move on? Oh, that's a great idea. Yeah. As I said at the beginning, this episode is brought to you by the compiler podcast from Red Hat. And just like you out there listening, we're big fans of podcasts, Brian and I, and we're happy to share one of the most highly respected, one from the most highly respected open source companies, Compiler, original podcast from Red Hat.
It brings together a curious team of red hatters to simplify tech topics, provide insight for a new generation of IT professionals. And the show covers topics like what are the components of a software stack? Are big mistakes that big of a deal? And do you have to know how to code to contribute and get started in open source?
And not all, not always. Depends on how you're trying to contribute. So Compiler closes the gap between those who are new to technology and those behind the inventions and services shaping our world. And they bring together stories and perspectives from the industry and simplify its language, culture, and movements in a way that's fun, informative, and guilt-free.
I recently listened to Are We as Productive as We Think? And that episode is really fun. There's a bunch of good advice in there. As a developer, owner of our tech company, and a technologist, these productivity hacks such as time boxing, focusing on one task at a time, and incorporating intentional breaks into your workday all stood out as super relevant.
So learn more about Compiler at pythonbytes.fm/compiler. The link is in your podcast show notes. Thanks to Compiler and Red Hat for keeping this podcast going strong. Awesome. All right. Yeah. Thanks. Fun show. And tell us... You gonna take us to school, Brian? Yeah. So Kevin Markham is a friend of the show, a friend of ours.
Ran into him a lot during... When I was going to conferences more. That's hopefully coming up again. What are those? Conferences. You know what? People get together in real life. But... So Kevin took a little bit of a break. He used to write a lot. And I guess I hadn't noticed. But there's a break between August of 2021 and then now in February of 2023.
So a couple of your break. And we all need that. That's fine. But these articles are great. So a couple of new articles that he has. I'm gonna pop through a couple of them. How to use f-strings with pandas. So basically, it's a good discussion of f-strings. If you're not comfortable with f-strings already, this is a good intro to why f-strings are great to pop in values.
I don't know if it's really that panda specific. But one of the things I really loved, I'm gonna pop to my favorite part of this article. So... And I forget to do this. So I'm glad that he points these out. So one of the things is you can... It's not just taking a value and putting it in brackets so that you can print it.
The part that it really... It never really occurred to me to do that I wanted to highlight was he had different columns of data within like a data frame and referencing him with a string index. And then using F string as the... To pick the index within a, you know, a loop. And it never occurred to me to use f-strings to generate the index in...
There's some great stuff like just, you know, hitting escape and enter to go back and forth between command mode and edit mode, for instance. And then I'm going to tell you going to remember this one. A and B for create a cell above or below the current cell. So these are just some really great little Jupyter tricks to make yourself more productive and not have to touch the mouse as much.
It's just not going to have it. Erin, what are your thoughts here? The F-string article was really nice. Yeah. It's hard to find a good F-string article that tells you all these different things you can do. So I was just scanning through it and we use f-strings quite a bit. And if we have old format Python strings that are in the code that we're updating in a pull request, we always ask the developer to please update those old ones.
I can tell you that Flint does. Flint. Yeah, that's it. Flint. So I've taken Flint and run it against large projects that I've done. And in the early days, it introduced one bug out of 20,000 lines of code. But it rewrote like 1,000 string formats of various versions. And I found it to be really helpful.
And that's F-L-Y-N-T. Yeah. For the podcast listeners. Exactly. Thank you. Yeah. So this is really good. So if you ask people to do that, you could suggest like, and you could try just running this on your code. Yeah. And just make sure it doesn't break anything. But it's been pretty stable since the oddities it hit.
See last episode. Yeah, exactly. That was a whole debate last episode. All right. My next item is BioGPT. And so we've heard about ChatGPT. And this is similar stuff, but applied to biology. So, Brian, you said you hadn't heard. Create me a cat that barks. Exactly. And now make it mutate into a snake.
It's like nested over. So the code starts in the middle, maybe a bit to the right of the screen. And it says return true, right? Like you shouldn't do that. What should you do? You should write guarding clauses. So check this out, Brian. If I go over to ChatGP and I say, I'm going to give you a program in Python.
Rewrite it to check for crocodiles. Look at this. So sure. No problem. We're going to write, is it a crocodile? And look, the tests are, is it a reptile? Has scales? Does it have jaws? Does it have a four chamber heart? Wow. Is that insane? All I did is I'm going to give you this code and just start asking questions.
So, okay. So impressive, right? So back to chat, BioGPT. Think of what this can do for doctors and nurses and people trying to understand like written text of this. So it contains, this BioGPT contains an implementation specifically trained for like medical analysis. Kind of like chatGP is a general analysis tool.
This one is like specifically for medicine. Okay. So pretty cool. Apparently it can do pub med QA tests. I have no idea what that is, but if I was a doctor, I'm sure this is like, how good are you answering questions with 81% accuracy, which might sound like, well, that's 19% not good enough, but I bet you doctors don't do it at 100% accuracy either.
You know, there's a lot of examples where AI is predicting cancer sooner or better or more accurately than. And I bet it's better than like Dr. Google and looking up your symptoms and thinking you have the worst thing. Yeah. Yeah, exactly. Well, that's what I was curious about if it was named like, like, what am I dying of today?
Will, will I die GPT? I don't want to know. Oh, it seems grumpy. I don't know. So it comes with different models. It has the GP, the BioGPT one, but it also has the large one. And my experience with this stuff is the large models are where it's at. The, the regular ones are quick, but they're not very accurate.
Like I said, I'm not a doctor. I don't really know a reasonable thing to ask it, but it's, it's a weird world that we live in and it has lots of positives and lots of negatives. I'm sure that we're going to come to learn about, but BioGPT, if you're working on analyzing medical texts, check this out.
Yeah. That's really cool. Indeed. All right. Well, I guess I was joking about it a little bit, but I think there's a lot of power there. I mean, like you said, I don't know if we can get doctors actually seeing people more, but also, you know, maybe a 911 call could like, if we determine it's not an emergency yet, but maybe we could direct the person to the right place faster.
I mean, there's lots of places where maybe somebody not with a, like the full degree, but somebody that's still pretty involved with medicine can, can utilize this to ask the, ask better questions and get somebody to somewhere faster. Right. Or even highlight, you know, what were the key takeaways from this visit with the doctor?
Yeah. Right. Yeah. So anyway, it's cool. Yep. All right. One more bit of feedback out there. Will McGooghan. Hey, Will. This is the kind of thing I'd like to see from AI, AI used for not putting artists and copywriters out of business. Yeah, I agree. Define people's good work, not necessarily replacing it.
Yeah. We'll see where it goes. All right. Erin, got the last one. Okay. Great. So yeah, talking about code mentorship and communicating with new developers, that's my next topic. So Sheena O'Connell gave a talk at DjangoCon last year. I attended that conference, but I missed this talk and watched it online later.
They had Sheena on. And she talked about her work at Muzi. And she talked about getting learners to review each other and also teaching green developers how to use GitHub and things like that. So they don't, quote, bother their teammates too much once they get into their jobs after they're finished at a Muzi.
And she specifically said, the quote I liked was, what sort of thing does a person need to know in order to not annoy their coworkers in the first three months? So I really liked thinking about the learning in that way. And yeah, so something we started doing recently where I work is we had been doing code reviews.
Me and the other code-based lead had been kind of just doing them all ourselves. And our project manager, Matt, suggested we take, we have a new requirement where two non-code-based leads have to review any pull request before any code-based lead looks at it. So that's something we just implemented.
So someone who is further along in her course gets to both learn how to review code and also review someone else's answer. Because, you know, with Python, there are like a lot of different correct answers, right? So just like reactivating that part of their brain to look back at the previous answers is kind of cool.
Yeah. Where are you going to? I also think that it's cool that they're learning more than just loops, variables, functions, you know, but how to coexist as a teammate in a software team. Yeah. Yeah, that's cool. Yeah. Good find there. Yeah. So we're always looking for new ways to like onboard developers.
Instead of giving them a whole ticket to work on, like half finishing you a ticket and like letting them fill in the other blanks is kind of cool. And just one more article that I found about this was on the Cactus blog. I used to work at Cactus as a Django developer there. And so I still follow their blog quite often.
And they had this recent blog post from Dimitri Chukin about their new internal mentorship program there where they have three different paths. And one is apprenticeship for folks just starting out as developers. One is for fellowship. And that's for people who are currently training in one of those coding camps.
And it'd be great if they also knew like RF measurements and stuff like that. And you just can't find those people. So you have to pick what you, where you want somebody to compliment somebody else with and, and know that you're going to have to help train. Right. They support them in the other areas.
So we, especially for long running things, we have a practice of using draft code reviews. So code reviews and draft so that, and GitLab won't let you merge it if it says draft in the title. So, so then, then people can just keep updating that and then, then get feedback even when it's not ready, when the code's not ready yet.
So Pike Cascades coming up soon. Yeah, indeed. Coming up very soon. Excellent. Aaron, how about you? Want to throw anything out there? Yeah. DjangoCon US is in Durham, which is 15 minutes from where I live. So I'm excited. Nice. North Carolina is a fun place to visit. Yes. It's generally warm, although not always warm, but generally warmer than a lot of places.
Oh, that's so smart. Like they might put a virus in request instead of requests with the plural, you know what I mean? Or, or if you transpose two letters and there's some stuff that they're, the PyPA is trying to do to work that, but it's still tricky. Or standard lib stuff that you don't have to install.
It's just there. People. Right. Right. Right. yeah. And it's create a package for that. All right. that's not the end of it. Another one. Brian, do you remember I announced, Hey everybody update your get. There's a, security vulnerability in get. This is the first time this has happened in a really long time.
Yeah. I said, make sure you apply get or you install 2.39.1 or higher. Well, guess what? 2.39.1 has a vulnerability that's completely different. But if you try to clone from a malicious repository, you're going to be having a bad day. So update your get again. All right. and then also I'm working on a project now where I needed a, an ignore file, but the project was originally created in one language and I wanted the ignore file for another.
Well, there's actually a repo github.com/github/gitignore. And every single language that you could have chosen that dropdown has its ignore file here. So for example, the Python one, this, it's checked into this project. So when you say create a new Python project, what comes out as the ignore is actually this file.
So if there's people out there who really need a change to the default behavior of the Python .gitignore for projects, you know, you could go to a PR for this, but the way I use it is I just said, I also need one on Flutter or, there's not a Flutter one, but there's a Dart one. So I got, I grabbed the one for Dart and piled that in there as well.
Add it to, or even if you're not using GitHub, you can use this for. Yeah, exactly. It has nothing to do with GitHub. It's just, you have access to every version of an ignore file that GitHub thinks is good. Related to that is .gitignore.io. This is another one. You come down here and search for other stuff.
And then, you know, see. Type, type by test, see if it'll do. No results found. Oh, oh, sad. Yeah. Sad face. Okay. But anyway, if you're looking for ignores, for projects, there you go. Those are kind of nice. Cool. Nice. All right. Are you all ready for a joke? Yeah. Yes. Brian, I thought about you on this one in particular, so we'll see, we'll see what you think of it.
So this is one. It has, it's a cartoon and it has a cartoon character looking at two red buttons. They're both going to do something massive. One has the star asterisk character and one has the ampersand. And there's the person there just sweating out like, their fingers in the middle, doesn't know which one to pick.
