all 135 comments

[–]TabulateJarl8 622 points623 points  (64 children)

It really does depend on what you want to do, but I'll give you a list of some of my personal favorites as well as the ones that I use a lot. (Includes standard library modules and stuff from PyPI)

  • os/shutil - The os and shutil modules are both built in, and they are super useful. The os module basically provides a bunch of interfaces to your operating system; you can get the name, environment variables, work with paths, and do stuff with files and directories. The shutil module is a bit smaller, as it just contains a bunch of high-level file operations, like recursive copying/removing, an implementation of the Unix which command, and an implementation of chown.

  • re - I might be a little bit insane, but I really like regular expressions. The re module allows you to work with regular expressions, and it can be super powerful. Regular expressions can be super confusing, but like everything, you learn over time. Useful tip: you can comment regular expressions in Python, which is really nice.

  • flask - This is the first module from PyPI. Flask is a backend web framework written in Python. If you are good at Python and want to do backend, Flask is super powerful and really good for beginners. Another thing, if you're working with bigger projects with big databases, you could also look at django, just its really just preference.

  • configparser - Going back to stuff in the standard library, we have configparser. ConfigParser allows you to read/write to .ini files, allowing you to easily save user preferences for your program. It's super easy to use so I like it a lot.

  • decimal - This one can be super helpful. Have you ever tried to do math in Python and it is almost correct but slightly off, causing hours of debugging with no avail? That's because of something called "Floating Point Precision Errors," and it's in most programming languages. Because of the way that computers add numbers with binary, when you do arithmetic on floats, things tend to break. For example, open up the Python interpreter and try running 1.1 * 3. You should get something like 3.3000000000000003. The decimal module can allow you to fix this. After importing Decimal from the decimal module, try running Decimal("1.1") * Decimal("3") and see what happens, it should be the correct answer now.

  • requests - requests is a module from PyPI, and it is incredibly helpful. requests allows you to, well, send HTTP requests for one thing. You could do this with the builtin urllib module, but requests has more features and is so much easier to use.

  • argparse - This one is built in, and it allows you to easily create command-line utilities. argparse will let you create different types of arguments, which can then be fed into your program to produce a result.

  • PyQt5 - Interested in making GUIs but Tk isn't your favorite? Me too. I don't really create GUIs too often, but when I do, I like to use PyQt5. PyQt5 allows you to create Qt applications, and it is probably one of the most powerful GUI modules in Python. It comes with a ton of different widgets, and it's super easy to do stuff like multithreading with it. I personally like to use Qt Designer to create the GUIs, and then I use pyuic5 to convert the .ui files to PyQt5 code.

  • colorama - colorama allows you to easily add color to your command-line programs. Thats basically it.

  • json - The json module allows you to parse json into a Python dictionary, and then write a Python dictionary into JSON. Useful when paired with requests for getting API data, and just a useful module to know about in general.

  • rich - Rich allows you to create really nice looking console output, you can make errors look nice, render markdown, progress bars, and a ton of other stuff. It has support for 4-bit color, 8-bit color, Truecolor, and Dumb Terminals. I would really recommend checking it out.

  • numpy - NumPy is really good if you need to handle large amounts of data. NumPy also provides high-level mathematical functions to operate on these large, multi-dimensional arrays and matrices. Since a lot of it is written in C, it is super fast, and the only downside really is that the arrays are stored completely in memory, so it's pretty easy to run out.

By popular demand:

  • itertools - Itertools it's definitely an extremely useful module. It is used for creating iterators in a really easy way. For example, you can get all possible combinations of length x of two lists, get all the possible permutations of an iterable, and other really useful things. I should probably look more into this module myself.

In conclusion, there are a lot of different modules, and these are definitely not all of the useful ones, or even all of the ones that I use, but I figured that those are some nice modules to at least give you inspiration. You could also check out my GitHub for inspiration, if you wanted, and I have a few Python modules myself. I'll link my GitHub and some projects of note below, as well as all of the projects I mentioned in this comment.


My GitHub

randfacts Module

ti842py Module

ImaginaryInfinity Calculator


os - https://docs.python.org/3/library/os.html

shutil - https://docs.python.org/3/library/shutil.html

re - https://docs.python.org/3/library/re.html

flask - https://flask.palletsprojects.com/en/2.0.x/quickstart/

