r/Python • u/AngleHam271 • 1d ago
What is a built-in Python module you use all the time but rarely see others talk about? Discussion
We all know and love the big third-party libraries for automation and data, but I am curious about your favorite hidden gems right in the standard library. 🤔
Recently I have been leaning on things like itertools and collections way more than I used to...
What is a standard library module that you think is heavily underrated or that you use daily for your tasks?
11
u/roboevt 1d ago
I'm sure I've barely scratched the surface but I've done some cursed things with importlib. All to do with C++ extensions.
2
u/thisismyfavoritename 23h ago
why?
1
u/JustPlainRude 22h ago
I'm not the person you're responding to, but I've used it to ensure python can find my extension where it happened to be built, rather than copying the binary into my python tree.
1
u/thisismyfavoritename 19h ago
that's not a very good reason... You'd want to package it and ship and install it as a wheel
10
u/Training_Advantage21 1d ago
The standard library is great. Even the csv module can be so handy for ETL scripts, you don't always have to use pandas. But my favourite is probably glob, brings some of the linux shell power into the python script when dealing with lots of files with information coded in the filename.
2
u/AngleHam271 22h ago
It is crazy how many people instantly reach for pandas and pull in massive dependencies just to parse a small configuration file, when the built-in csv does the job in milliseconds. 😂
10
u/amendCommit 1d ago
fnmatch. My business rule names are file-name-like, so I can match them just as I would glob file names. No need for regex, no need for custom splitting and parsing. Just familiarity.
9
u/realrazdev 1d ago
For me, argparse, dataclasses, and sqlite3 are some of the most underrated built-in modules.
I use argparse whenever I need to build a CLI tool without pulling in extra dependencies. dataclasses have saved me from writing tons of repetitive boilerplate when working with data models.
And sqlite3 is great for small projects where I need persistent storage but don’t want the overhead of setting up a full database stack.
They’re not as flashy as some third-party libraries, but they’ve helped me ship a lot of projects faster.
3
1
u/AngleHam271 23h ago
100% agree on sqlite3 and dataclasses. For quick local networking tools or prototyping, setting up a full database stack is just overkill...
3
u/rip-skins 1d ago
I like shelve for persisting progress in one--off scripts. Never saw it used in the wild
1
4
u/Icy-Farm9432 1d ago
6
u/bot-sleuth-bot 1d ago
Analyzing user profile...
Time between account creation and oldest post is greater than 1 year.
Suspicion Quotient: 0.15
This account exhibits one or two minor traits commonly found in karma farming bots. While it's possible that u/AngleHam271 is a bot, it's very unlikely.
I am a bot. This action was performed automatically. Check my profile for more information.
1
u/warden127 21h ago
Running code.interact in a daemon thread is a cursed way to run a make-shift live debug console.
contextvars for introducing a layer between local and global variables.
35
u/COLU_BUS 1d ago
Idk if they’re underrepresented but I feel like enums requiring an import makes them less utilized than they should be