5 Python Libraries You Should Know in 2025!

5 Python Libraries You Should Know in 2025!

Machine-readable: Markdown · JSON API · Site index

Поделиться Telegram VK Бот
Транскрипт Скачать .md
Анализ с AI

Оглавление (5 сегментов)

Segment 1 (00:00 - 05:00)

hey what's up everyone and welcome back to another video so two weeks back I made a video on staying up Tod date with programming trends and in that video one of the tips was to follow Reddit communities to kind of see what's popular within the space I was doing that the other day and I stumbled upon a Reddit post which was labeled what are your glad to have met you packages I checked it out there was a bunch of good stuff there and so in this video we are going to cover five libraries specifically that you might not know now but after this video you'll be glad that you do all right the first Library we're going to talk about today is tqdm no idea what that stands for but what you use as library for is a progress bar in Python and this might seem like a simple thing but it can be very useful if you have a big project that has long running tasks and you kind of need to monitor progress of how things are executing so to get tqdm you can go ahead and do a pip install tqdm I don't know if it comes default or not um and then we could do from tqdm import tqdm and then what it's going to help us do is let's also how about import time real quick what it is going to help us do is we do something like for I and range how about 10,000 and we might you know do time. sleep Z. 01 and run this right by default this is running but we have no sense of like is this Frozen is it actually running you can imagine this time dos sleep is replaced with any old code in the world it could be anything and we just by default I don't know if it's doing anything I think back in the day my solution to this was I could do something like if I mod 100 equal 0 print I and I could run this and I could slowly monitor the execution but it's kind of clunky to see these numbers kind of pop up on the screen so a better solution is leveraging tqdm and surrounding this all you have to do is surround this with tqdm range 10,000 and if I run this we now see a nice looking progress bar that monitors exactly where we are in the loop so I can have a peace of mind my code is executing and I'm making progress uh you can also add nice little things to this so imagine if you have a bunch of different progress bars running I could add a description uh I could just do this like basic loop I could call this whatever though so if I was doing a certain task I'd probably name it something according to that task if I run this again we now see that it's called basic Loop and that is executing so that is quite helpful you know it doesn't need to be a range object that you do this on it could be a list so you could have a list of numbers how about or like list of objects or strings so how about people names and I could do a print name for name and yeah exactly like something like this and we see that there's a progress bar for this as well and it executed you know fully if you had a more complex list comprehension this might be different uh these are the basics of tqdm can be very useful to monitor things especially when you have long running python tasks check it out all right the next library that we're talking about today is called Rich so we can install this by doing pip install Rich this is helpful for formatting text very pretty manner when we're printing things to the console so as an example how about we um H get a get rid of this terminal um how about we Define a dictionary with a bunch of Shrek information so I'm going to say uh create a python dictionary with a lot of information on Shrek get up co-pilot and co-pilot chat is pretty nice okay so we got this nice looking Shrek info python dictionary if I was to just go ahead and print this out we might get a little bit overwhelmed by the result so I run this we see we get all this dictionary information here it's kind of a lot to take in it's not super neat so the first thing that we can do with Rich is I could go ahead and do from Rich import print and this is going to overwrite the default python print and what that's going to let us do is it's going to print this out in a very nice clean manner it also does this so if I

Segment 2 (05:00 - 10:00)