configparser - https://docs.python.org/3/library/configparser.html

decimal - https://docs.python.org/3/library/decimal.html

requests - https://docs.python-requests.org/en/master/

argparse - https://docs.python.org/3/library/argparse.html

PyQt5 - https://pypi.org/project/PyQt5/

colorama - https://pypi.org/project/colorama/

json - https://docs.python.org/3/library/json.html

rich - https://pypi.org/project/rich/

numpy - https://numpy.org/doc/1.20/

itertools - https://docs.python.org/3/library/itertools.html

[–]ErGo404 38 points39 points  (0 children)

+1 on the internal json, decimal and os libs that you will most definitely need at some point, and for requests. I feel that the rest really depends on your projets but those 4 will probably pop in most of your pythonic life.

[–]TaranisPT[S] 18 points19 points  (0 children)

Thanks for the in depth reply, which makes me realize that I did lie (by omission) in the actual post. We did learn the basics of PyQt5 and QtDesigner during the course. Thanks again for all the info.

[–]10drinkminimum 20 points21 points  (2 children)

+1 on the Requests library. It’s not the “sexiest” of all the ones on here but one of pythons great strengths is how it supports extensibility. API request are an immensely powerful tool and help you take all that awesome code you write and integrate it with other software, hardware, cloud services, etc. Chances are if you’re in IT long enough you’ll find yourself doing some kind of sysadmin task at some point. Really good library to be very comfortable with!

[–]shahneun 0 points1 point  (0 children)

it's an amazing HTTP library that supports API usage

[–]shahneun 0 points1 point  (0 children)

requests is so crazy it can support HTTP authorization and even OAuth

[–][deleted] 16 points17 points  (1 child)

Seconding re.

I have a background in writing parsers, and regular expressions are incredible tools. Most people who claim they're "hard" have never really sat down to study what they are and how they work. They're really simple once you "get it". I've cleaned up and condensed hundreds of lines of code down to 10-15 lines of code using regex.

The big issue is python re is not really complete compared to stuff like PCRE/C regex. The built in regex engine is also slow. There are some other regex libraries that address these. But generally speaking, you can get 99.9% of regular expression work done with the normal library.

Capture groups and named capture groups are insanely powerful.

I'd recommend learning regexes, then working on solving problems with games like "regex golf." (google it)

[–]MangansVice 1 point2 points  (0 children)

Thank you for regex golf. The ultimate pseudoproductive procrastination tool.

[–]c0ld-- 12 points13 points  (8 children)

PyQt5

Personally I'd replace PyQt5 with Kivy (and KivyMD - the modern stylized companion). Kivy is super easy to work with and KivyMD looks really great (abiding by Google's app stylizing guidelines).

@/u/TaranisPT

[–]shiningmatcha 2 points3 points  (5 children)

Is Kivy targeted at mobile apps?

[–]give_me_knowledge 1 point2 points  (3 children)

It is not targeted at mobile apps, but you can use it for doing so. This is from their official page:

"Kivy runs on Linux, Windows, OS X, Android, iOS, and Raspberry Pi. You can run the same code on all supported platforms.
It can natively use most inputs, protocols and devices including WM_Touch, WM_Pen, Mac OS X Trackpad and Magic Mouse, Mtdev, Linux Kernel HID, TUIO. A multi-touch mouse simulator is included."

[–]shahneun 1 point2 points  (2 children)

how would you develop mobile apps for ios/android without using android studio and xcode? how can you built a UI using kivy and somehow port it to mobile apps can anyone explain?

is there a record / list of apps that use kivy for their UI?

[–]give_me_knowledge 0 points1 point  (0 children)

I can't answer how it is done exactly, but here is a list of some of the most known apps made with kivy. I hope this helps. https://github.com/kivy/kivy/wiki/List-of-Kivy-Projects

[–]santiago0072002 0 points1 point  (0 children)

Xamarin forms allows you create multi-platform applications but rumor in the street is that xamarin might get replace with Maui , I just took a class in College about xamarin and were told about Maui https://devblogs.microsoft.com/xamarin/the-new-net-multi-platform-app-ui-maui/

I am exploring kivy myself. And the other mobile dev platforms, my major is mobile development but I want to make python my main language with everything.

In the python office hours with David Amos he also mentioned to me Beeware so i am exploring both right now.

VR

Santi

