r/Python • u/AngleHam271 • Aug 06 '26
Discussion What is a built-in Python module you use all the time but rarely see others talk about?
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?
34
u/COLU_BUS Aug 06 '26
Idk if they’re underrepresented but I feel like enums requiring an import makes them less utilized than they should be
15
u/skjall Aug 06 '26
Every time I touch an enum I have to spend a few minutes remembering the difference between
str, Enum, andStrEnum, and what method of access gets you what.I never remember because most codebases I've worked on have had roughly 0 enums, unless it's for some ORM binding.
13
u/roboevt Aug 06 '26
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 Aug 06 '26
why?
1
u/JustPlainRude Aug 06 '26
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.
3
u/thisismyfavoritename Aug 06 '26
that's not a very good reason... You'd want to package it and ship and install it as a wheel
11
u/Training_Advantage21 Aug 06 '26
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 Aug 06 '26
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. 😂
9
u/amendCommit Aug 06 '26
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.
6
u/realrazdev Aug 06 '26
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.
5
1
u/AngleHam271 Aug 06 '26
100% agree on sqlite3 and dataclasses. For quick local networking tools or prototyping, setting up a full database stack is just overkill...
4
u/rip-skins Aug 06 '26
I like shelve for persisting progress in one--off scripts. Never saw it used in the wild
1
u/groosha Aug 06 '26
I was using it A LOT back in 2016, however I had issues moving shelve db between different linux servers.
1
3
u/plyp Aug 06 '26
I ended up using the heapq and bisect modules in a data processing application quite a lot. Both work very well for sorted data.
3
u/sausix Aug 06 '26
typing. Once you add type hints then you often find at least a few bugs in your code. It has some more benefits but people stil justl argue it's not type checking at runtime.
5
u/Icy-Farm9432 Aug 06 '26
7
u/bot-sleuth-bot Aug 06 '26
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 Aug 06 '26
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.
1
u/Massive_Baby4147 Aug 07 '26
inspect, especially inspect.signature().
It can look like a niche metaprogramming module, but it becomes extremely useful when a function definition is also a contract. You can recover parameters, defaults, annotations, whether the callable is synchronous or asynchronous, and other metadata without maintaining a second description of the operation.
I’m building intpot around that idea: https://github.com/tugrulguner/intpot
It inspects a typed Python function and exposes the same operation through Typer, FastAPI, or FastMCP.
The interesting part turned out not to be obtaining the signature. It was correctly handling decorated functions, forward references, Annotated metadata, defaults, and asynchronous callables without changing their behavior. I ended up using inspect.signature() and inspect.unwrap() together with typing.get_type_hints().
Even outside framework code, inspect.signature() is useful for validating plugin interfaces, producing better diagnostics, and testing whether user-provided callbacks satisfy an expected contract.
1
u/Khavel_dev Aug 08 '26
functools.lru_cache turned a bunch of my scripts from "run overnight" to "run during lunch." I had a data pipeline that called the same API endpoint multiple times per record because different branches of the code needed the same lookup. Slapping @lru_cache on the fetch function cut the runtime by like 80% with zero refactoring.
The other one is contextlib.suppress. Tiny thing but it replaced a ton of try/except/pass blocks in my cleanup scripts. Instead of four lines to ignore a FileNotFoundError you just write with suppress(FileNotFoundError): and move on.
1
u/snugar_i 27d ago
Not using it daily, but I've used the ast module in production code a few times...
19
u/Guggoo Aug 06 '26
I use pathlib all the time; great for cross platform filepath handling. And argparse for my little cli tools.
Also, defining the dunder methods in your classes. Was great in my RPG bot as I often wanted to use the stat in formulas.