commented or deleted Shrek info we also can just do this with other random things so AAL 5 Bal three I could do you know print a I don't know something like this run it we see it kind of formats things nicely uh if I removed this line you know it starts coloring things does all the sorts of things by default nicely for you so one reason use print uh rich but if you want to get into some more sophisticated things we could do something like def compare numbers so we're going to import now this from rich. console import console and we're going to Define console here and now we'll call this function compare numbers and we'll see what this does by default so I run this and now how about actually let's run some compare numbers okay so we have three examples here I run this we see that it formats it I can also add different styles to things so I could do style equals bold green here I style equals bold red here and if I run this we see we get colors this is helpful imagine you have tons of print statements and some code you're executing and you need to find specific things if you want to sty things specific uh console. print can be quite helpful other things that are helpful here is you could like add your own custom theme so I could do from rich. theme import theme and then I could Define a theme as let's say error equals bold red warning equals bold yellow how about that's perfect I add my theme to my console and then instead of doing style equals bold red how would I do style equals warning here so we'll see the a less than b case now be yellow cool uh other cool things about rich we could do from rich. traceback import install we added install line to the top of our code and now let's say I do compare numbers but I do something that I know is going to break this so I do five and I do my name I'm trying to compare Keith to five and if we run this it outputs a error message that's you know very you know pretty looking uh so we see that just nicely formatted traceback error message whereas if I removed this line and I ran this again we get an error message but it's kind of hard to see exactly so traceback can be super helpful another cool thing is you can add a console print and we can do something like log locals equals true if I run this uh should work why is log local not working I realized that uh in addition to console. print you could do console. log uh which I think adds a timestamp but that has this log locals and if I do this we see that we get a Time stamp now and we get the local variables here which can be super useful if we running a loop and want to see everything that's being passed into it and where errors are you know being caused or something cool stuff here that is rich in a nutshell I'll add a link in the description to more information about rich but some useful stuff here next let's talk about pathlib so pathlib is a standard python a library as of python 3. 6 and what we might use pathlib for is imagine this example uh import pandas as PD and then we have a data file let's say our file path is something like uh data or in the current directory data test. csv so if we look at our um repo right now we see we have data test CSV so this is the file path there I can very easily load the file in pandas by doing DF equals pd. read file path and then maybe I print out our data frame so if I run this we will see our data frame right we see it right there the thing that's interesting though is if I navigate away from our current directory and now I'm in this code folder if I now try to run this file so it's called um good to know libraries 03 pathlib it's going to error out because it can no longer find

Segment 3 (10:00 - 15:00)

thatd test CSV so there's multiple ways to solve this issue the traditional library that you might use is this OS library but recently the kind of python standard is to leverage this path Library there's some niceties of um this being kind of an objectoriented way to navigate paths so how I would do this with the path lib is I might do something like file path where we on this file right now is pathore file underscore so this would give us the path to the specific file that we're working off of so that the code is in right here if then I do parent this will give me the directory that this file is in so it's going to be the um good to know uh python uh libraries directory and then I can go ahead do data do slash test. csv and that would get this syntax allows me to get specifically into that test. csv folder sometimes you might also want to call a resolve to make sure you get the absolute path but I don't think that in this most situations it will matter too much but if you ever need to make sure you get the absolute path as well as if there's like a symbolic link or something thing you probably want to surround everything uh with this resolve but now what we'll see is if I again run this python 03 pathlib we see that it works if I navigate to a different directory and run python goods and no python Library 03 pathlib we see that it's still works so it's a little bit more of a robust way to access different file paths there's some other niceties such as like I could do um uh let's say path uh doome and get our home directory so if I print this you're going to see my the absolute path to my home directory so we see users Keith galy um I could do something like code and we'll see that what this gives us cool all sorts of cool things that you can do with this path Library all right the fourth Library we're going to talk about today is called pantic so to install it you can do pip install pantic and this is super useful if you're are trying to check types and enforce types in Python which is not you know something that python is traditionally known for so imagine I wanted to Define a class called account you know in normal traditional type python syntax uh I might have something that looks like this right and then I you know maybe my balance is a float maybe my name is a string and if I did if you know I defined an account uh and then I printed out the account right uh this is you know standard traditional python syntax but I think one thing to know about this is that like if I yeah printed account. name how about you know there's no issues but if I let's say set my balance to one you know some string that was just like hello and you know try to print out account. balance by default with python no issues it's like yeah that's chill do whatever you want doesn't matter what we Define balance as a float but in pantic this does not fly so I can't set my balance to like a string when it's supposed to be a float value so let's go ahead and try this again with pantic so um from pantic kind of what you'll typically do is import this base model and so now we are going to Define our class account as a base model pantic we can just call it like this and this is now set up in the same way where I can find my name I can Define my balance and I run this and we see an error and I think to make this video Go full circle if I do from Rich import traceback and I do traceback do install we can see this error message in a more pretty manner uh which is cool to see and it's basically saying okay input should be a valid number unable to parse string as a number so okay if we change this to how about 100 it will work and maybe this is a checking account let's say uh I don't know if this is a good analogy because

Segment 4 (15:00 - 20:00)