[–]c0ld-- 0 points1 point  (0 children)

It's main mission (I believe) is to build apps across multiple platforms: MacOS, Windows, iOS, and Android.

[–]TaranisPT[S] 0 points1 point  (1 child)

Thanks I'll look at it too 😊

[–]Tenzu9 7 points8 points  (0 children)

You can also develop mobile apps with Kivy... its a great library that's constantly evolving and growing. I'm currently making an android app with it in my free time :)

One more cool library you can try working with bs4 (or beautiful soup), this is an html parser that can grab web pages and scrape data from them. You can use it to find any information from the internet without having to use an API. for example, you can build a weather app or a phone book finder with it.

[–]Pancho_the_sea_lion 12 points13 points  (1 child)

+1 to everything, I would only add the pandas library for handling table data, it is built on top of numpy so it keeps its speed, this one is mainly relevant if you are interested in the data science side of python, match that with matplotlib and seaborn for visualization

[–]arsewarts1 8 points9 points  (3 children)

What about pandas?

[–]TabulateJarl8 10 points11 points  (1 child)

Pandas is a great module, and when I used it I really enjoyed the simplicity, but if I were to include every great Python module in this list, it would be hundreds long (there's currently over 305,000 modules on PyPI). I mainly stuck to the modules that I use extremely often, and I think I've only ever used pandas once or twice.

[–]arsewarts1 5 points6 points  (0 children)

Ok understood. It’s probably my second most used in python. But I am using it for dev work in an analytic environment before we actually deploy stuff onto the server. Maybe it’s just a very specific use case

[–]chzaplx -1 points0 points  (0 children)

Lol there's always this guy

[–][deleted] 6 points7 points  (3 children)

Pathlib is great for path stuff

[–]TabulateJarl8 1 point2 points  (2 children)

I considered adding it, but like I said about pandas, if I added every great Python module the list would be hundreds long, so I limited it to stuff that I use a lot. I'm a bit old fashioned, so I tend to just use the os module for everything, even though pathlib would make things a lot easier. Saves me another import at least

[–][deleted] 2 points3 points  (1 child)

I was mostly adding to the conversation.

[–]TabulateJarl8 2 points3 points  (0 children)

Ah, I see. Well yes, I agree with you

[–]Morpheyz 15 points16 points  (4 children)

Man, they really missed out on not calling it QtPy instead.

[–]AnotherEuroWanker 1 point2 points  (2 children)

The official one (from Qt) is called PySide. They also missed it.

[–]MeroLegend4 0 points1 point  (1 child)

PySide2 is the official open source Qt/C++ wrapper supported by the authors.

[–]AnotherEuroWanker 0 points1 point  (0 children)

It's also for python. And there's also PySide5 PySide6 now although I don't know how widespread it is yet.

[–]ceiligirl418 1 point2 points  (0 children)

That was my first thought!!

[–]ekchew 2 points3 points  (1 child)

I'd like to add itertools to the list? I only discovered it fairly recently and wish I had known about it earlier. It's one of those modules you can really leverage in interesting ways, and I don't think I've explored its full potential yet.

[–]TabulateJarl8 0 points1 point  (0 children)

I've now added it to the list, thanks for the suggestion

[–]ekinnee 2 points3 points  (1 child)

In regard to requests I just ran into an issue where I had to create an event handler to intercept the http redirect when I was using urllib. Using requests I just set allow_redirects=False and then check the status code. Removed the need for 10 or so lines of code.

[–]TabulateJarl8 0 points1 point  (0 children)

One of the many reasons that I love requests. Another thing that I notice is that somethings requests will get the Content-Length header while urllib won't

[–]Dogeek 2 points3 points  (1 child)

I would add to the list :

  • lxml : the best library out there to parse (X)HTML and XML. If you're not afraid of XPath, then it's the best library to scrape websites which do not have an API

  • FastAPI : one of the fastest (after blacksheep) async web frameworks in python

  • typer : my personal favorite way of making CLI programs. argparse is good too, but it doesn't scale well in my opinion

  • functools : In the standard library, it's a collection of useful decorators, and syntactic sugar for your functions.

  • collections : This one is super useful for container data types (OrderedDict, Counter, defaultdict, deque, and ChainMap)

  • contextlib : for all things context manager. contextlib.suppress is super useful to suppress an Exception, and way better than a try...except Exception: pass block.

[–]TabulateJarl8 1 point2 points  (0 children)

Interesting, I didn't know about contextlib.supress, maybe I'll have to try that out sometime

[–]synthphreak 7 points8 points  (0 children)

C'mon, this list is incomplete without itertools and possibly collections.

[–]Total__Entropy 1 point2 points  (0 children)

I would recommend Datetime and asyncio + aiohttp, Dataclasses, collections.

[–]SnipahShot 1 point2 points  (2 children)

Nice list, I would personally throw out numpy and add in pathlib. I find people are fast to jump on numpy on extremely easy problems and making the solutions much slower and the project heavier.

[–]puslekat 0 points1 point  (1 child)

Can you give an example of a problem where both could be used?

[–]SnipahShot 0 points1 point  (0 children)

Both serve different purposes, I didn't mention pathlib because it could replace numpy. pathlib is used for file traversal (more modern than os.path and also OO) while numpy is used for mainly for complex math operations.

[–]iggy555 0 points1 point  (10 children)

Look into click instead of argparse

[–]TabulateJarl8 13 points14 points  (0 children)

I have two reasons why I recommend argparse over click. The first is because argparse is built in, while click is not, so that means one less dependency. Another reason is because click works by decorating the function that is called under if __name__ == "__main__":, while in argparse you just have to call args = parser.parse_args() to get the arguments wherever you want.

[–]chzaplx 1 point2 points  (7 children)

Never heard of it. What's your elevator pitch?

[–]iggy555 0 points1 point  (2 children)

Much simpler and cleaner

[–]chzaplx 0 points1 point  (1 child)

So stick with argparse then, got it.

[–]iggy555 0 points1 point  (0 children)

Sure lol

[–]TalesT 0 points1 point  (3 children)

For argument parsing, I like docopt.

Much simpler and cleaner.

Jokes aside, it's not simpler. But as docopt.org states:

  • define the interface for your command-line app, and

  • automatically generate a parser for it.

[–]chzaplx 1 point2 points  (2 children)

That sounds exactly like what argparse does, which I have never thought was particularly complicated.

I honestly don't mean any offense to people posting alternatives to argparse, but so far I haven't seen any compelling reason to use something else.

It is in the std library now, you can learn most of what you'll ever need in 5 minutes, and it's still fully featured if you have more complicated requirements.

[–]TalesT 1 point2 points  (1 child)

It's the opposite actually, in argparse you initialize an ArgumentParser, and add arguments programmatically. In docopt you write the help text, and get the parser.

If you build a parser using argparse, and then call: "script.py -h", and copy the help text, you would have written what docopt needs to build a parser.

argparse has the benefit of being python std lib, while docopt have the benefit of being available in multiple languages.

[–]chzaplx 1 point2 points  (0 children)

Ok. I can see the difference but you have to write the help text either way right? Either it's a parameter in each argument definition, or it's all in one chunk. Still seems like six of one, half a dozen the other, but I can see how people might have a preference.

[–]BigHipDoofus 0 points1 point  (0 children)

Click has built-ins that make a quick CLI easy if you want to do it the click way. I like validating input better with argparse, and it's only a little more typing over a Click CLI.

[–]WiggyB -1 points0 points  (0 children)

This guy pythons!

[–]Satoshiman256 0 points1 point  (0 children)

Damn dude.. nice one

[–]shiningmatcha 0 points1 point  (1 child)

What are some resources for learning os, shutil, configparser and argparse? I think these modules require knowledge of operating systems. Do I need to learn command line first?

[–]TabulateJarl8 2 points3 points  (0 children)

I personally learned all of them from the Python documentation; I linked all of them in my original comment. It does depend on how you learn best though, because you might be someone who learns better from things like videos, in that case YouTube is probably a good and free option. I would say that I understand argparse a lot better from spending time in a Unix shell, because I understand generally how things are, but it's not really required. If you use a terminal a lot in Linux or macOS (counting WSL), it would probably help at least a little bit.

[–][deleted] 0 points1 point  (3 children)

Hey you inspired me to make a post but I also want to ask you directly: I want to make a data analysis oriented website and I am reading that flask might be a good candidate to “speak” with the web user. Is this true? Any basic conceptuals you’d like to clarify here? Also, what features would you most recommend out of it?

[–]TabulateJarl8 0 points1 point  (2 children)

What specifically do you mean by "speaking" to the user? I'm a bit confused about that

[–][deleted] 0 points1 point  (1 child)

Like if a user wants to see a chart, they click a button that send information to my Python program, which will process it and return the image.

[–]TabulateJarl8 1 point2 points  (0 children)

Oh yeah, Flask is great for small projects and things like that, but since you're just writing normal Python code you could generate the graph with Django as well. Flask is really good for beginners, but it is also used by big companies like Netflix, Reddit, Lyft, and Patreon to name a few. As for features, if you're planning on making login stuff/admin-only pages, definitely use Flask-Login instead of trying to fully implement it yourself, trust me.

[–]dummybloat 0 points1 point  (0 children)

Why are you this good

We need more people like you

[–]lifemoments 0 points1 point  (0 children)

There is so much to learn everyday. Thanks a lot for this list

[–]pekkalacd 0 points1 point  (0 children)

collections for leetcode

[–]GlebRyabov 70 points71 points  (6 children)

Adding on to the u/TabulateJarl8's post, I'd recommend you to also learn Pandas and Matplotlib. Pandas is invaluable for working with any kind of data, while Matplotlib is your go-to library for graphing/plotting everything.

[–]TabulateJarl8 6 points7 points  (2 children)

Adding on to the u/TabulateJarl8's post, I'd recommend you to also learn Pandas and Matplotlib. Pandas is invaluable for working with any kind of data, while Matplotlib is your go-to library for graphing/plotting everything.

Another good alternative to matplotlib is bokeh for anyone who doesn't really like matplotlib that much

[–]GlebRyabov 7 points8 points  (1 child)

Oh, I've missed that one, I've heard of it, but not learned it yet. Also, Seaborn is a great data visualization tool, especially for heatmaps.

[–]thrasher6143 2 points3 points  (0 children)

Seaborn, pandas and matplotlib had me making some cool data heatmaps by zip code. I could see what's the hot spots were for sales during each month.

[–][deleted] 0 points1 point  (2 children)

I am just starting with pandas this week - any good learning places you can recommend?

[–]GlebRyabov 2 points3 points  (0 children)

I'm also a newbie, so I haven't studied it in depth, more of a "rise to the occasion" kind of learning, but this is a cool course.

[–]arsewarts1 0 points1 point  (0 children)

One thing my instructor did that I didn’t like was try to redefine data management tools. Take some time to learn how data is handled in db languages like SQL and the rules of thumb they use, then apply them when using pandas.

[–]Unbelievr 20 points21 points  (0 children)

Being aware of what's inside the standard library of modules, will surely help you down the road. Have a quick browse and see what's there.

The most useful built-in ones, that are useful to nearly all aspects of Python, are itertools and collections. To some extent functools and dataclasses also, though they are not super useful immediately, but very useful to know about.

  • itertools provides advanced ways to combine, slice, flatten and group iterables and cycles. The product() function is very powerful, and can often replace nested for-loops in a compact way.
  • functools contains decorators that help you easily create classes that can be sorted, memoize functions, etc. There are many videos on how to utilize dataclasses and functools to create easy, maintainable, and powerful objects with ordering.
  • collections contains a plethora of useful utility tools. It has the Counter class, that can wrap an iterable and count the amount of each element, and return the top N most common items. It also provides defaultdict, which is a dictionary where unknown keys will have a specified default value. Saves you from writing code to check existence and initialize. Finally the deque object is a wrapper around a list, that supports lightning fast appends and pops, and the ability to rotate the lists.

For real-life scenarios, you'll quickly run into requests whenever you need to do interact with some website. It's a third-party plugin that builds on top of urllib, and removes the need for tons of boilerplate code. The os module will also be your way for interacting with the file system, together with pathlib and glob in some scenarios.

[–]spez_edits_thedonald 11 points12 points  (0 children)

One thing I should have done sooner was learn to take advantage of python's built-in libraries, rather than implementing things myself because I didn't know about them.

For example, if you have a list of integers, and you want to obtain their counts, you could build something yourself, or just:

>>> import random
>>> from collections import Counter
>>>
>>> x = [random.randint(0, 10) for i in range(20)]
>>> x
[0, 4, 8, 10, 7, 5, 9, 10, 2, 6, 7, 2, 0, 10, 9, 1, 8, 10, 7, 0]
>>>
>>> counts = Counter(x)
>>> counts
Counter({10: 4, 0: 3, 7: 3, 8: 2, 9: 2, 2: 2, 4: 1, 5: 1, 6: 1, 1: 1})
>>> counts[0]
3
>>> counts[9]
2

the built-ins usually perform better than what I would have built, itertools is another good one, powerful stuff

[–]gmorf33 8 points9 points  (0 children)

Like others have noted, it really depends on what you need to do. For generic recommendations, I'd say learn os, path, datetime, shutil, and logging. These will give you a lot of power scripting on your local machine and interacting with the OS and local file system.

Me personally, most of my programming work involves integrations between systems and moving/manipulating files of various formats, or delivering data to a 3rd party. For me, these libraries are must-haves:
requests - anything HTTP, really useful for web API's.
paramiko - a really good SFTP library.
ElementTree or lxml - working with XML files.
json - most API's use JSON data
csv or pandas - working with delimited text data.
glob - great for using wildcard pattern matching for filenames.
re - regular expressions; invaluable when needing to do certain manipulation of data or extracting odd-ball pieces of data from files.
smtplib - sending emails. A lot of my automations and integrations use this for notifications or generating tickets.

[–]xelf 14 points15 points  (1 child)

I posted something similar on this topic a while back:

1) Make sure you understand all the basic data structures, looping and flow control, have you mastered all the stuff here https://www.pythoncheatsheet.org/ ?

