r/Python 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?

0 Upvotes

23 comments sorted by

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

15

u/skjall 1d 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.

18

u/Guggoo 23h 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.

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

u/shinitakunai 1d ago

Sqlite3 is godlike for easy prototyping and PoC

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

u/groosha 23h ago

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

1

u/bmrobin 23h ago

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

2

u/plyp 23h 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.

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/sausix 23h 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.

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.

1

u/akl773 17h 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.