5 Built-in Python Libraries That Will Elevate Your Coding
If you’ve ever spiraled down a rabbit hole of pip installs, Stack Overflow threads, and third-party modules only to find out later that Python already had what you needed built in. I hate to admit that I am guilty of that all the time.
One of the things I love most about Python is how powerful its standard library is. You don’t always need fancy external packages or bloated dependencies. Sometimes, the tools you need are already built into the programming language you are using.
So, here’s a roundup of built-in Python libraries (and some hidden gems within them) that I’ve stumbled across that have helped me tremendously both at work and in my personal projects.
1. collections: Your Data Structures’ Best Friend
The collections module extends Python’s core data structures with specialized alternatives that are faster, smarter, or just easier to work with in certain situations. If you’ve ever found yourself writing a ton of boilerplate just to count things, group data, or simulate queues, collections can do it, and almost certainly do it better.
One of my favorite things that I discovered from this library is from when I was looking at ways to solve interview questions back when I was job hunting. You can use counter to determine whether or not two words are anagrams of each other.
from collections import Counter
def are_anagrams(word1, word2):
# Remove spaces and convert to lowercase for comparison
word1 = word1.replace(” “, “”).lower()
word2 = word2.replace(” “, “”).lower()
# Use Counter to count character frequencies
return Counter(word1) == Counter(word2)
Other than counter, there’s also defaultdict, which saves you from those repetitive “if key not in dict” checks, and deque, which acts like a list but is optimized for fast appends and pops on both ends. I think if you are working with any sort of data structure then you need to be looking at this library to help you out in your day to day or interviews.
2. itertools: Iterate Smarter
Itertools is like a Swiss Army knife for iteration. It gives you a suite of fast, memory-efficient tools that work especially well with large data streams. This includes functions to help you calculate permutations, calculate combinations, count, or repeat.
from itertools import permutations
chars = [’A’, ‘B’, ‘C’]
for p in permutations(chars, 2):
print(p)
What makes itertools so useful is that it leverages Python’s generators under the hood. It’s especially helpful when you’re writing algorithms, doing simulations, or building tools that need to explore multiple combinations or patterns of data without exhausting memory.
3. datetime: The Time Library
Dealing with time, dates, and durations can get surprisingly complex, especially when formatting is involved or time zones come into play. Fortunately, Python’s datetime module is incredibly capable and helps handle all that mess with elegance. It’s the go-to solution for tracking logs, generating timestamps, calculating time differences, or formatting data for reports and interfaces.
from datetime import datetime, timedelta
now = datetime.now()
later = now + timedelta(hours=2)
print(f”Started at: {now}, will end at: {later}”)
# Output: Started at: 2025-06-28 20:52:54.886239, will end at: 2025-06-28 22:52:54.886239
4. os and pathlib: For When You Have To Talk to the Computer
Okay, I am going to combine two libraries in this one section because they are almost always used at the same time when I am writing code. If your script ever interacts with the file system, reading, writing, renaming, or creating directories, you’ll be dealing with either os, pathlib, or both. os provides the “lower level” functions for interacting with the operating system like checking environment variables or walking through directory trees, while pathlib offers a more modern, object-oriented way to handle file paths.
from pathlib import Path
screenshots = Path(”./screenshots”)
for i, file in enumerate(screenshots.glob(”*.png”)):
new_name = screenshots / f”screenshot_{i}.png”
file.rename(new_name)
5. enum: Defining Enums in Python
When your code relies on fixed sets of values, it’s tempting to use plain strings or integers. But those get messy fast! Enums, a built-in python module that lets you define named constant sets in a safe, readable, and maintainable way.
from enum import Enum
class token(Enum):
PLUS = “+”
MINUS = “-”
DIVIDE = “/”
MULTIPLY = “*”
print(token.PLUS)
Final Thoughts
One of the things that I have come to realize in my programming journey is that you don’t need to reinvent the wheel. Python’s standard library is full of hidden gems, and the more you explore it, the more you learn to appreciate all the things that Python has without the need for installing external packages. These built-ins save time, reduce dependencies, and often lead to more portable, maintainable code.
Let me know what your favorite built in library/function is so that I can check it out!