Top 10 Essential Python Packages Every Developer Should Know
This article presents a curated list of the ten most essential and widely used Python packages—including NumPy, Pendulum, Pillow, MoviePy, Requests, Tkinter, PyQt, Pandas, Pywin32, and Pytest—explaining their core functionalities, typical use cases, and providing practical code examples to help developers quickly adopt them in various projects.
1. NumPy
NumPy makes complex mathematical operations easy by providing multi‑dimensional arrays and a suite of numerical functions. It is fundamental for scientific computing and also underpins machine‑learning libraries such as TensorFlow.
<code>import numpy as np
a = np.arange(15).reshape(3, 5)
print(a)
print(a.shape)
print(a.ndim)
print(a.dtype.name)
print(a.itemsize)
print(a.size)
print(type(a))
b = np.array([6, 7, 8])
print(b)
print(type(b))</code>2. Pendulum
Pendulum is a drop‑in replacement for the built‑in datetime module, offering a more intuitive API and automatic timezone handling.
<code>import pendulum
now = pendulum.now("Europe/Paris")
now = now.in_timezone("America/Toronto")
print(now.to_iso8601_string())
now = now.add(days=2)
print(now)</code>3. Pillow (Python Imaging Library)
Pillow enables opening, manipulating, and saving images in many formats, making it the go‑to library for basic image processing tasks.
<code>from PIL import Image
im = Image.open("images/cuba.jpg")
im.show()
im = im.rotate(45)
im.show()</code>4. MoviePy
MoviePy provides high‑level functions for importing, editing, and exporting video files, such as adding titles or rotating clips.
<code>from skimage.filters import gaussian_filter
from moviepy.editor import VideoFileClip
def blur(image):
"""Return 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 simplifies HTTP communication with a clean, human‑readable API, handling query strings, POST data, 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 Python interface to the Tk GUI toolkit and is ideal for creating simple cross‑platform graphical applications.
<code>from tkinter import *
window = Tk()
window.title("Welcome to LikeGeeks app")
window.mainloop()
</code>7. PyQt
PyQt provides bindings to the Qt framework, offering a richer set of widgets for building more complex, native‑looking desktop applications.
(Code example omitted for brevity.)
8. Pandas
Pandas is the premier library for data manipulation and analysis in Python, allowing easy handling of time‑series data, statistical operations, and CSV/Excel I/O.
<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 gives Python access to many Windows APIs, enabling tasks such as registry manipulation, COM automation, and controlling Office applications.
<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 powerful 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>These ten packages form a solid foundation for general‑purpose Python development, covering numerical computing, date‑time handling, image/video processing, HTTP requests, GUI creation, Windows automation, data analysis, and testing.
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.