Bank of America they'll let your your account go uh to negative not that I would know but uh let's say you can't have a negative balance we can also Define a custom field validator with pantic and what we can do with that is uh we could set up some custom logic it's these Auto completes are amazing uh to yell at us if we try to set something that's inv valid so now I have this code if I try to run balance equals 100 we should see no issues also wonder why I didn't print my account. balance here uh that's weird but now if I try to set this to -10 we see we get an error value error balance must be positive so that is cool to see I wonder if this was an INT if it would actually show this I don't know why the um float values weren't showing that is so strange what happens if I remove this oh yeah now it shows I don't know why the custom field validator is causing it to show as none maybe if value else uh maybe this will work probably didn't have it fully completed the issues I guess sometimes of doing uh AI completions okay -10 doesn't work we make this now a float I think it will show what we expect and we make this 100 uh yeah now it shows okay so custom field validator we also have the ability so maybe we have like a password associated with our um account and this is you know sensitive information so if I had a very um very Advanced password such as password and I printed out my account by default oh no that's being logged and I can see my password right there but there's other like kind of built-in pantic things such as secret strings and if I now make password a secret string uh and I try to run this we see that it automatically hides that information so super useful if you're like you know trying to avoid logging sensitive stuff we can also add some custom type logic to this so imagine I tried to set my balance after the fact to be negative 100 if I run this it's totally fine with me doing that which should be an issue but if I do pass in validate assignment equals true here and now try to run this it will complain about that reassignment of the variable I could also do other things like I could make my name uh something that's uh so I can import something called field I can say my name needs to be Min length three max length 50 and I could also say that this is frozen equals true so if I ever try to change my name in my code so maybe I try to change my name to Humphrey good name it's going to yell at me for that I guess maybe first let me fix this error so it is now yelling at me because the field is frozen so I can't change it to Humphrey as I wanted to um but now it will let me once I remove that frozen field so lots of cool stuff you can do uh custom validators things like secret strings there's also like you could import like an email string so if you had an email you could validate automatically using the type email string that it is an email that is pantic in a nutshell hope you find it useful very useful for bigger python projects all right the fifth library that we're going to talk about today is rough so rough is a code formatter it's a code linter it's very quick and it also can help you improve your code in general so to use rough we can do something like we have let's say some code here okay so if I run this file we get a drawing that looks like this we can see the code if I zoom out a bit looks like this and what Ruff lets us do is if I open up a terminal and make sure you have Ruff installed by doing pip install rough I can do two different things that are very useful one is that I can do a

Segment 5 (20:00 - 22:00)

rough I can do a check and I could check this file so 05 ruff. py and it's telling me some issues that I have with this code that it doesn't like we see all these different error messages just kind of gives us formatting improvements for our code and you can kind of configure this so that it automatically does this when you're trying to commit code or uh push code that it doesn't let you save it without like fixing these errors but another thing that we can do that's cool is we can format it to adhere to a certain standard so if I let's say do a rough format and I format this file watch what happens to the code we see that it now adheres to pep 8 standards some of those like semicolons and stuff we saw on the screen are now removed it just looks a lot cleaner one thing that's interesting though is that we're not using some of these libraries so if I check this again we're still going to see that we have some issues so we libraries that are not imported one cool thing you can do with rough as well is we could do rough and I want to show my screen again rough check this file and then we can do D- fix and watch what happens to our code those issues those unused libraries are automatically removed and now we have you know a much cleaner formatted as well as a you know f file that doesn't have un imported libraries so rough can be super useful for this uh I will add a link to kind of some Advanced rough configuration settings and whatnot but I think one cool thing that you can do is you could have rough run automatically like when you save your file or something like that it might do this Auto reformatting and you can play around with a bunch of settings so rough can be super useful as well all right there were five libraries five we did tqdm the second one which was rich path lib panic and rough five libraries that you'll be glad that you have met if you start playing around and using them I'm going to try to incorporate them more into my daily workflows hopefully this video was educational and informative if you like this video make sure to throw it a thumbs up subscribe to the channel if you haven't already and that's all peace

Другие видео автора — Keith Galli

Ctrl+V

Экстракт Знаний в Telegram

Экстракты и дистилляты из лучших YouTube-каналов — сразу после публикации.

Подписаться

Дайджест Экстрактов

Лучшие методички за неделю — каждый понедельник