Python Bytes - #70 Have you seen my log? It's cute!

Episode Date: March 23, 2018

Topics covered in this episode: Online CookieCutter Generator cutelog – GUI for Python's logging module wagtail 2.0 peewee 3.0 is out Machine Learning Basics Cerberus Extras Joke See the full ...show notes for this episode on the website at pythonbytes.fm/70

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 70, recorded March 15th, 2018. I'm Michael Kennedy. And I'm Brian Ocken. Brian, how are you doing? I'm doing great. It's good to talk to you again. Yeah, you as well. Super excited to talk about some of these things that you got here. Before we do, though, let's just say real quick thanks to DigitalOcean.
Starting point is 00:00:21 They're sponsoring this episode like they do many of the episodes. So check them out at do.co slash Python. You know, I'm a big fan of cookie cutter. I've done a couple of things with it. Yeah, actually, I'm warming up to it and I use it for quite a bit now. That's nice. You found an interesting online cookie cutter thing. What is this? It's from Konstantin Pavlovsky.
Starting point is 00:00:43 That's a cool name. Anyway, online cookie cutter generator. And so cookie cutter is a command line thing where you point it at a you give it a link to a usually a GitHub cookie cutter, but you can have them be local also.
Starting point is 00:00:58 And it starts asking you questions about what you want to fill in the project and then it starts like a Python project for you. You could probably describe it better And then it starts like a Python project for you. You could probably describe it better. It's more of a templating thing you could do anything with. It's pretty interesting. So the way cookie cutter works is it's a CLI thing and you run it and it will ask you questions, right?
Starting point is 00:01:15 Like what's your email address? What's your full name? What do you want to call the project? Do you want to use ginger to or chameleon templates, et cetera, et cetera. This is like that, but it's like a website with a web form that asks the questions like that way, right? Right. So he doesn't have like everything up, but he's got quite a few up now that are some of the common templates, like the PyPackage and PyPackage Minimal and a Flask and Bottle and a few, and actually quite a few others.
Starting point is 00:01:43 And instead of doing on a command line, you select it and it shows you basically all of the questions that you're going to get asked. And you can just fill it in and then generate a project and it generates a zip file for you and you can download it. So basically, if you don't have Cookie Cutter installed, you can still execute the Cookie Cutter template by going to the site. Yeah. Nice. You just kind of want to see all of the, all the questions before you get going, gather those up first. That's quite cool. I thought it was neat. And he's a, he's a pretty
Starting point is 00:02:14 cool guy on Twitter. So if you have a favorite cookie cutter that you'd like to have him put up there, I bet if you just contacted him, he'd probably put it up there. Yeah, for sure. Very cool. So check out the online cookie cutter generator. I like it. So did we go on like a rant about GUIs for a while? Yeah, for a bit. Yeah. So I'm not exactly going to talk about like another GUI platform that like, I don't know, takes restructured text and turns into a UI, nothing like that. But there is a really cool project that integrates with standard Python
Starting point is 00:02:45 logging. So Python logging works in a certain way where it's got like the time and then like the module or the category and then the level like trace or info or error, and then the message, things like that. So someone built a really cool UI that will let you in real time, watch and accumulate the logs into a rich application just by starting up and running it. Oh, this is actually really cool. Plus you can filter your different levels and filter them out. Exactly.
Starting point is 00:03:15 So like, imagine if you want to tail your log, right? I'm going to tail it and see what's coming through. And then it's just like ripping by like, oh my gosh, there's all this stuff. Was there an error? I'm going to search. It's kind of hard to correlate right so what you do is you install into your app you install a socket handler as one of the trace sources and then you just this just listens to that udp source so you install like a like a socket handler thing and then you run this app and it just boom it just
Starting point is 00:03:42 starts capturing the logs in real time as as if you're tailing them. But with a UI, you can filter and sort and interact with. Yeah, and change the color on them and stuff. It's got a dark mode. You know it's for developers. Yeah. Yeah, but quick shout-out to just the framework, though. It is based on PyQt 5, and it's all open source,
Starting point is 00:04:01 so you can go check it out and see how they built it. It's a pretty decent-looking app. Yeah, and actually, I haven't been putting a lot of levels of logging in some of the work apps that I do, but I might with having this logger like that. It's pretty cool. So it allows any number of simultaneous connections, so you can have different people can watch it. You can change the look of the field. You can filter, like you said.
Starting point is 00:04:23 You can search. You can view exceptions and tracebacks and stuff on separate windows. watch it you can change the look of the feel you can filter like you said you can search you can view exceptions and tracebacks and stuff on separate windows so you can like pop out the traceback and just look at the details it's pretty cool yeah okay yeah very nice so there's a really cool cms for python called wagtail right yeah and i'm actually surprised we haven't talked about it yet but there's um i know that when i think of a cms i'm usually thinking like for for a lot of stuff i think of uh like like maybe wordpress or what's another popular one like uh squarespace something like that drupal drupal drupal that's it yeah
Starting point is 00:04:58 there is one for there's actually i think there's several for python but Wagtail is one of the more popular ones. And it's got a really nice look. And 2.0 just came out, and they're pretty excited about it. We did cover Django 2.0 changes recently, and this Wagtail 2 does support Django 2. And there's apparently a better, newer text editor that they're excited about. And some fixes in scheduling your published content. Yeah, it's awesome that it's based on Django 2. And of course, that means
Starting point is 00:05:31 goodbye legacy Python as well, right? Yeah. But one of the things that I wanted to highlight as well while we're talking about Wagtail is if I'm thinking about a different framework, often I kind of want to know
Starting point is 00:05:44 really what it's going to be like. And that's really hard to tell without just starting it. But they do have a couple things to help. We're going to link to both of these. One of them is a gallery of sites made with Wagtail. So it isn't really how to do this, but these are things that are possible with this framework. And some of them are professional professional and they look really nice. Yeah, they do look really nice.
Starting point is 00:06:06 And like the whole, what one is it? It's the Royal College of Art in London. Its entire site is driven by Wagtail. Wow, that's nice. And then there's a couple of e-commerce sites that are in there too. So you can set up e-commerce as well. And then the other thing is
Starting point is 00:06:22 they have a Zen of Wagtail page that talks about, they have a Zen of Wagtail page that talks about, they have kind of their design philosophy of how they're set up their code and what they're in with the end user. So that's neat. I like it that they have that kind of philosophical guidance to help you
Starting point is 00:06:37 to go along. It's cool. Yeah, I would definitely consider Wagtail if I was building a site and other people had to add stuff to it who were not developers and you wanted it to be CMS-like. It's very cool. Yeah, actually, I think I'm going to set up something for work using Wagtail just to try it out. Yeah, super nice. So speaking of setting up stuff, let me tell you about DigitalOcean. So with DigitalOcean, you know, you go and create a new server and you get like a Linux machine of some variety that you pick you SSH in and then you
Starting point is 00:07:06 begin your process of building your infrastructure, right? Do you want WordPress and you got to go set that up? You want Django, you've got to like make sure Python's installed, all the things are all set up and and whatnot. That doesn't even mention the database, right? So one of the cool things that they have that I want to highlight is they have the ability to create what they call one click apps. And those are actually entire virtual machines that are pre configured to run the thing that you want. So you want to ghost for, you know, like that blog service, static blog service, whatever it is. So you just click go to the one click apps and say I want to go server boom, it's up and running. You want to my SQL server, click that you got it MongoDB configured. So it's
Starting point is 00:07:43 all safe on the network click that super cool they have discourse they have wordpress they even have a machine learning and ai pre-built thing so you want to have click that and then just log in and start doing your tensorflow and things like that it's just like ready to roll yeah one of the things i like they have a gitlab one so you can set up your own uh like a your own team github like thing so yeah that's super cool you don't need to know that much about it right it's like all the stuff is set up and own team GitHub-like thing. Yeah, that's super cool. You don't need to know that much about it, right? It's like all the stuff is set up and running. You just have to be able to keep it running, more or less.
Starting point is 00:08:11 Cool. Nice. All right, yeah, so check them out at do.co.python, and they're big supporters of the show, so check out their stuff. Tell them thanks. So I'm a big fan of databases. We talked about MySQL and MongoDB there.
Starting point is 00:08:22 What's the most popular way of accessing databases, you think? What would you use? Raw SQL statements. I'm sure it's the most popular. But outside of that, I'm thinking like Django ORM, SQL Alchemy. Like these are the major tools, right? Yeah, ORMs. Yeah, the ORMs.
Starting point is 00:08:38 So there's another one that's really cool that's really small and lightweight called PeeWee. You would never know by the name. It's a good name, actually. It is a good name. So it's a simple and lightweight called PeeWee. You would never know by the name. It's a good name, actually. I like it. It is a good name. So it's a simple and small ORM. There's a few but very expressive concepts to make it easy to learn, intuitive to use, and so on, right?
Starting point is 00:08:55 That's what they say about it. It's been around for a while, but the news is they did a complete rewrite of it and released PeeWee 3.0. Nice. Yeah, so it's pretty cool. It's developed withee 3.0. Nice. Yeah. So it's pretty cool. It has, it's developed with Python 3.6. So it like embraces all those features. It has built-in support for SQLite, MySQL and Postgres. Those are all nice. And it has extensions for things like
Starting point is 00:09:16 full-text search and migrations and whatnot. So that doesn't sound so PeeWee. Actually, that's a lot of features. It's a lot lot of cool stuff one of the reasons it's really interesting to me is because there's a separate project called peewee async okay one of the challenges you have like doing any async stuff is like everything that is blocking or slow has to be async or there's kind of no point to even getting started right if i'm going to call a web service i have to use like h the async the aio http client or it just doesn't make sense right it's just blocking like there's no async behaviors and youO HTTP client, or it just doesn't make sense, right? It's just blocking. Like there's no async behaviors. And you run into that problem often with accessing databases, like say SQL Alchemy and stuff.
Starting point is 00:09:52 So this thing, PUE Async, will let you add async ability to your queries. So it's super cool. So you can go, if you want to insert something, you would just say, like, await objects.create, and you pass off the object you're going to insert to the database. You want to do a query, you just say, like, all objects equals await objects.execute, like, you know, your model.select, like in the syntax. So it basically allows you to just plug in this async and await
Starting point is 00:10:19 to very, very minimal effort to make your code much more scalable. That's pretty cool. Yeah. Neat. Yeah, so I'm pretty excited to see them doing this. This is really cool. All right, not a whole lot more. very very minimal effort to make your code much more scalable that's pretty cool yeah neat yeah so i'm pretty excited to see them doing this this is this is really cool all right not a whole lot more i just i think this this is a really cool thing that's out there and i wanted to shine a little bit of a light on it because i think uh django and sequel alchemy get most of the sunshine yeah so i i told you that digital ocean you can go push that button and create a machine learning
Starting point is 00:10:41 thing but what if you don't know about machine learning? Which I'm kind of in that camp. I know most of the buzzwords, but I haven't really done much work in it. So I was excited to see that there was somebody that put up a repo, a GitHub repo, called Machine Learning Basics. And the idea behind this is it's a repository of a lot of the machine describing and showing a lot of the machine learning algorithms, but not necessarily how you would do it in production. Because in production, you've got all these like fancy server tools that you can use to make things really fast. But if you're just trying to understand the concepts, I'm kind of one to just I want to see the code. And so what they've set up is a bunch
Starting point is 00:11:26 of Jupyter notebooks, actually, to go through and describe how you would do it in raw Python. How would you do, what does it mean to do linear regression or logistic regression or k-means clustering or k-nearest neighbor. And
Starting point is 00:11:42 there's a bunch of different algorithms there. And if you're just sort of learning what these are, being able to look right at the code and being able to play with it, I think that that might help before you jump into using some of these extra tools. I think this is really cool. And it's super simple.
Starting point is 00:11:58 The pictures and graphics are really clear. The notebooks are just a couple of pages. And yeah, it's just pure Python, right? It's not like, oh, you call this thing a TensorFlow, then magic, magic things happen, right? It really shows you the steps. So quite nice. Right.
Starting point is 00:12:11 I mean, when I'm just learning stuff, and I don't need it to be fast, and I don't need to hook up to TensorFlow right away. I just want to know more about this stuff. This is a great thing. Yeah, definitely. Yeah, well done. And if you're getting started, then definitely check that link out. All right, so final thing I want to know more about this stuff this is a great thing yeah definitely cool yeah very well done and if you're getting started then definitely check that link out all right so final thing i want to
Starting point is 00:12:29 talk about is seboras very cool name for a project it is a cool name so it's got this uh i think creek name i'm not sure so it's the name for the god or the character that is the watchdog of hades whose duty it was to guard the entrance. So the idea is that this is a validation framework created by Nicola Erosi. And what you do is you can give it like a schema. So the schema is a dictionary, it has the names of the fields, and then you can do type validation, min max validation, all sorts of different things that you can plug in there. So you create this dictionary, that's where it says, these are the fields I want to validate.
Starting point is 00:13:09 And here's their types and restrictions and whatnot. And then if you receive any form of document, it could be from like a rest post, it could be something you'd read out or write to a database, whatever, any kind of dictionary, you can just say validate this and it'll go through and validate. So like make sure that say the name is a string or if you say the age is five, but in your schema, you said it's an integer and the minimum is 10, you'll get an error back. Sorry, there's a problem or set of problems. One of them is the age and the min value is 10, but you gave five. Okay. What do you pass it? Is it a JSON or? No, it's just a dictionary. Okay. Yeah. So it looks very JSON-y, but you just give it any dictionary. And so anytime you're reading data that comes in in a dictionary form and you want to validate it,
Starting point is 00:13:52 this is a really rich and extensible way to do that, right? So quite cool. That's a great way to write at your API level to make sure that bad data doesn't go down to the rest. Then you can simplify your code in the rest of your project because you can assume that data is going to be in the right forms. Absolutely. Like these fields are required. It has to be this format. You don't have to go, okay, well, I know it comes in a string. Can I convert it to an integer?
Starting point is 00:14:17 No, that's an exception. Okay, so then I'm going to capture that error and save it back, right? There's just so many if statements and clauses for testing. You could just define these schemas in one place, call validate when you get the data and off you go. It's really, really nice. Nice and really very cool
Starting point is 00:14:32 that you put that as a separate project so that other projects can use it. Exactly. So this is used in the E-framework, which is a RESTful framework based on Flask and Mongo. But instead of baking that into the framework, it's like, I'm going to create this validation thing,
Starting point is 00:14:44 which is totally separate. It makes sense to be used wherever but it just also happens to be the validation layer in the rest framework so quite cool neat yeah very very neat all right for all the cool things you found yeah thank you bye hey everyone just a quick bit of news before we get out of here when brian and I recorded, I didn't have anything to share, so we didn't talk about it. Since then, I've just launched a new course over at TalkPython Training, and it's called 100 Days of Code with Python. So if you're thinking about doing 100 Days of Code, or you want this big challenge where you write a little bit of code each day, check out the course at talkpython.fm slash 100 days, so 100 days. Thank you for listening to Python Bytes.
Starting point is 00:15:28 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 Ocken, 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.