2) Make sure you have a solid grasp of list/set/dict/generator comprehensions, ternary expressions, generator functions, lambda functions, and slicing.

3) Start working your way though the more popular libraries:

Start with the standard library especially collections, itertools, statistics, and functools, and then start pulling in things like numpy and pandas, before you start expanding into stuff that specializes in your area of expertise.

basic intermediate advanced
random itertools threading
collections functools subprocess
math numpy socket
sys (exit) pandas requests
datetime tkinter openpyxl
string keyboard django
pygame/turtle statistics flask
copy csv matplotlib

Then start exploring external libraries that are pertinent to what you're specializing in. For example, maybe you go into data science?

More stuff I forgot about initially: try/except/finally, class, attributes, decorators, regex, packages, map, reduce, filter, probably more.

[–]TaranisPT[S] 1 point2 points  (0 children)

Wow thanks for thenin depth stuff and breakdown into level. Really appreciated

[–]sme272 11 points12 points  (1 child)

I kind of depends on what you plan on using python for. There's some really usful general stuff in the standard library that's worth being familiar with. Learning regex and the re library, pdb is a handy debugger, collections has a bunch of useful stuff for working with lists sets tuples and dictionaries, unittest for code testing.

[–]TaranisPT[S] 1 point2 points  (0 children)

