r/Python 26d ago

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?

0 Upvotes

26 comments sorted by

20

u/Guggoo 26d ago

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.

34

u/COLU_BUS 26d ago

Idk if they’re underrepresented but I feel like enums requiring an import makes them less utilized than they should be

16

u/skjall 26d ago

Every time I touch an enum I have to spend a few minutes remembering the difference between str, Enum, and StrEnum, 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 26d 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 26d ago

why?

1

u/JustPlainRude 26d 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.

3

u/thisismyfavoritename 26d ago

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 26d 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 26d 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. 😂

8

u/amendCommit 26d 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.

7

u/realrazdev 26d 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.

5

u/shinitakunai 26d ago

Sqlite3 is godlike for easy prototyping and PoC

1

u/AngleHam271 26d ago

100% agree on sqlite3 and dataclasses. For quick local networking tools or prototyping, setting up a full database stack is just overkill...

5

u/rip-skins 26d ago

I like shelve for persisting progress in one--off scripts. Never saw it used in the wild

1

u/groosha 26d ago

I was using it A LOT back in 2016, however I had issues moving shelve db between different linux servers.

1

u/bmrobin 26d ago

never heard of it, thanks for the reading opportunity you've given me

3

u/plyp 26d ago

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 26d ago

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.

2

u/akl773 26d ago

difflib. SequenceMatcher is what i reach for whenever i need to measure how much a human changed a generated bit of text, and i never see anyone mention it lives in the stdlib.

5

u/Icy-Farm9432 26d ago

8

u/bot-sleuth-bot 26d 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 26d 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.

1

u/Massive_Baby4147 25d ago

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 24d ago

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 18d ago

Not using it daily, but I've used the ast module in production code a few times...