Python Bytes - #66 Wait, NoSQL with ACID and transactions?

Episode Date: February 23, 2018

Topics covered in this episode: Object-Oriented Programming (OOP) in Python 3 ScriptedForms MongoDB to add multi-document transactions and ACID Python packaging pitfalls Blogging principles pipenv ...is officially official Extras Joke See the full show notes for this episode on the website at pythonbytes.fm/66

Transcript
Discussion (0)
Starting point is 00:00:00 Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to your earbuds. This is episode 66, recorded February 22nd, 2018. I'm Michael Kennedy. And I'm Brian Ocken. And we have a ton of stuff. As usual, we've scoured the web. And actually, I don't know about you, Brian, but I had a really hard time actually picking the topics. Every one I found was better than the last one.
Starting point is 00:00:20 It's exciting to see a lot of content out there. Yeah, for sure. So I want to say real quick, thanks to Rollbar. Check out what they're doing at pythonbytes.fm slash rollbar, add error reporting and real-time monitoring to your web apps and other things. We'll talk more about them later.
Starting point is 00:00:34 Right now, let's focus on modern Python a little bit. I wanted to bring up, there's a lot of tutorials on how to do object-oriented programming and also object-oriented programming in Python. But RealPython put out an object-oriented programming in Python 3, which I think is just a nice update, just making sure that everybody understands currently how to do things if you want to do classes and objects and inheritance. And to be clear, all of Python is object-oriented.
Starting point is 00:01:05 It's just everything's an object. I hope that's true. I'm pretty sure that's true, yeah. Even functions and numbers and all that stuff. What this is meaning is if you're going to define your own classes, how to go about doing that. And this is a pretty nice tutorial. One of the reasons why I wanted to call it out is there's a reason I'll get to later,
Starting point is 00:01:26 but he kind of didn't. He brushed by construction. So if you came from C++, one of the things that C++ does is it calls your base class constructors automatically. And I wanted to just call that out. Right. Especially if they're parameterless, right?
Starting point is 00:01:42 Like, it'll just happen straight down the stack, right? You don't have to be explicit, yeah. But in Python, you do have to be explicit. If you override init, the base class init will not get called unless you call it yourself. And there's been many incantations of it, and I think the recommendation right now is to just call super.init to call the base class constructor. Yeah, yeah, definitely. Very, very cool. Worth checking out.
Starting point is 00:02:07 It really digs into the object model and inheritance and all that kind of stuff. So if that's a little bit shaky to you, definitely check it out. Even has some little exercises and examples in there, right? I guess also if you're not a bad thing to brush up on if you're just about to go into an interview, probably. It's a nice article. Also, pay attention. I've been playing with adders a lot if I need objects. So make sure that it's a really easy thing to pick up if you want to check that out as well. Yeah, that's cool.
Starting point is 00:02:36 Adders is pretty sweet. Definitely a lot of really solid people make it a great recommendation. So it appears frequently at the end as the featured pi pi package on talk python for example yeah so you want to stay on a gooey trip for a while how about we keep going like we really opened a bag man like uh when i started that it really uh kicked off uh oh but michael did you hear about this did you hear about that and i'm i'm happy i did and i love all the things people are sending us. Learned about WXPython Phoenix, which I only knew about the older version, which is really awesome. I learned about GUI, G-O-O-E-Y, and WUI, and all these other interesting things. So I come to you,
Starting point is 00:03:16 Brian, this week with yet another thing called scripted forms. So tell me, how's your Markdown? I love Markdown. Yeah, Markdown's not hard. Yeah, it's not bad, right? So here is a project in Python that lets you basically sketch out a UI in Markdown. Then it becomes an interactive GUI with input fields and everything. Okay, neat. I gotta check that out. Yeah. So for example, like you want the title, like a big title at the top of your form or your window, hash space, type out the title. Isn't that cool? Yeah. Yeah. So you can do all sorts of interesting things in there. It's not like a lot of these are not totally general purpose.
Starting point is 00:04:01 But if you want a simple UI, check out this thing called scripted forms, of course, we're linking to it in there. And you just basically sketch it out. And it runs actually on Jupiter. But the way it gets packaged up is you just see like a desktop window pop up, and then it's interactive. So it's pretty cool. They got some examples and all kinds of stuff. You can have like sliders and live graphs and so this looks particularly interesting to data sciencey folks who have that kind of display stuff going on that's cool yeah it's cool right so scripted forms there's yet one more way in which you can create niche python gui apps and then bundle it up with something like pi installer
Starting point is 00:04:40 i definitely want to try that yeah yeah i do as well So do you know that I'm a fan of MongoDB? Yeah, you're like the Uber fan. I am the Uber fan. I love it. I talk about it, do stuff with it all the time. Like, for example, Python Bytes, the web app, is driven by MongoDB, for example. But you actually, you are the one to bring the big news,
Starting point is 00:05:01 not me, on MongoDB these days, right? I guess so. I was surprised, but I grabbed it. The news that came out on the 15th was that MongoDB will, and it doesn't do it right now, but in the 4.0 release, it will do multi-document transactions and have ACID data guarantee, integrity guarantees. That's kind of blowing my mind. Like one of the big things that Mongo's done is really focused on when it treats the document level record as the thing, that way we can do sharding and auto scale out and all kinds of stuff and not worry about like communicating across machines and clusters and all the other pitfalls you can run into by trying to do like
Starting point is 00:05:44 really complex transactions. So this, you're right, by trying to do like really complex transactions so this you're right this kind of is uh i didn't see this coming either so this is uh due out in the summer so the 4.0 will is supposed to do transactions and the 4.2 which is the i'm not sure when that's coming out that will even deal with transactions across sharded deployments. Wow, that's really cool. And it has snapshot isolation. So even the sort of repeatable read type stuff. Very cool. So yeah, they said sometime this summer, right? The ability to do transactions, and hopefully we'll get things like rollback and things like that. These are a lot of the reasons why people don't choose a document database. And so that changes the table of pros and cons.
Starting point is 00:06:25 It definitely changes the trade-offs that you're considering. I just find working with these document databases so much easier. Like the last time I ran a migration or worried about upgrading my database schema to match a new deployment was never. Like I literally have not had to run any form of update script for the last two years on training.talkpython.fm, on Python Bytes or any of these things, right? Like they just adapt and it just makes the sort of living with it so much easier. So I'm really happy to see it get one more check in the sort of comparison table in that column. Yeah, definitely. Yeah, very cool.
Starting point is 00:07:02 So if I did mess up my schema, something went wrong though, my web app would crash. That would call them. Yeah, definitely. Yeah, very cool. So if I did mess up my schema and something went wrong though, my web app would crash. That would be bad. And actually working with Mongo Engine, you can like basically take the site down because it'll like not read records if it thinks it's inconsistent with them. So that's a different type of problem.
Starting point is 00:07:17 Same thing happens with SQL Hockney. But if I did that and I had Rollbar installed like I do, we would know about it right away. We'd get little notifications in Slack and email and pop-ups and stuff saying, hey, the site is down. Something has gone terribly wrong. Like just the other day I was sitting around and I started getting all these notifications of something going wrong with the site. I'm like, ah, what is this? Why are these, you know, like on Python bytes and talk Python and whatnot. And I pull up roll bar and it says cannot find MongoDB server. How about that? And the reason is the digital version of
Starting point is 00:07:50 the host was actually patching the underlying Linux servers for the Spectre and Meltdown vulnerability. So they had to take the machines down and they didn't do it in like a controlled way because they're just like, we're telling you at some time we're taking the machines down. We've got to fix this. So even when it's not your fault, you'll know about it if you have this installed and you can at least switch, you know, switch up a dialogue or something, a page saying, oh, sites under super maintenance right now. Sorry. Yeah, that's cool.
Starting point is 00:08:16 Yeah. So super easy to install it. Not, not much work at all. Plugs into all the web frameworks. Check it out at pythonbytes.fm slash rollbar. So another kick that, that you've been on for a while, Brian, is Python packaging. Yes. We talked a lot about what the right structure that is and all those various things.
Starting point is 00:08:34 So this week I want to feature this thing called Python Packaging Pitfalls. It's not super new, but I thought it might be fun to cover anyway because we talked a lot about it and we haven't covered this. So a couple of items that I don't know how many there are, probably 10, 12 little things. Don't forget to do this. Don't forget to do that. Like don't forget, you know, so if you're doing packaging, you might forget to clean the build directory before you do it. Or you forget to specify package data, or using package underscore data or fine grained package data, all sorts of mistakes that are listed there. And it says,
Starting point is 00:09:12 why it's really nice. The article says, why is this a problem? How do you fix it? Like hard coding your packages in the setup py versus like discovering the packages with Python code in your setup UI. Yeah, these are all great tips. I haven't read this for a while. I remember reading it a couple years ago to try to make sure that most of these look like they're still valid. Yeah, I think so. One of them that might be nice and close for you is your test the installed code. They test what's actually in your working directory rather than running the setup
Starting point is 00:09:46 and testing the thing that actually was the result of that. Is that one of the things to avoid? That's one of the last things to say. Be careful of, make sure you test the actual install result, not just your code on development. Yeah. And that's one of the reasons why I really like Tox is because Tox creates like these clean environments. But you still have to be careful of that. Even with talks. That's why we talked about using a source directory. Absolutely. So a while ago, I had a bunch of authors, including you on talk Python about writing. And some people were asking, like, how do you become a better writer? And you said, by writing. Right?
Starting point is 00:10:27 Just get out there, blog, write, do things like that. So you came across something like that again this week, right? Yeah. I came across an article called Blogging Principles I Use by Julia Evans, which I think it's cool. She goes by Bork on Twitter with a zero. But I'm just going to read through her tips, and then we can talk about them. Be honest about what you know. Try not to write anything too long.
Starting point is 00:10:51 Be positive. Write for the past you. Stick with your own experience. It's okay if not everyone likes it. And a lot of these really hit home with me. One of the things, try not to write anything too long. I tend to try to completely get my head around something and not want to write about it until I completely understand it. And then sometimes I don't have time to do that. And I think that's
Starting point is 00:11:17 too bad. And I think I love it when people just have a little couple screens full of information of just, hey, I learned this neat new thing. Here's how to do it. And just go and teach it so other people can learn from you. It doesn't have to be huge. So be okay with short things. If you do short things frequently, that's probably better than saving up that one long post that actually never gets written, right? Yeah. Also, one of the things you can do is with metrics as well, if you, instead of writing a long blog post that has like five subtopics, write five different posts, and then you can find out which piece is resonating more easily. Metrics will just point it out.
Starting point is 00:11:56 Yeah, that's a really good point. The last one is, it's okay if not everyone likes it. And her example actually is, she's got a, I forget which article it was, but one of her articles is more popular than others. And she needs to remind herself to not try to keep up with that. It would be a mistake to try to hit that every time. That's actually something that hits with me is I haven't been blogging a lot lately. I do want to pick it up.
Starting point is 00:12:21 I think I need to, it will help me to try to write shorter stuff. And also, I've got a few tutorials out there that are really popular, and I don't know how to beat that. So don't try. Just write little things. I learned a few new things during the webinar today. I learned some new things about PyCharm, and I could just write a short blog post about cool things I learned about PyCharm today. Yeah, that's awesome. Why not? Yeah, why not? And definitely, I feel like these little series ones are real nice. Like I've done several, like here's, I'm going to write, I'm going to blog 10 blog posts in this kind of theme and those turn out to be really easy to write. But I also find that I periodically get distracted and just life gets in the way and i
Starting point is 00:13:05 don't finish them i have like here's the top 10 and like they have seven filled out you know yeah so i i mean i think that's a really great way to do it but maybe actually write the 10 and then do the hey i'm doing a series on it you know what i mean like kind of do it in reverse a little bit to bring it together what you you've done i think that one of the takeaways i would i would add is like it is so hard to predict what is going to be popular and what is not going to be popular. It's just, you know, you look at things and you think, oh, this is going to be so popular. And it gets like a hundred views. Like you're like, I guess I'll throw this out. Why not? I got a half hour and it's kind of on my mind.
Starting point is 00:13:40 And maybe it won't matter. Like it's thousands or hundreds of thousands of views. You're just like, okay, why is that like this? So just put stuff out there and it will happen. I think the write for the past you, I fall into this trap of trying to write for, either write for experts and try to impress the people that know more than I do, which that's a bad place to try to be.
Starting point is 00:14:02 And trying to write for absolute beginners, but I haven't been an absolute beginner for a long time. So I don't really know how to do that. So I think writing for like me a month ago, if I would have read this article a month ago, it would have saved me time. So just write it down. Yeah,
Starting point is 00:14:19 absolutely. Very cool. So we spoke about PIP and P I P E and V a while ago. But I want to bring up something that I just, I don't know why I found this. I just randomly ran across this. So I was looking at pipenv again for something. And so pipenv is a way to kind of package up virtual environment, dependencies, requirements.txt, pip, activating the virtual environments, all that kind of stuff into like one little workflow. Okay, now, Kenneth writes is behind this in a significant way. But I somehow was looking across it. And I saw it's on github.com slash pi pa, the Python packaging authority slash pip inf. Interesting. And then I scrolled down, it says pip inf, the officially recommended Python packaging tool from python.org. Free as in freedom. Did you know this is the official way?
Starting point is 00:15:11 Like pip and requirements.txt is apparently out? No. I didn't either. That was my reaction. Like, wait, what? I mean, I know there's pipfile and pipfile.lock and all that kind of stuff, but it seems to me, reading this at least, that because this comes from PyPA,
Starting point is 00:15:27 that pipenv is the way we should be doing things. So I don't know about you, but I need to study this and kind of get in touch with it because I feel a little bit lost when I use PIP-EMF. And I'm really confident with PIP and requirements.txt and all the stuff I do there. I guess I'm comfortable with PIP and setup files. So I will have to read up on this too. Do you know if you can just get away with doing this and then pushing a package up to API? I don't know. But one of the things you can do is you can tell it to generate a requirements.txt from its behaviors and its lock files and stuff. Okay. So let me give you the quick workflow. If you go there, there's a docs.pipinf.org,
Starting point is 00:16:08 which you can go to. And it has a nice little screencast from Kenneth Wrights. It's like four minutes. It says, let me show you this new tool. I've been working on it with a bunch of people and it seems really nice. Here's how it goes. And so you just go into a directory,
Starting point is 00:16:22 no virtual environment, nothing set up. And you say, pipinf install a thing. And if it's never run, it will create right there was a pip lock file, a pip file and a pip dot file dot lock. And it will somewhere in like your temp working area create not in that folder somewhere else, create a virtual environment and install it into that. If you type pip install a pipenv install another thing, it'll put it into that same environment because it now is like tied to the pip file, and it'll actually automatically add the requirement to your pip file and to your pip lock. And the pip file is like requirements.txt. The pip file.lock is like that plus the dependencies. So it's like pip freeze, everything, not just what you pip installed so uh it's pretty
Starting point is 00:17:06 cool and then you could just pip shell pip m shell to kick it off or you can find the there's a command for finding the virtual environment so then you can you know source activate it just tradition like traditionally okay and actually the the video is like the reason why i gave it a shot because just reading about it confused me even though I read it like seven times. I know. Why is this bouncing off me? But then you watch him use it in like this little couple minute video and it's like, oh, okay, that's easy. Yes, exactly. Another thing I like about it is it says Windows is a first class citizen in our world. Wow, that's rare. That is. It's really nice. Like I have a windows 10 setup, but I typically work on my Mac, but I know many, many people in the world use windows, especially in like large enterprise environments and having windows be a first class citizen in the Python space is good for everyone.
Starting point is 00:17:57 Yes. This is neat. Yeah. So, uh, just like really the news for me is like, it's a review of pip F, but the fact that it seems to be the officially recommended way over the traditional ways we've been doing it means I need to pay more attention. Yes. Very cool. All right. So that's our set of items for the week. You just did a webcast, right, which you will probably have live certainly by the time this goes – well, probably by the time this goes out. Well, it was already live.
Starting point is 00:18:24 It was live this morning. Well, I mean the recording will be out and Well, it was already live. It was live this morning. Well, I mean, the recording will be out and available. Recording should be out. Yeah. That was with, yeah,
Starting point is 00:18:31 the JetBrains PyCharm team. And that was super fun. I had a good time. We talked about using PyTest within PyCharm. And we just scratched the surface. There's a lot more to cover.
Starting point is 00:18:44 But it was fun. Sounds really cool. Awesome. So we'll definitely link to the video next time, I'm sure, because we'll know where it is. Also, I have two quick follow-up items. One is the pandas, the whole pandas project, super important in data science. Gosh, I'm sorry.
Starting point is 00:19:00 I forget the guy's name who sent it to me. I got a message saying, hey, we're having this really interesting idea of the Pandas documentation sprint. And these are throughout the world. And to say how many locations, I don't know. Quick counting, let's say 15 locations throughout the world, slightly biased towards Europe, but also everywhere but apparently Australia or Antarctica. There's these physical locations like San Diego, Seattle, and so on, where people are getting together to do sprints on the documentation for pandas. That happens on March 10th, 2018.
Starting point is 00:19:42 So a couple weeks. Yeah. And it has a countdown all the way down to the seconds. Definitely has a, yeah, down to the seconds. We start now. I think this is a cool idea if you've never contributed to open source and you want to get that checkmark on your resume and you want that on a major project. Here's a really cool way to become a contributor to pandas without deeply understanding it or having majorly adding a feature and also you get to hang out with people who are experts in pandas and so
Starting point is 00:20:12 those are probably good connections to make so check that out at python-sprints.github.io slash pandas that should be fun yeah and every open source project will love you if you write documentation for it yes Yes, absolutely. Okay, so really great. And then the other item I wanted to follow up with is we talked about the workflow in Unreal coming from
Starting point is 00:20:35 Autodesk, I think. Anyway, really, really cool stuff that they were doing there. And now someone followed up and said, that's really great. Do you know you can now embed Python in the Unreal Engine 4? There's this project called Unreal Engine Python, and it lets you just embed there. So it's like a plug-in for embedding the entire Python VM, three or two in there. And then, you know, you can basically add scripting into your game and let people write Python and control your 3D environment.
Starting point is 00:21:07 Pretty cool. So just a quick follow-up from when we talked about that before. Thank you for being here. It's great to chat with you. And I loved your picks this week. Thank you. You too. Bye.
Starting point is 00:21:16 Bye. Thank you for listening to Python Bytes. Follow the show on Twitter via at Python Bytes. That's Python Bytes as in B-Y-T-E-S. And get the full show notes at PythonBytes.fm. If you have a news item you want featured, just visit PythonBytes.fm and send it our way. We're always on the lookout for sharing something cool. On behalf of myself and Brian Auchin, this is Michael Kennedy. Thank you for listening and sharing this podcast with your friends and colleagues.

There aren't comments yet for this episode. Click on any sentence in the transcript to leave a comment.