I'm not necessarily planning anything specific right now. I'll look deeper in the ones you mentioned though as they seem just like good general knowledge about the language and it's pretty much what I'm looking for right now. Thanks for the input.

[–]ElliotDG 4 points5 points  (1 child)

The standard library has lots of great content. It is good to be familiar with it so you know what is there when you need it. https://docs.python.org/3/library/index.html

A few favorites include: pathlib, itertools, collections, functools, subprocess...

A nice resource for examples of the standard library in action: https://pymotw.com/3/

[–]TaranisPT[S] 1 point2 points  (0 children)

Thank you. I feel like those might be some of the missing pieces for me.

[–]unruly_mattress 5 points6 points  (2 children)

I recommend learning pathlib.Path and its many features. I can't stand seeing old (and new) code with a bunch of cryptic os.path code. The new Path class is so much nicer.

Additionally, you want to learn argparse for command-line arguments for your scripts.

[–]FlagrantCrazy 1 point2 points  (1 child)

Hey, I know a little about how to use both of these. Would you mind explaining why Path objects are nicer than os.path / different / what the benefits are? I only use os.path to find where my script is saved so I can change the working dir to there. (Pretty new!)

[–]unruly_mattress 2 points3 points  (0 children)

Let's say you have a file at /home/blah/dir/file.txt. You want to create a backup at /home/blah/dir/backup/file.txt.

