Top 10 Essential Python Packages Every Developer Should Know
This article introduces the ten most essential and widely used Python packages—including NumPy, Pendulum, Pillow, MoviePy, Requests, Tkinter, PyQt, Pandas, Pywin32, and Pytest—explaining their core features, typical use cases, and providing code snippets to help developers quickly adopt them in various projects.
There are over 200,000 Python packages on PyPI, which makes it difficult for developers to know which ones are most important. This article lists ten essential, broadly applicable packages that frequently appear in many Python projects.
1. NumPy NumPy simplifies complex mathematical operations by providing multi‑dimensional arrays and a rich set of mathematical functions. It is also a foundational library for many machine‑learning frameworks.
<code>>>> import numpy as np
>>> a = np.arange(15).reshape(3, 5)
>>> a
array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14]])
>>> a.shape
(3, 5)
>>> a.ndim
2
>>> a.dtype.name
'int64'
>>> a.itemsize
8
>>> a.size
15
>>> type(a)
<class 'numpy.ndarray'>
>>> b = np.array([6, 7, 8])
>>> b
array([6, 7, 8])
>>> type(b)
<class 'numpy.ndarray'>
</code>2. Pendulum Pendulum is a drop‑in replacement for the built‑in datetime module that offers a more intuitive API, automatic timezone handling, and easy parsing of common datetime formats.
<code>import pendulum
now = pendulum.now("Europe/Paris")
# Change timezone
now = now.in_timezone("America/Toronto")
# ISO‑8601 string
iso = now.to_iso8601_string()
# Shift by two days
later = now.add(days=2)
</code>3. Pillow (Python Imaging Library) Pillow enables opening, manipulating, and saving images in many formats. It is the go‑to library for basic image processing tasks such as resizing, rotating, and format conversion.
<code>from PIL import Image
# Open an image
im = Image.open("images/cuba.jpg")
im.show()
# Rotate the image
im = im.rotate(45)
im.show()
</code>For more advanced computer‑vision work, OpenCV can be used alongside Pillow.
<code>import cv2
import numpy as np
import matplotlib.pyplot as plt
image = cv2.imread("C://gfg//tomatoes.jpg", 1)
half = cv2.resize(image, (0, 0), fx=0.1, fy=0.1)
bigger = cv2.resize(image, (1050, 1610))
stretch_near = cv2.resize(image, (780, 540), interpolation=cv2.INTER_NEAREST)
Titles = ["Original", "Half", "Bigger", "Interpolation Nearest"]
images = [image, half, bigger, stretch_near]
for i in range(4):
plt.subplot(2, 2, i+1)
plt.title(Titles[i])
plt.imshow(images[i])
plt.show()
</code>4. MoviePy MoviePy provides high‑level functions for video editing such as cutting, concatenating, adding titles, and applying effects. It works well for standard video‑processing tasks, while more complex operations may still require OpenCV.
<code>from skimage.filters import gaussian_filter
from moviepy.editor import VideoFileClip
def blur(image):
"""Returns a blurred (radius=2 pixels) version of the image"""
return gaussian_filter(image.astype(float), sigma=2)
clip = VideoFileClip("my_video.mp4")
clip_blurred = clip.fl_image(blur)
clip_blurred.write_videofile("blurred_video.mp4")
</code>5. requests The requests library makes HTTP communication simple and human‑friendly, handling query strings, form encoding, and connection persistence automatically.
<code>import requests
from requests.exceptions import HTTPError
for url in ['https://api.github.com', 'https://api.github.com/invalid']:
try:
response = requests.get(url)
response.raise_for_status()
except HTTPError as http_err:
print(f'HTTP error occurred: {http_err}')
except Exception as err:
print(f'Other error occurred: {err}')
else:
print('Success!')
</code>6. Tkinter Tkinter is the standard GUI toolkit bundled with Python, providing a straightforward way to create cross‑platform graphical interfaces.
<code>from tkinter import *
window = Tk()
window.title("Welcome to LikeGeeks app")
window.mainloop()
</code>7. PyQt PyQt offers bindings to the Qt framework, enabling the development of sophisticated, cross‑platform desktop applications. It is more suitable than Tkinter for heavyweight GUI projects.
8. Pandas Pandas is the premier library for data manipulation and analysis in Python, offering powerful data structures like DataFrames and time‑series functionality.
<code>import pandas as pd
import numpy as np
dates = pd.date_range("20130101", periods=6)
df = pd.DataFrame(np.random.randn(6, 4), index=dates, columns=list("ABCD"))
print(df)
</code>9. Pywin32 Pywin32 provides access to many native Windows APIs, allowing Python scripts to interact with the Windows registry, clipboard, and other system components.
<code>import win32com.client as win32
excel = win32.gencache.EnsureDispatch('Excel.Application')
excel.Visible = True
input("Press ENTER to quit:")
excel.Application.Quit()
</code>10. Pytest Pytest is a flexible testing framework that supports simple unit tests as well as complex functional testing, making it essential for maintaining code quality in larger projects.
<code># test_capitalize.py
import pytest
def test_capital_case():
assert capital_case('semaphore') == 'Semaphore'
def test_raises_exception_on_non_string_arguments():
with pytest.raises(TypeError):
capital_case(9)
</code>While many other valuable Python packages exist, these ten cover the most common scenarios for general Python development.
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.