Ten hidden Python modules replace bloated third-party libraries
Overview
Python comes with a batteries-included philosophy, yet many developers immediately install third-party packages for tasks that the Python Standard Library handles natively. Utilizing these built-in tools reduces project bloat, minimizes security risks from external dependencies, and improves performance. This guide showcases how to write cleaner code using powerful, overlooked native modules.
Prerequisites
To get the most out of this tutorial, you should have a solid grasp of basic Python concepts like decorators, generators, and dictionary manipulation. A environment running Python 3.11 or later is highly recommended, as some modules like tomllib are not available in older versions.
Key Modules & Tools
functools: Utilities for higher-order functions, including caching and partial application.heapq: An implementation of the heap queue algorithm, ideal for priority queues.graphlib: Tools for working with graph-like structures, specifically topological sorting.tomllib: Native parsing for TOML configuration files, introduced in Python 3.11.

Code Walkthrough
Let's build a quick memoized power function and a dynamic priority queue to see how these standard modules work in practice.
Memoization with Functools
The cache decorator in functools optimizes CPU-heavy operations by storing previous inputs and results:
from functools import cache, partial
@cache
def compute_power(base: int, exponent: int) -> int:
# Computes power and caches the result automatically
return base ** exponent
# Create a specialized function using partial application
square = partial(compute_power, exponent=2)
print(square(10)) # Outputs 100
Prioritizing Tasks with Heapq
The heapq module dynamically orders tasks so that the lowest priority number is always processed first:
import heapq
tasks = [(2, "Write documentation"), (1, "Fix critical bug")]
heapq.heapify(tasks)
# Dynamic addition
heapq.heappush(tasks, (0, "Deploy emergency hotfix"))
while tasks:
priority, task = heapq.heappop(tasks)
print(f"Processing {task} (Priority: {priority})")
Syntax Notes
Python uses the division slash operator (/) in pathlib to join file paths gracefully, overriding standard division. When working with dataclasses, setting frozen=True provides read-only attributes, ensuring object immutability.
Practical Examples
Native modules shine in system automation. You can use graphlib.TopologicalSorter to schedule build pipelines by resolving tasks in sequence, or use secrets to generate secure, unguessable password reset tokens.
Tips & Gotchas
Do not use the standard random module for security keys or passwords; it is predictable. Always use secrets instead. When caching with functools.cache, be aware that it grows infinitely; use lru_cache(maxsize=...) for long-running processes to prevent memory leaks.
- Pydantic
- 33%· products
- Python
- 33%· products
- Python Standard Library
- 33%· products

10 Powerful Python Modules You’re Probably Not Using
WatchArjanCodes // 15:39
On this channel, I post videos about programming and software design to help you take your coding skills to the next level. I'm an entrepreneur and a university lecturer in computer science, with more than 20 years of experience in software development and design. If you're a software developer and you want to improve your development skills, and learn more about programming in general, make sure to subscribe for helpful videos. I post a video here every Friday. If you have any suggestion for a topic you'd like me to cover, just leave a comment on any of my videos and I'll take it under consideration. Thanks for watching!