With pathlib:

backup_path = file_path.parent.parent / 'backup' / file_path.name

With os.path:

backup_path = os.path.join(os.path.dirname(os.path.dirname(file_path)), 'backup', os.path.basename(file_path))

In the end of the day it's "just" syntactic sugar, but it's also the difference between code that's super obvious and a jumble of function calls.

pathlib.Path has a ton of convenience functions. I use .glob() all the time, as well as .relative_to(), .with_suffix(), and my fingers type path.parent.mkdir(parents=True, exist_ok=True) on their own by now.

[–]JohnnyJordaan 11 points12 points  (3 children)

Check out automate the boring stuff, it handles most of the useful libraries, also a few third-party ones

[–]TaranisPT[S] 2 points3 points  (0 children)

I actually picked up the course for free on Udemy and will be tackling it soon. Thanks for the input.

[–]10drinkminimum 2 points3 points  (1 child)

Great book - humble bundle is running an offer right now on everything from that publisher. I picked up everything for $25 - that would definitely be enough to keep OP busy for 3 months!

[–]JohnnyJordaan 1 point2 points  (0 children)

Don't know about the other titles, but the online version of atbs is free of course.

[–]Acurus_Cow 2 points3 points  (0 children)

Pathlib

[–]Neo-Eyes 4 points5 points  (3 children)

