Improve Matplotlib With Style Sheets & Python Async for the Web | Real Python Podcast #125
Key Takeaways
The video discusses improving Matplotlib with style sheets and Python async for the web, covering topics such as async programming, matplotlib customization, and performance optimization.
Full Transcript
welcome to the real python podcast this is episode 125. have you thought the standard output from matplotlib is a bit generic looking would you like a quick way to add style and consistency to your data visualizations this week on the show christopher trudeau is here bringing another batch of pi coders weekly articles and projects we cover an article about the magic of creating style sheets for matplotlib you can quickly customize plots and graphs with a single line of code we share additional resources for you to try out new styles and learn what parameters are customizable christopher covers an article about using async for web development in python the creation of python generators inspired the development of async functionality he discusses recent changes and async additions within python web frameworks we cover several other articles and projects from the python community including how you can install a pre-release version of python caching in python with lru cache ways to get better at debugging suggestions of libraries that deserve attention a python library for creating mathematical animations and an extremely fast python linter that is written in rust this episode is sponsored by platform sh discover an alternative to diy for your web fleet and all the stacks it contains on a single stable platform find us at platform.sh all right let's get started [Music] the real python podcast is a weekly conversation about using python in the real world my name is christopher bailey your host each week we feature interviews with experts in the community and discussions about the topics articles and courses found at realpython.com after the podcast join us and learn real world python skills with a community of experts at realpython.com hey christopher welcome back mr bailey good to be here yeah i'm excited to dive in this week we have one little tiny news thing i wanted to hit on and then one kind of related news item on the 7th of september there was a quick security content thing that came out python 310.7 and 3914 and 3814 and 3714 all became available lots of regular bug fixes and i'll put a link to that for you if you're just learning a little more about it but yeah keep your python up to date for security content stuff the other one is related to the upcoming release of python 311 we've been talking about it a lot this year and real python our python release article writer in chief garage yela he uh kind of did a different approach this year he started writing articles as sort of beta releases and even some of the alphas as he kind of went along these sort of previews we're getting to the point now it will be the first week of october that the new version should be coming out and we're gonna do our typical coverage which would be an article talking about the new features a video course which you're going to be involved with still christopher trudeau there and we'll probably also do a podcast episode which has been our trend so lots to expect from but i wanted to mention an article that came up on real python that garanna also wrote that is in a new format for real python it's a qa sort of question answer format and this one was how can you install a pre-release version of python and that may seem really obvious but in some cases it it can be a little odd and there's actually four little sections on it it's a fairly short tutorial slash article that gets into it and the first method that he dives into oh maybe i should mention briefly like you know we've mentioned also that throughout these betas and alphas that you should try it out on your code base and just to reiterate what pablo glenda salgado was saying he being the release manager for python 310 and 311 his summary is no matter who you are and what you do test the beta releases if you can and now we're up to the release candidates and i would agree that those fall in the same boat as the beta releases that you should try to test them out and right now i think we're on release candidate one this article goes through that and the first one methodology for installing a pre-release method is to use a tool called pi m which we've talked about on the show a little bit already it allows you to manage multiple versions of python we have a pretty good article diving into it and a video course if you're interested one trick with pi m generally is that it isn't supported directly on windows so there's a fork of it that you can install and a recent article that i covered from ian that was about uh your python coding environment on windows and that sort of setup guide covers the tool chocolaty that lets you install a version of pi m and kind of covers the details there so i'll include links for both of those if you're interested to learn a little more the other way of installing a pre-release is to do it directly from python.org and there's a whole set of paragraphs there talking about it and then kind of a more advanced way if you are a docker user is to use a slimmed down docker container with a version of python in it that you can kind of set up try your stuff out at it and tear it down that might be easier depending on you know your environment how you set stuff up and the last one was uh using your operating system's package manager and you can kind of again dive into the article to learn a little more about it so i just wanted to mention it as we're in kind of the season of lots of releases and ways that if you're interested in you know doing that testing stuff this article addresses it pretty directly head on and some of these things aren't as obvious as you might expect that the pre-release version is not on the downloads page and because of how google works if you google it you might get a link to the alpha or the beta rather than whatever is the most recent yeah okay and i i ran into this when i was installing 311 in order to start writing the course for october and it took me about five minutes of mucking around until i could actually find the release candidate and i found plenty of links to the alpha and several links to the documentation but it took me a little bit to find the actual thing so uh this may not be as obvious as you might think it is yeah in that section about going to python.org he has a little picture of the downloads and again you see like the normal download stuff and then kind of in the middle of the page there's a link that does say pre-releases but if you were just sort of scanning over it you could easily miss it i have missed it several times i didn't know it was there yeah he highlighted a little pink circle to try to show it off the other aspect that i find it as well is and one of the other things that makes it hard to google is i i don't know that the word pre-release is what comes to my mind right so yeah sure you google python 311 if maybe if i had said pre-release i might have found the pre-release link faster but uh yeah yeah terminology huh it wasn't it wasn't the word that i uh i would have my google foo failed me is what it comes down to yeah if you're interested and again i agree with the sentiment there if you're you know a user of python it's a it's a good habit to you know get into of testing these releases to make sure that everything's going to run smoothly for you when when it does come out in october so what's your first article i'm starting out today with the understanding async python for the web this is by james bennett a couple weeks back the 4.1 release of django came out and the django core team has been busy over several releases adding more and more async capabilities to the framework so the article there's been a lot of articles kind of popping up around the concept james's article isn't actually django specific he touches on it a little bit it's more of an intro into async and why that concept is helpful for web applications okay and what it means sort of in the industry and how things are changing so in case you're not deeply familiar with parallelism in python and all the ways it mangles it we'll start out with a quick version of async you know the zen of python has this line there should be one and preferably only one obvious way to do it well it comes to running multi-threaded parallel code there are a few more ways than one yeah so either the zen was considered a suggestion in this case or someone's definition of the word obvious didn't meet consensus so async and await were keywords that were introduced in python37 so that's four years ago now and these allow you to write what's called a co-routine which is a way of writing multi-threaded programming and the intention here was to make coding in parallel more explicit than in the past so parallel coding has been in the libraries but this is bringing it into the language rather than just in the support libraries and in theory this can make it easier for the compiler and any tooling to constrain the behavior in ways that are actually good for your coding because you're making it part of the language so the article starts off by introducing the concept of a generator and that's code that uses the yield keyword most let's use the word regular programming is linear right so if you have a function with 10 lines in it the computer runs each line in succession and returns and then the yield keyword's a little different so when the computer hits the yield keyword it suspends the function and returns a value and then it can come back to the function after the yield statement and resume so the most common use of this is let's say you've got a function that is supposed to output a lot of sequential data so if you didn't have generators you would have to generate the entire chunk of data in a list and you'd return the list but with a generator what you can do instead is you can just keep yielding items in the list so as your function is being iterated over if you stop say you break out of your loop you don't have to generate the rest of the data so this is a much more efficient way of doing things for for large amounts of sequential data so the async and await keywords build on top of this concept and they allow you to suspend the execution of a function when you're waiting on some i o so there's a huge speed difference between your cpu and your ram and then there's another huge speed difference between your ram and your disk and it gets even worse between your disk and your network so by the time you get between your cpu and your network your computer is waiting a lot your software spends a lot of time just waiting for something to catch up so what a sync and a weight do is they give you the ability to go somewhere else and run some other code while you're waiting for that i o so this is called i o bound parallelism and implementing it can give you a lot of speed up if your code happens to wait on i o a lot if your code is mostly waiting on the cpu instead doing some fancy calculation this will not help you at all and you need a different set of tools and python has libraries for that so i o bound stuff only so let's say uh you know you were writing for the web well the web is on the network and guess what you're doing a lot of i o weight in this case right the ability to add a sync and a weight here can make a lot of performance improvements if you're building out web applications now just because this parallelism is available doesn't mean you need to necessarily do anything about it for example the web server code might actually use these techniques and you might not have to think about it at all so uh just because it's there doesn't necessarily mean you've got to learn this stuff but you could just implement something there that yeah you build on top of things right okay and in fact without async io what often happens in a lot of web servers is you just you spawn a whole bunch of threads and apache takes care of it for you and you just think about it in a synchronous fashion if you want now there are some cases where that becomes problematic and one of the more common ones is web sockets so vanilla web pages give you just one round trip right you hit the browser browser hits the page this spits back some html and you view it there might be some back and forth to get images or whatever but once it's loaded it's loaded so if you wanted to build something like a chat client inside a javascript you don't want to do it this way because otherwise every single time anybody sent anything you'd have to connect again and of course if i don't have that connection open i can't tell that you're trying to send me something so websockets is a tool that gets around this and it opens up a network connection and keeps it open and goes back and forth so the web server now has to be able to do some things in a more asynchronous fashion and of course a sync the code keyword can help you do all of this so essentially you get to this place where you're waiting and sleeping and then the chat message wakes you up and this allows you to do this at this point the article james starts talking about django and how django's been slowly adding asynchronous features over the last few years so django three introduced support for asgi which is the asynchronous protocol for integrating python with web servers this support means libraries like channels and daphne could take advantage of this and you can start using web sockets in a django world and over the last four releases django's been adding more and more features and for one added asynchronous access to the orm so wrappers for talking to the database nice james basically gives an overview of this and how it's changing in django then gives an overview of libraries that are found with them so like so if you're writing something in flask then uh you might be using say sql alchemy and of course if that doesn't support async you're screwed so you know how it's it's not just does the web application do it do all the companion libraries do it as well yeah and then he finishes up with a little bit of an opinion piece he's a little bit skeptical about the rush to async and i kind of agree with them it's definitely a useful tool it's a bit of a sharp tool and somebody going to be missing some digits at some point because the tool's a little sharp sure so i'm a big fan of it being used to help support the libraries but it's not something that i think web programmers have to rush out and learn immediately so it's cool that it's out there and the article gives you a nice sense of what that is and what it means and but you don't have to feel you're not a web programmer if you don't know any of this stuff yeah it's interesting how async very often is portrayed as at least over the last several years like oh my god everybody should be doing this but it really depends on the project and maybe the scale of the project and so forth like if you're not gonna have i don't know thousands of connections or what have you like i i don't know where the the big performance boost is going to be like what what are the things that are waiting and so maybe that might get into some kind of profiling or whatever i mean i guess it's nice that we're building toward it but there definitely is a curve of learning it and i've definitely gone over that like i had a conversation with brett cannon and talked about how async was you know kind of like this article's talking about came from generators and i didn't realize that until i kind of started really studying generators really deeply and sort of the unraveling stuff that he was doing i'm like oh my god this is the same stuff underneath it and how it kind of led to that development i guess it's good that it's coming along and moving there but yeah i i wonder about the the rush like well i think it's because because python is popular and slow yeah uh the most common thing python programmers tend to be defensive about is how do we make it faster sure and better parallelism is one of the ways you can get get some speed up right the other aspect of it i find as well is you know i've done a fair amount of concurrent programming in my days my grad studies were based on it and the one solid lesson to me is try not to do it it immediately introduces race conditions and you think regular bugs are hard to find anything that is not deterministic becomes really brutal to find um so this to me is one of those great tools but don't prematurely optimize right like if you if you you know if your program's taking two seconds and you want it to take one second adding async isn't going to fix your problem right if you've got a six hour job that needs to run in 20 minutes then you can start digging into this stuff yeah so my next one is by robert ritz he has a site called data fantic i wanted to say fanatic but it's not it's data fantic but it's a tutorial about a feature that i was not aware of when i kind of looked around and looked at data visualization libraries just a few minutes ago i was like okay what is the popularity level in python for this and so i did like you know just a kind of cursory not peer-reviewed study of like okay well what are the popular libraries and at the top of every of these top lists that i looked at of like what should you learn and what are people using and so forth matplotlib is always kind of up there and we even talked offline before we started that there are some maybe some other reasons not coming from academia it's got a real tight connection with pandas also so my only problem with matplotlib and this is just an aesthetic thing that i've always felt about it is that it's kind of ugly out of the box like it doesn't have a whole lot of initial style and this article gives you a really neat way to kind of update that and maybe even apply a consistent style across your stuff like if you're you know designing a website and you're going to use a lot of graphs and visualizations it's nice to not have to repeat a lot of code and it's about the magic of matplotlib style sheets i was impressed that this very very short article took this you know very simple looking plot and turned it into something that you would see on you know some of these popular websites that show data visualizations like the one that he's trying to mirror in this particular article is a political site called 538 it's a particular blog that's out there and they have tons of graphs and and so forth so you wanted to kind of create something in that style and by using this style sheet he's able to kind of modify this very plain looking matplotlib line graph and and turn it into that the the style sheet just to kind of get that out of the way it's saved as a text file it will have an extension of mpl style and you load it in with just a single line plot.style.use and then you have in parentheses your your file path it looks kind of interesting it has comments basically that you can use to divide up the sections and the standard you know pound sign kind of thing to basically and you can either do them like you know topping the comments or you could do ones that are in line after it just to kind of indicate what you've set up inside there but as you lay this out you are things like modifying the grid style modifying the dpi the default dpi dots per inch for your graphs that are matplotlib or 100 and even changing to like something 150 will make it look a lot better printed or even on screen he suggests setting it up for 300 for printing figure spacing which is like your aspect ratios the default is a 4x3 and doesn't always look great depending on what you're trying to format and kind of put it on especially things that are very phone based these days ticks the tick labels their font sizes and there's a matplotlib documentation page i'll link to also that covers this and has all of the parameters that you can kind of adjust or at least the majority of them at the moment with the style sheets and then i also went and did a little kind of deep dive and said well what have people created out there already and i found a couple uh sites one that i'll link to that is a github repository with some already existing style sheets because i think it's handy to kind of see what other people have done with it to kind of get an idea like oh this could be handy it's kind of like if you're i think a really common thing as you learn web design is to really look at other sites and then open up what what they've kind of created inside there and try to you know reverse engineer it and this uh set of style sheets actually features some sheets that are inspired by a previous guest tonya allard she had created this vs code theme and he took a lot of the colors and and kind of the look of it and applied it there the tutorial ends with adding a few things that are not available in the style sheet a couple kind of nice to haves like uh [Music] in something like a 538 thing they might have a text you know next to the line as opposed to like having it you know directly always in like a legend to the side so he kind of shows how to do something like that labeling lines directly adding additional title and subtitles and how to create that kind of look it's a really nice tutorial it's very short and to the point i set it up myself using a jupiter notebook and just kind of followed along with it building and as i went and i was really impressed with like just immediate little changes and stuff with it but he has a link to a service called deep note which i haven't used it's like basically a link to a notebook with all the data ready to go the data he's using in this example is a kaggle uh data set that has a he has a link to it directly at the top so yeah i was really impressed with it i was not familiar with the concept of having style sheets for matplotlib and i think a lot of people will find this a very useful feature for them in the future and again for something like an organization to be able to set up a look and a feel and keep it consistent i think is really great well and simple simple things can go a long way with this stuff right like like you said you know just tweaking the resolution a little bit thickening a couple lines that kind of thing and the fact that there's other people who've published these style sheets is fantastic because if you're not the person like me i can't do that right i look at it go i know how i want it to look and i have no idea what to do with it right so mixing and matching other people's stuff out there right this was the picasso quote good artist copy great art great artist steel well uh i'm not a great artist but all thieving seems like the right answer so uh yeah it can be really really helpful with that kind of stuff yeah even a simple thing like this particular example he's changing and not having the typical ticks on the left side for a line drawing because everything is ramping up in this case it's a gdp growth from 1960 to 2010. and it makes more sense to have the labels and on the right-hand side and the ticks and so forth and so that can be like kind of a head scratcher sometimes you know like how am i supposed to do that so i was again impressed with the results so check it out i think we should spend the next hour talking about visual stuff in an audio only format it's uh perfect perfect place to do it oh i'll do more of that at the end here perfect okay [Music] platform sh provides the cloud-based solution you need which allows you to manage update and optimize your website and or online application fleet with our secure unified enterprise grade platform designed for effective building running and scaling of web applications we are the leader in web fleet management are you ready to join the platform sh community and optimize your fleet operations there's no time like the present find us at platform dot sh [Music] so what do you got next all right so next one up is a video course called caching in python with lru cache uh the course is based on a real python tutorial by santiago of valderrama and the course itself was done by real python's preeminent course creator my humbleness disallows me from just saying how smart handsome and fantastic the creator is so i'll pause here for you to say something smart and fantastic about the creator can i just clap yeah yeah well humble humble is the key word yeah yeah anyways uh so lru cash is a decorator that is found in the funk tools library and is probably the shortest change you can make to your code that will improve its performance your code can benefit a lot from it and it's like a one-liner you put on the top of the right kind of function so how do you know if your code's gonna benefit from this the course starts talking about what you know what a cache is and the different ways of managing a cache and the fact that a cache really is just sort of a trade-off between memory and speed so if you have something that takes a long time to compute or a long time to fetch say from over the network callback then there's value in keeping it around in memory so that if the data is reused you don't have to go and get it again it can just be pulled out of memory of course what you're doing there is you're eating up memory in order to get that performance gain but that performance gain can be huge so the example that i ran through in the course is the fibonacci sequence so this is an exponential calculation which means the more data you want the worse the performance gets and on my machine calculating the first 20 digits takes about 0.004 seconds and then the next 10 digits after that takes a hundred times as long right so that the slowdown just keeps getting worse and worse now a fibonacci calculation is a recursive algorithm each value in the sequence is the sum of the previous two values and this is a perfect case for caching because all the data is getting reused a lot so that same code i was just talking about by slapping the lru decorator on top of the function the first 30 digits are calculated in about the same time as the first 10 digits without the calculator so it's a speed up of like 4 500 times like it's it's huge yeah so with the base concept out of the way the course then goes to show you how to build your own version of lru cache building on top of the code in funk tools and the the good thing about caches is they keep things around the bad thing about caches is they keep things around right sometimes you want your data to expire say you're caching a web page with some news headlines the cache can help if you're you know caching the logo but you don't necessarily want to cache the headline because you might be reading yesterday's headline or last week's headline at your cache so the course talks about how to adjust the lru cache to add an expiration concept and there's a little tangent lesson in here so that if you haven't done decorators before you can go in there and understand how they you know how to read them and and what they look like so there's a tiny little introduction to decorators in case you're new to writing them um so yeah it's uh well i'll let someone else speak to the quality of the content but the lru cache decorator is definitely one of those tools that you want to have in your coding belt and uh you know if if you enjoy my sultry tones well then you can get another 30 minutes of them and learn the lru cache so there you go radar radio announcer voice and everything so yeah i mentioned this as a video course spotlight last week and i was including it because we were having a conversation about recursion with al swigert we got to the point of talking about memoization not memorization but memoization this idea of sort of holding on to values and it is a technique that if you're going to use recursion might make sense in certain certain circumstances and the trade-off with computers now this idea that kind of ram is becoming less of this like very very rare commodity you know that's built into your machine and maybe could be used in other purposes could really you know in this particular case generate really wonderful performance gains and in certain algorithms of certain techniques and so forth so yeah i thought it was a great course i i got a lot out of it and i think that it also shows off the the handiness of decorators and how simple it is to just modify your code with like a couple lines an import statement and a decorator it's awesome yep cool so my next one is not per se a python article but an article about just general purpose computing you know and development it's titled some ways to get better at debugging it's by um i'm not even sure what to call julia evans she does a lot of different things a lot of different projects uh she creates these cool little zines uh little you know kind of small magazines about very technical topics that i think is kind of cool her the line that she uses is they're called wizard zines and their her twitter handle is at bork b 0 rk so they're like things like on how dns works or bite size command line stuff for bite size bash and uh learning about css and containers and and so forth and you know i've been impressed with them there's one uh that i've wanted to talk about that covers some stuff in git that i think is really kind of cool and that she did with another person so this blog post is very short and to the point kind of like a lot of her stuff she's very good at i think editing down and just kind of hitting key little points for you to kind of continue your research from but there were five key sort of strategies and the first was if you want to get better at debugging it helps if you know the code base and this one is kind of two sides of the same coin if you know the code base and you want to learn a little bit more about how it's performing you can debug it or if you want to learn the code base you can kind of start up a debugger and see what it's doing and so it's kind of an interesting way to kind of learn that and get deeper into it she references a paper that she used as kind of the basis for some of these ideas the paper is towards a framework for teaching debugging the paper called that system knowledge and then the next one she has is just like learning the systems like to fix bugs you need to learn a lot about the broader environment not just really the language and so in the case of if you're working on web stuff which a lot of her topics kind of touch on you may need to learn about how http caching works how a database transactions work something called cores you might need to learn a little more about and this is called domain knowledge and learning how to kind of combine all that stuff together then it gets into learning tools which would be you know debuggers themselves or could be additional tools that we've talked about like profilers s trace ltrace tcp dumps wire shark if you're studying network traffic and what's going on even knowing how to read your error messages and look at like a stack trace and kind of digging into it and that is referred to as procedural knowledge and then she provides a handful of these sort of learning strategies writing a unit test writing standalone programs taking a break which i can agree for learning sometimes it doesn't always make sense to just keep powering through because sometimes you're not learning anymore i like this one about explaining the bug that you're dealing with to a friend and then figuring out what's wrong halfway through as you're explaining it i've done that myself um just talking about something kind of like can kind of as you're trying to explain it it makes you kind of learn the interactions a little better it's interesting that way are you familiar with rubber duck debugging i'm not sure if i'm familiar with that term no that this comes from somebody who this had discovered in themselves exactly what you're describing that explaining it out loud gives you the illumination for the problem so rather than bothering his co-workers he got a little rubber ducky and put it on his desk and when he got stuck okay he would out loud explain it to the rubber duck and hence rubber duck debugging and there are websites out there which you can do this to and they will respond quite appropriately quack no matter what you say [Laughter] nice this is like an image of a duck that you're speaking to nice yep okay yeah i can you know i see how that would work as long as the people around you are wearing headphones oh it doesn't say anything about whether or not your co-workers will hate you for it but you will it does help you debug that's uh two different problems yeah and then the last one that's kind of in there is talking about kind of github issues and and looking to see if other things match with it sort of a strategic knowledge is what the paper had called it and then the next one is just sort of get more experience at doing this and yeah i mean that's one way to get better at debugging do some debugging yeah practice for sure yeah and that's how you know many things are and i i know that a lot of people debug via you know print statements and so forth but actually you know to go back to you know our previous conversation that we've had about this it's it's a technique that isn't taught that often in the development like these kind of like low level things of like learning how to program very often it's sort of skipped across but most systems that you have even idle which comes with your installation of python has a debugger it's maybe not the most powerful one that's out there but it can provide you concepts that are hard to initially learn if you're a beginner like scope and you know what values are at different times what's currently being run and kind of the idea of like jumping through and it really lets you follow that flow chart of programming and i think it's a fantastic way to learn more so if you're at that beginner or intermediate point and haven't been playing with a debugger it's a really good way to learn your code if you know even if the program runs properly now you can kind of learn more about it or if you want to install and run somebody else's code you can really learn a lot so uh yeah i agree with that whole get experience part but one of my favorites is uh is a tui debugger called uh pudb okay and it's it's a 2e version of pdb and so it's got a very sort of borland turbo pascal look and feel to it that you can actually see your code all of your code on the screen at a time yeah and set break points and things like that but one of my most common uses with it i find is i set the breakpoint and then immediately dump down into the rebel because it's rebel within the context of wherever you're break pointed so you can play with your variables you can change things you can muck with it and i find it far you know yeah i can look at the current value of something but if i'm only looking at the current value something i can do that with print statement whereas this allows me to dig in and go oh wait a second fight oh that object's not what i expected to be what if people threw weird characters in yeah yeah and so it allows you to muck around a little bit and and so that idea of being able to get at that rebel spot inside of the context i find is is really really helpful yeah and the the other thing you're talking about learning the code base one of my favorite tricks for that uh is and it obviously depends greatly from code base to code base but uh reading the unit tests yeah you often learn more from the unit tests than you learn from the code because the unit tests are expressing what the system is supposed to do so if you can find like a high level oh you know you know if i'm looking at something that you know a web interaction at a high level it's like oh okay it goes here it logs in it does this it fills in this form then it does that and that's expressing you know what a user is probably doing with the system right and that can help you as well right so if you take the unit tests and then start adding uh print statements or debug uh breakpoints to your unit tests now you're not even having to figure out what the use case is because the unit tests are giving you those use cases yeah nice yeah so i'm a fan of uh julia's work i think you can get some some good ideas of just kind of diving in a little deeper with this short article but uh check out some of her scenes also [Music] this week i want to shine a spotlight on another real python video course it dives further into a topic we discussed this week it's titled python debugging with pdb the course is based on a real python article by nathan jennings and in the video course instructor austin sapalia takes you through how to perform the most common debugging tasks using pdb including setting up breakpoints stepping through code viewing stack traces creating watch lists and more i think it's a worthy investment of your time to learn how to use this powerful troubleshooting tool and learn how it can improve your code and speed up your efficiency and you can also get a printable pdb command reference real python video courses are broken into easily consumable sections and where needed include code examples for the technique shown all our lessons have a transcript including closed captions check out the video course you can find a link in the show notes or you can find it using the enhanced search tool unrealpython.com [Music] does that take us into discussions i think we're into our discussion land yes okay yeah we had a choice of two different things and i kind of went with the second one this is a tweet from previous guest will mcgougan who's just been really on fire on twitter he's a really good follow and he posted a question which was suggest a lesser known library deserving attention and his little note at the bottom of that is like even if you're the the owner that's okay because you know like that's the problem is a lot of people are afraid to do self-promotion and feel weird about it yeah it's horrible if they don't have that humbleness like what can you do yeah like certain individuals so i want to mention two that ended up in the list one is last week's guest al swigert he in between our recording and uh me publishing the last week's episode he has worked on a library called hum ray i don't know how to pronounce it exactly but h-u-m-r-e which is human-readable regular expressions is the the concept behind it and he you put it out was looking for a lot more comments and i don't know if he felt like he didn't get a lot of attention on it but i think it's slowly getting a little more attention there and so i want to definitely re-up that problem with regular expressions very often is that you learn them and then six months later you're having to relearn them they're they're so forgettable i don't know why but they just don't really hold in people's heads very well i've taught them multiple times and i still look them up anytime i use them i always get them wrong yeah yeah they're fiddly so i think this might be a good way to kind of maybe make it be a little easier to read and and maybe give you that you know one level above abstraction that might help you kind of break into it so that's a cool one that i saw and then the other one i wanted to mention that is in there is a another previous guest i'm just throwing out all the previous guests here but it's from star girl somebody else had mentioned it but it's called mox nox it's a library uh for testing and kind of automating the testing kind of like talks if you've heard of it but there's a lot of really kind of nice modifications and kind of a way you know different way of looking at that kind of stuff and um if you are familiar with star girls work uh thea flowers she does really great documentation so um it also would be a good project to look at just for that what do you got just just just a little picture behind the behind the curtain here for our listeners uh we don't talk about this ahead of time knox made my list as well so oh cool awesome have you used it i haven't used it yet uh i use talks regularly talks constantly reminds me that one of the features that i depend on it has been deprecated so i i'm counting the days until all the things i do with talks start to fail so looking for another library and finding some other things that there's some value in that so i that was definitely on my list to look at the couple others one was auto editor this is very us yeah i know i want to try it uh but it automatically removes dead air from videos so it looks for your pauses and things and and clips automatically so that's something that i want to play with yeah i wonder what formats it's picky about and stuff like that and there were two more one one seemed like just a quick little uh utility to keep in mind was a library called howard which will convert your dictionaries into data classes and your data classes into dictionaries so if you want to go back and forth there's there's a couple libraries out there which will allow you to do things like dot notation with your dictionaries so this would be another way of getting at that and then the last one which i know nothing about but it is called pi app and it calls itself the django for cli apps so they basically are trying to do uh some of the pieces that you know django takes care of it's always been a bit of a bug bear for me that you know django that there's some things in django that i would like to be able to pull out of django easily i always felt like the the library should be like three libraries so i'm always interested when somebody takes a uh tackles this because if i wanna if i wanna be able to do some of the things that i do in django but i'm not in a web context uh other tools can be useful so uh so i know nothing about any of these but they were the ones that kind of struck me as interesting and uh add them added them to my to-do list and it's a long long conversation yeah there's a lot of stuff in there it seems it keeps going yeah which is good dear pi gooeys on there that we mentioned before too yep and there was a fair amount of uh data science stuff yep so not my belly wick so i i didn't you know nothing popped out at me but uh if that happens to be your thing there there might be some cool libraries out there that help you out do something you're working on yeah yeah i mean that's the trick there are so many libraries out there to even get somebody uh to just basically you mention one kind of helps you kind of float it up to a point to say oh maybe that's worth a check if this person is suggesting and so and if you know nothing else go give them some love on github and add another star because yeah definitely us maintainers love that feeds the ego so it seems to be a theme today yeah well actually that takes us into our particular projects that we were mentioning this week do you want to go first on this one sure okay uh so i was looking at a new python linting tool that's been making the rounds called rough it's written in rust which means it's compiled and that makes it way faster than your typical python linting tools okay and that's the primary focus of rough it the maintainer charlie marsh has written a companion blog where he calls out the horrible performance of a lot of the tools in the python space and has basically said you know for large code bases this is problematic and so it it not that it's not a useful tool but i got the sense from the article that it was more of almost a challenge of what can we do better rather than hey this is you know you should switch linters and so and although it is uh compiled and written in rust he has built a whole bunch of wheels for it there's like 15 or 16 of them so you can just pip install it and you know it had both versions of the mac for example for both the different processors so he's got he's covered it very well cool so in all likelihood you do not have to have rust installed or think about it you just pip install and you're good so as i usually do with these kinds of tools as i just sort of went into a couple of my active projects and ran them against it the speed was really really noticeable i didn't do any formal timing but by comparison pie flakes which is my usual go-to linter it takes like a one or two mississippis to run on you know one of my projects rough came back so fast i couldn't measure it it was basically oh look there's the answer like it's done so it was so for small to medium-sized projects it's essentially instantaneous nice and nicely i it found a couple of errors that pi flakes didn't uh so that kind of surprised me oh wow i missed an import or two in a dunder string method and my testing i doesn't cover my dunder string methods so it didn't get caught so thanks to rough i've got some fixes to write which i think i'm blaming rough for rather than taking responsibility so the only downside i found is the command line arguments were a bit clunky the help says rough you know bracket options and then bracket files and it's got a dash dash ignore so if you want to say hey don't pay attention to lines that are too long for example it kept flagging one of my django projects the migration files the lines are too long and so you could say dash dash ignore whatever it was e150 and say don't tell me about that and i had to fiddle with it because although the instructions say the parameters go before the list of files it's actually the other way around and so this is the kind of thing that can frustrate new users if they're not willing to play with it but again this is a first release of this tool yeah it's young you know it's a minor minor little nitpick and documentation will fix it right so uh so it's pretty cool a lot of promise the speed difference has got me hopeful uh that we you know we can get some more tools in the future like this so uh yeah yeah it's definitely worth playing around with it yeah all the people that i've spoken to over the last couple years the most common answer to what do you want to learn next has been rust yeah so it's uh i'm sure there'll be more tools coming um and it's rough spelled with uh ru just like rust r u f r u f f that's right yeah so mine is taking off of um kind of an update if you will back in episode 21 david amos was my co-host and we were talking about projects then and he had mentioned this is august 7th 2020 so that's like almost exactly two years ago he had mentioned dave is really into math if you haven't followed him on twitter and so forth um he was following this guy grant sanderson who's more well known on youtube as three blue one brown and has this whole animated math learning channel which is really fantastic for learning you know all kinds of mathematical concepts and even statistical concepts and so forth so uh i'll i'll put a link to the youtube for that but at that point he was mentioning that you know grant sanderson created this python library called manum which is basically a mathematical animation library and i think at the time he even mentioned that it was a little you know rough around the edges if you will as far as the documentation and you know support because it was really just a thing that he had created for his own projects and so forth well in october of 2020 so just a couple months later a community-maintained python library started to happen and so now there's a complete separate thing madam python library for creating mathematical animations at manum dot community and if you go to that site there's really great documentation uh it has an example library it has tutorials and guides a whole side thing for plugins if you go to the example gallery you can very quickly see why this might be of interest if you're trying to animate mathematical things and trying to make videos of these things because that's what it outputs outputs actual little uh video snippets that you can kind of use from there it has sponsors which i was really impressed with they already have outside sponsors including you know pretty big ones like one password and a couple other companies it installs on mac with home brew so they've got a nice kind of installer ready to go for that on windows that uses chocolaty which you've mentioned before and then linux there's a variety of instructions for the different flavors of linux there you can try it out just on its own there's a link right from that main page where it uses a tool called binder another sort of jupiter notebook thing and you can kind of again just try running some of the code and seeing what it does the animations can have these cool camera settings to like actually move along different planes as things are animating again it's just really pretty what it does it can do latex that kind of tool for doing numerical very advanced sort of formulas and things like that there's a whole separate 30-minute tutorial just for that it's a really active community so yeah in two years this thing is like you know this fork in your community version has really exploded they have a discord reddit twitter all that so if you're interested in mathematics or you're interested in you know mathematical animations you're a teacher and you want to teach some of these concepts this could be a really handy python tool to add to your to your tool belt so that brings us to the end thanks again christopher for bringing all these articles and projects this week as always i'm your humble servant and we'll be talking a little more frequently got our python 311 release coming up soon so i'll be talking to you soon looking forward to it [Music] and don't forget test out platform sh for yourself with our free trial available on our website now just search platform.sh in your favorite browser i want to thank christopher trudeau for coming on the show again this week and i want to thank you for listening to the real python podcast make sure that you
Original Description
Have you thought the standard output from Matplotlib is a bit generic looking? Would you like a quick way to add style and consistency to your data visualizations? This week on the show, Christopher Trudeau is here, bringing another batch of PyCoder's Weekly articles and projects.
👉 Links from the show: https://realpython.com/podcasts/rpp/125/
We cover an article about the magic of creating style sheets for Matplotlib. You can quickly customize plots and graphs with a single line of code. We share additional resources for you to try out new styles and learn what parameters are customizable.
Christopher covers an article about using async for web development in Python. The creation of Python generators inspired the development of async functionality. He discusses recent changes and async additions within Python web frameworks.
We cover several other articles and projects from the Python community, including how you can install a pre-release version of Python, caching in Python with lru_cache, ways to get better at debugging, suggestions of libraries that deserve attention, a ti Python library for creating mathematical animations, and an extremely fast Python linter that is written in Rust.
Topics:
- 00:00:00 -- Introduction
- 00:02:21 -- Python releases 3.10.7, 3.9.14, 3.8.14, and 3.7.14 are now available
- 00:03:51 -- How Can You Install a Pre-Release Version of Python?
- 00:08:13 -- Understanding async Python for the Web
- 00:17:11 -- The Magic of Matplotlib Stylesheets
- 00:24:20 -- Sponsor: Platform.sh
- 00:24:56 -- Caching in Python With lru_cache
- 00:29:41 -- Some Ways to Get Better at Debugging
- 00:38:14 -- Video Course Spotlight
- 00:39:26 -- Suggest a Lesser Known Library Deserving Attention?
- 00:44:52 -- ruff: An Extremely Fast Python Linter, Written in Rust
- 00:48:19 -- Manim: Python Library for Creating Mathematical Animations
- 00:51:50 -- Thanks and goodbye
👉 Links from the show: https://realpython.com/podcasts/rpp/125/
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Real Python · Real Python · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
A better Python REPL – bpython vs python interpreter
Real Python
Introducing large-type.com – A Utility Website
Real Python
Reading Hacker News Without Wasting Tons of Time
Real Python
Forward References and Python 3 Type Hints
Real Python
Using Sublime Text as your Git Editor
Real Python
Python Code Linting and Auto-Complete for Sublime Text
Real Python
Make your Python Code More Readable with Custom Exceptions
Real Python
Write Better Tests with Sublime Text's Split Layout Feature
Real Python
How to Use Sublime Text from the Command Line
Real Python
Rename Variables with Multiple Selection in Sublime Text
Real Python
Sublime Text Settings for Writing PEP 8 Python
Real Python
Write Cleaner Python with Sublime Text's Indent Guides
Real Python
Sublime Text Whitespace Settings for Python Development
Real Python
Function Argument Unpacking in Python
Real Python
Python Code Review: Debugging and Refactoring "Conway's Game of Life" + Automated Tests
Real Python
Using "get()" to Return a Default Value from a Python Dict
Real Python
A Python Shorthand for Swapping Two Variables
Real Python
Python Code Review: Refactoring a Web Scraper, PEP 8 Style Guide Compliance, requirements.txt
Real Python
Click & Jump to Test Failures from the Command Line (iTerm2)
Real Python
Setting up Sublime Text for Python Developers
Real Python
Sublime Text + Python Guide Overview
Real Python
Python Code Review: Adding Pytest Tests to an Existing Python Web Scraper
Real Python
Type-Checking Python Programs With Type Hints and mypy
Real Python
A Shorthand for Merging Dictionaries in Python 3.5+
Real Python
Python Code Review Flask Web Security Tutorial + Virtualenvs, requirements.txt
Real Python
My Python Code Looks Ugly and Confusing – Help!
Real Python
Setting Up a Programmer Portfolio/Developer Blog – How To Get Started
Real Python
Do I Need a GitHub/GitLab/Bitbucket Profile as a Developer?
Real Python
Programmer Portfolio – Example and Walkthrough
Real Python
How to Get Your 1st Speaking Gig at a Tech Conference
Real Python
How to Build Your Public Speaking Skills as a Developer
Real Python
The Object-oriented Version of "Spaghetti Code" is "Lasagna Code" ?!
Real Python
Setting up Sublime Text for Python Developers – Lesson #1
Real Python
Cool New Features in Python 3.6
Real Python
"is" vs "==" in Python – What's the Difference? (And When to Use Each)
Real Python
Emulating switch/case Statements in Python with Dictionaries
Real Python
Python Function Argument Unpacking Tutorial (* and ** Operators)
Real Python
What Code Should I Put On My GitHub/GitLab/BitBucket Profile?
Real Python
A Crazy Python Dictionary Expression ?!
Real Python
String Conversion in Python: When to Use __repr__ vs __str__
Real Python
Method Types in Python OOP: @classmethod, @staticmethod, and Instance Methods
Real Python
Optional Arguments in Python With *args and **kwargs
Real Python
Python Context Managers and the "with" Statement (__enter__ & __exit__)
Real Python
Installing Python Packages with pip and virtualenv / venv
Real Python
"For Each" Loops in Python with enumerate() and range()
Real Python
Python Code Review: LibreOffice Automation and the Python Standard Library
Real Python
Managing Python Dependencies With Pip and Virtual Environments – Lesson #1
Real Python
Python Tutorial: List Comprehensions Step-By-Step
Real Python
Leveraging Python's Implicit "return None" Statements
Real Python
What's the meaning of underscores (_ & __) in Python variable names?
Real Python
Python Data Structures: Sets, Frozensets, and Multisets (Bags)
Real Python
Writing automated tests for Python command-line apps and scripts
Real Python
How to find great Python packages on PyPI, the Python Package Repository
Real Python
Immutable vs Mutable Objects in Python
Real Python
PyPI vs Warehouse, the Next-Generation Python Package Repository
Real Python
pep8.org — The Prettiest Way to View the PEP 8 Python Style Guide
Real Python
My Experience at PyCon 2017 in Portland
Real Python
Pylint Tutorial – How to Write Clean Python
Real Python
"Reverse a List in Python" Tutorial: Three Methods & How-to Demos
Real Python
Python Refactoring: "while True" Infinite Loops & The "input" Function
Real Python
More on: Systems Design Basics
View skill →Related Reads
📰
📰
📰
📰
7 Apache Kafka Design Patterns Every Backend Engineer Should Know
Medium · Machine Learning
The Most Dangerous Failure In Distributed Systems Is The One Nobody Notices
Medium · Programming
Fat Controllers No More: Architecting Clean Laravel Apps with Services and Repositories
Medium · Programming
I Finally Read Designing Data-Intensive Applications (2nd Edition) - Here's Why Every Backend Engineer Should
Dev.to · Stack Overflowed
🎓
Tutor Explanation
DeepCamp AI