Python provides ecosystem of standard library modules and third-party packages that simplify common programming tasks. From clipboard management and emoji support to web scraping, GUI development, and desktop automation, these modules extend Python's capabilities and make development more efficient.
Installation
Some of the modules covered in this article are included with Python's standard library, while others must be installed separately before they can be used. Install the required third-party modules using the following command:
pip install pyperclip emoji wikipedia
Also, Modules such as sys, urllib, dis, turtle, and antigravity are part of Python's standard library and do not require installation.
Comparison Table
| Module | Purpose |
|---|---|
| pyperclip | Clipboard operations |
| emoji | Display and convert emojis |
| wikipedia | Access Wikipedia articles |
| dis | Disassemble Python bytecode |
| urllib | Work with URLs |
| turtle | Graphics and drawing |
| antigravity | Python Easter egg |
| sys | System-specific functions |
types (or type()) | Dynamic type creation |
Pyperclip
The pyperclip module provides cross-platform clipboard functionality. It allows Python programs to copy text to the system clipboard and retrieve text currently stored in the clipboard.
import pyperclip
# Copy text to the clipboard
pyperclip.copy("Hello, World!")
# Retrieve text from the clipboard
text = pyperclip.paste()
print(text)
Output
Hello, World!
Explanation:
- pyperclip.copy() copies the specified text to the system clipboard.
- pyperclip.paste() retrieves the current clipboard contents.
- This module is useful for automating copy-paste operations and transferring text between applications.
Working with Emojis
The emoji module allows Python programs to convert emoji aliases into Unicode emojis and work with emoji characters in strings. It is commonly used in chat applications, social media tools, and text-processing programs.
import emoji
text = emoji.emojize(
"Python is awesome! :thumbs_up:",
language="alias"
)
print(text)
Output
Python is awesome! 👍
Explanation:
- import emoji imports the emoji module.
- emoji.emojize() converts emoji aliases into their corresponding Unicode emoji characters.
- The language="alias" parameter enables the use of common emoji aliases such as :thumbs_up:.
Note: You can find the complete list of supported emoji aliases in the official emoji documentation.
Wikipedia
The wikipedia module provides an interface to search Wikipedia and retrieve article summaries or complete page information directly from Python.
import wikipedia
summary = wikipedia.summary("Python (programming language)", sentences=2)
print(summary)
Output
Python is a high-level, interpreted programming language...
Explanation:
- wikipedia.summary() retrieves a summary of the specified article.
- The sentences parameter limits the number of sentences returned.
- This module is useful for fetching concise information from Wikipedia.
Note: If multiple articles match the search term, the module may raise a DisambiguationError. If no matching article is found, it raises a PageError.
Creating Dynamic Classes Using type()
This can create new types in a fully dynamic way. It's the same as creating a class but something new which you can show to your friends.
# Python program to
# create new type object
# Creates a new type object
NewType = type("NewType", (object, ), {"attr": "hello newtype"})
New = NewType()
# Print the type of object
print(type(New))
# Print the attribute of object
print(New.attr)
Output:
<class '__main__.NewType'>
hello newtype
The above code is same as:
# Creates a class
class NewType:
attr = "hello newtype"
# Initialize an object
New = NewType()
# Print the type of object
print(type(New))
# Print the attribute of object
print(New.attr)
Output:
<class '__main__.NewType'>
hello newtype
Probably not the best module but still worth a try!
Disassembling Python Bytecode
The dis module is part of Python's standard library and is used to disassemble Python bytecode. It helps developers understand how Python compiles source code into bytecode, making it useful for debugging, learning, and performance analysis.
import dis
def duplicate(number):
return str(number) + str(number)
def greet(name):
print("Hello", name)
# Display the bytecode for the functions
dis.dis(duplicate)
print()
dis.dis(greet)
Output
5 0 LOAD_GLOBAL 0 (str)
2 LOAD_FAST 0 (number)
...
18 BINARY_OP 0 (+)
22 RETURN_VALUE
8 0 LOAD_GLOBAL 0 (print)
...
20 RETURN_VALUE
Explanation:
- import dis imports the dis module.
- dis.dis() disassembles a function and displays the corresponding Python bytecode instructions.
- The output shows how Python executes the function internally using bytecode operations such as loading variables, calling functions, and returning values.
- The dis module is commonly used for debugging, understanding Python's execution model, and analyzing code behavior.
Note: The exact bytecode instructions may vary depending on the Python version.
Python's antigravity Easter Egg
antigravity is a fun Easter egg included in Python's standard library. Importing this module opens the famous XKCD comic "Python" in your default web browser.
import antigravity
Output
The default web browser opens the XKCD comic related to Python.
Explanation:
- antigravity is part of Python's standard library and does not require installation.
- Importing the module automatically opens the XKCD comic in your default browser.
- It is intended as a fun Easter egg rather than a utility module.
Exiting a Program Using sys.exit()
The sys module provides access to system-specific functionality. The sys.exit() function terminates the current Python program immediately.
import sys
while True:
response = input("Type 'exit' to quit: ")
if response.lower() == "exit":
print("Exiting the program...")
sys.exit()
print("You entered:", response)
Output
Type 'exit' to quit: Python
You entered: Python
Type 'exit' to quit: exit
Exiting the program...
Explanation:
- import sys imports the sys module.
- sys.exit() immediately terminates program execution.
- It is commonly used to exit a program when a specific condition is met.
Working with URLs Using urllib
The urllib package provides modules for working with URLs. It can retrieve web pages, parse URLs, handle HTTP errors, and process robot exclusion files. Urllib is a package that collects several modules for working with URLs, such as:
from urllib.request import urlopen
response = urlopen("https://www.geeksforgeeks.org")
print(response.status)
print(response.headers["Content-Type"])
Output
200
text/html; charset=UTF-8
Explanation:
- urlopen() sends an HTTP request and returns a response object.
- status returns the HTTP status code.
- headers provides access to the response headers.
- urllib is commonly used for retrieving web resources programmatically.
Reading the Contents of a Web Page
The response returned by urlopen() can also be used to read the contents of a web page.
from urllib.request import urlopen
response = urlopen("https://www.geeksforgeeks.org")
content = response.read().decode("utf-8")
print(content[:300])
Output

Explanation:
- read() returns the page contents as bytes.
- decode("utf-8") converts the bytes into a readable string.
- Printing only a portion of the content makes the output easier to inspect.
Drawing Graphics Using turtle
The turtle module is part of Python's standard library and is commonly used to introduce graphics programming. It provides simple commands for drawing shapes and patterns by moving a virtual turtle across the screen.
import turtle
pen = turtle.Turtle()
length = 100
while length > 0:
pen.forward(length)
pen.right(90)
length -= 10
turtle.done()
Output

Explanation:
- turtle.Turtle() creates a turtle object used for drawing.
- forward() moves the turtle forward while drawing a line.
- right() rotates the turtle clockwise.
- The loop gradually decreases the line length, producing a spiral.
- turtle.done() keeps the graphics window open until it is closed.
Note: The original recursive implementation can eventually exceed Python's recursion limit. An iterative approach using a while loop is simpler and avoids recursion-related issues.