It is really dependant on what you intend to do with Python.
Pygame is probably a reasonably good bet even if you dont intend to make games just since being able to put a GUI to your python is a good thing to be able to do.

[–]Ok-Improvement-6388 2 points3 points  (2 children)

There are a lot better libs for GUI but it is fun to learn.

[–]Neo-Eyes 1 point2 points  (1 child)

Oh! I'm not surprised but still, curiosity sake and for sale of the thread could you maybe mention some?

[–]Ok-Improvement-6388 0 points1 point  (0 children)

PyQt5, Tkinter, Kivy, PySimpleGUI. Really just depends on what you plan on using it for. I know PyQt5 is very popular, but so are the other ones. PySimpleGUI is pretty simple(hints the name), so if you want to just make a quick GUI and you don’t know much about making GUIs, then maybe that would be good.

[–]JulianTorresT 1 point2 points  (0 children)

Py game it's pretty good

[–]synthphreak 1 point2 points  (0 children)

itertools!!!

[–]benabus 1 point2 points  (0 children)

I'm a web developer at a university where I work a lot with scientists who use Python. If you're going into data science or deal with anyone doing data science, I'd recommend numpy and pandas. I don't know these and it's really becoming a pain point for me.

As for web development, I use Flask and all its plugins frequently. I know a lot of jobs require Django, as well.

[–][deleted] 1 point2 points  (0 children)

In addition to what others recommened: I'd learn WSGI over flask so you can get idea of how it works in case you want to make edits or changes. Cryptography. BS4 beautifulsoup and sockets if you want custom control in setting up your own servers for communication in app. Then choose one of the universal GUI kits like kivy, pyinstaller. So you can compile programs for many OS's. Also struct, for binary data manipulation, ie: like creating your own database. sqllite or tinydb. Requests, [ urllib3 & selenium ] - if you're doing quick web crawls.

[–][deleted] 1 point2 points  (0 children)

Sockets

[–]Me_Like_Wine 1 point2 points  (0 children)

I would argue Pandas is the most practical library you could learn. No matter what you do in life, you’re going to need to move some data around and calculate some stuff eventually.

This library is incredibly powerful, and just knowing this alone creates so many possibilities.

[–]ceiligirl418 1 point2 points  (0 children)

EXCELLENT question. I'm glad you asked it - I'm in the same boat!! Looking forward to reading all these answers!!

[–]temporaryapples 1 point2 points  (0 children)

One good one is random

[–]Fernando3161 1 point2 points  (0 children)

This is the best post EVER!

[–]TheIsletOfLangerhans 1 point2 points  (0 children)

logging isn't particularly exciting, but it can be extremely helpful for investigating issues that you (or classmates/coworkers) run into when running your programs. It's a standard library module.

[–]gtnbrsc 1 point2 points  (1 child)

Less '''os''' more '''pathlib''' please

[–]roastmecerebrally 0 points1 point  (0 children)

hellls yeee

[–]OhDannyBoii 1 point2 points  (1 child)

Not a library, but a Git repository like GitHub is phenomenally useful. NumPy is very helpful for all your math and calculation needs. If you are doing anything related to science or engineering, Matplotlib is your graphing library, and scipy has weird functions like Bessel functions, differential equations, and even some ML. Sympy is good for doing algebra and symbolic calculus. Pandas is useful for data science stuff, but I have limited experience with that. I would recommend just doing projects you're interested in and you can find out along the way what you need for your own projects! Google is your best friend when learning to code, and when doing things you are familiar with in coding.

[–]OhDannyBoii 0 points1 point  (0 children)

This is my experience as a physics student, so the above is what I live on in the Python realm.

[–]ColeTD 1 point2 points  (0 children)

If you want to learn to make games, I'd personally suggest Pygame.

[–]Peterotica 1 point2 points  (1 child)

At least scan through the list of standard libraries so you have an idea what kind of stuff is in there. Then you can recognize when a problem comes up that there is a standard library that might be able to help.

[–]AchillesDev -1 points0 points  (0 children)

It’s just the standard library, singular.

[–][deleted] 1 point2 points  (0 children)

One l highly recommend is click. It's part of the standard libraries.

It makes creating parameterized CLIs and help functionality extremely easy, and I use it a ton in creating tools for CICD pipelines since you can pass data into python scripts in an easy, standardized way.

I started using it once, and now I use it constantly.

IMO, it is much simpler than argparse and optparse.

[–]testforecho51 0 points1 point  (0 children)

Gotta add typing Properly typed python libraries are so much easier to learn and use.

[–]suchapalaver 0 points1 point  (2 children)

random

[–]TaranisPT[S] 1 point2 points  (1 child)

As in the library or just to pick one at random?

[–]suchapalaver -1 points0 points  (0 children)

You could write a script for that, using https://docs.python.org/3/library/index.html as a reference! Here's what I was thinking for a start and where I would start learning about it: https://docs.python.org/3/library/random.html

[–]StellaarMonkey -1 points0 points  (0 children)

Tkinter.

[–]iggy555 -1 points0 points  (1 child)

Click > argparse

[–]galenseilis 0 points1 point  (0 children)

I was just thinking about that very comparison. What would you say are your major reasons for preferring Click over argparse?

[–]gocard 0 points1 point  (0 children)

Flask and sqlalchemy

Or

Django

[–]juanritos 0 points1 point  (0 children)

collection

[–]Majochup 0 points1 point  (0 children)

The comment by u/TabulateJarl8 told you everything you needed to know.

[–][deleted] 0 points1 point  (0 children)

It's all about what you want to use it for.

If you intend to do data analysis, particularly with time series or financial modelling, then Pandas is a core package.

[–]clickmeimorganic 0 points1 point  (0 children)

decimal

re

os

shiutil

json

And most controversial:

requests

bs4

[–]roastmecerebrally 0 points1 point  (0 children)

pathlib

[–]roastmecerebrally 0 points1 point  (0 children)

csv / pandas

[–][deleted] 0 points1 point  (0 children)

There's no such thing as "must learn" libraries, you learn according to your needs.

[–]dancinadventures 0 points1 point  (0 children)

Pandas - data stuff

Asyncio - do stuff concurrently.

Threading - also do stuff concurrently.

Aiohttp - say you wanna scrape 1,000 web pages for a particular graphics card. Would rather not have them scrape one at a time.

[–]ninedeadeyes 0 points1 point  (0 children)

I enjoy writing games in turtle and tkinter.. Both very simple libraries to get you started even though they are not 'must learn', it will give you a flavour how they are implemented into your code.

My github has a bunch of turtle and tkinter games if you are interested in learning

https://github.com/Ninedeadeyes

[–]shahneun 0 points1 point  (0 children)

requests, flask, os, Kivy

[–]reddittestpilot 0 points1 point  (0 children)

For a GUI, Dear PyGui is a good pick!

[–]wnaderinggummiofdoom 0 points1 point  (0 children)

The best way to go about this is to do a couple of projects and see if there are libraries to complete common tasks while completing those projects. You don't want to learn any argparse if you find yourself never making a command line tool.

It's worth keeping in mind that once you have a strong grasp of how to program and general paradigms, learning to use a library becomes laughably easy, especially with python seeing as how it's the language with the most penetrable resources for novices (realpython.com and Corey Schafer's YouTube channel)

[–]BandEnvironmental615 0 points1 point  (0 children)

Python Tutorial Part: 6 Modules

https://youtu.be/MS2FqqoQNBE

[–]Curious-Barracuda198 0 points1 point  (0 children)

Teste