External Modules in Python
Last Updated :
27 Nov, 2023
Python is one of the most popular programming languages because of its vast collection of modules which make the work of developers easy and save time from writing the code for a particular task for their program. Python provides various types of modules which include built-in modules and external modules. In this article, we will learn about the external modules in Python and how to use them.
What are External Modules?
External modules are collections of pre-written code that offer additional functions, classes, or methods not available in Python's standard library. These modules usually cater to specific needs like web scraping, data analysis, or machine learning. Python's package manager, "pip", makes it exceedingly simple to install and manage these modules.
Advantages of Using External Modules
- Efficiency: Instead of writing code from scratch, you can leverage pre-built functionalities.
- Community Support: Many popular modules have vast communities, ensuring updates, bug fixes, and support.
- Standardization: Using common modules means adhering to widely accepted best practices.
List of Most Popular Python External Modules
Here's a list of some of the most popular external Python modules across various domains. Below are just a few of the most popular external modules available in the vast collection of Python packages. Depending on the domain and specific needs, there are countless other valuable packages available to Python developers.
1. Web Development:
- Django: A high-level web framework that encourages rapid development and clean, pragmatic design.
- Flask: A lightweight and flexible micro web framework.
2. Data Analysis and Manipulation:
- pandas: Provides high-performance, easy-to-use data structures and data analysis tools.
- numpy: Fundamental package for numerical computations in Python.
3. Machine Learning and Artificial Intelligence:
- scikit-learn: Machine learning library featuring various algorithms and tools.
- TensorFlow: Open-source machine learning framework developed by Google.
- PyTorch: An open-source deep learning platform by Facebook.
4. Data Visualization:
- matplotlib: Comprehensive library for creating static, animated, and interactive visualizations.
- seaborn: Data visualization library based on matplotlib; provides a higher-level interface for drawing attractive and informative statistical graphics.
5. Web Scraping:
- BeautifulSoup: Library for pulling data out of HTML and XML documents.
- Scrapy: An open-source and collaborative web crawling framework.
6. Networking and APIs:
- requests: Simplifies making HTTP requests.
- socket: Low-level networking interface.
7. Databases:
- SQLAlchemy: SQL toolkit and Object-Relational Mapping (ORM) library.
- sqlite3: Interface for SQLite databases.
8. Testing:
- pytest: A robust framework for writing and executing tests.
- unittest: (Part of the standard library) Unit testing framework.
9. GUI Development:
- tkinter: Standard GUI library for Python.
- PyQt: Set of Python bindings for the Qt application framework.
10. Scientific Computing:
- SciPy: Library used for high-level computations.
- SymPy: Python library for symbolic mathematics.
Examples of External Modules
Let's understand it by using code examples of two popular external Python modules.
Example 1: Using "requests" module in Python
The "requests" module simplifies the process of making HTTP requests in Python. We can install this module by executing the below command in terminal.
pip install requests
With just a few lines, we are able fetch, send, and handle HTTP requests and responses.
Python3
# Import request module
import requests
# store the response from an API in response
response = requests.get("https://api.github.com")
# Checking if the reponse status
if response.status_code == 200:
print("Successfully connected to GitHub API!")
else:
print("Failed to connect to GitHub API!")
Output:

Example 2: Using "pandas" module in Python
"pandas" is a powerful data manipulation and analysis tool for Python. Using "pandas", we can handle vast datasets, manipulate data structures, and perform complex data operations with ease. To install "pandas" module execute the below command in terminal.
pip install pandas
Below is a simple example showcasing reading a CSV file and displaying its first five rows:
Python3
# Import pandas module
import pandas as pd
# Read a CSV file
dataframe = pd.read_csv('datafile.csv')
# Display the first five rows
print(dataframe.head())
Ouput:

Example 3: Using "numpy" module in Python
Numpy library is used for numerical computing in Python. It provides support for large multi-dimensional arrays and matrices, along with a collection of mathematical functions to operate on these arrays. We can install this library by executing below command in our terminal.
pip install numpy
In the below code, we first import the numpy library and then create an one dimensional array using array() function after that we print the mean of all the elements in an array by using mean() function inside the print() function.
Python3
# Import numpy library
import numpy as np
# Create an array
arr = np.array([1, 2, 3, 4, 5,
6, 7, 8, 9, 10])
# Calculate the mean
print(np.mean(arr))
Output:

Example 4: Using "matplotlib" module in Python
Matplotlib is a plotting library that is used to visualize large datasets. It provides an object-oriented API to embed plots into applications using general-purpose GUI toolkits. To install "matplotlib" execute the below command in the terminal.
pip install matplotlib
In the below example, we draw a simple plot by using the sample data set.
Python3
# Import matplotlib module
import matplotlib.pyplot as plt
# Create a sample Data
x = [0, 1, 2, 3, 4]
y = [0, 1, 4, 9, 16]
# Create a plot
plt.plot(x, y)
# Show the plot
plt.show()
Output:

Example 5: Using "flask" module in Python
Flask is a lightweight framework for web development in Python. It's easy to use and allows for the rapid development of web applications. We can install flask by executing the below command in terminal.
pip install flask
In the below example, we have written the script to display the message "Hello, Flask!" on the webpage.
Python3
# import Flask from flask module
from flask import Flask
# Creating an instance of flask app
app = Flask(__name__)
# Defining a route
@app.route('/home')
def home():
return "Hello, Flask!"
# Run the application
if __name__ == '__main__':
app.run()
Output:

These are only the few examples of Python external modules. There are lot more external module available to perform various tasks according to our requirements. Whether we're developing a web application, analyzing data, or venturing into artificial intelligence, there's likely an external module available to make our tasks easy.
Similar Reads
Built-in Modules in Python
Python is one of the most popular programming languages because of its vast collection of modules which make the work of developers easy and save time from writing the code for a particular task for their program. Python provides various types of modules which include Python built-in modules and ext
9 min read
C Extension Module using Python
Writing a simple C extension module directly using Pythonâs extension API and no other tools. It is straightforward to make a handcrafted extension module for a simple C code. But first, we have to make sure that the C code has a proper header file. Code #1 : #include <math.h> extern int gcd(i
4 min read
Import module in Python
In Python, modules allow us to organize code into reusable files, making it easy to import and use functions, classes, and variables from other scripts. Importing a module in Python is similar to using #include in C/C++, providing access to pre-written code and built-in libraries. Pythonâs import st
3 min read
Create and Import modules in Python
In Python, a module is a self-contained Python file that contains Python statements and definitions, like a file named GFG.py, can be considered as a module named GFG which can be imported with the help of import statement. However, one might get confused about the difference between modules and pac
3 min read
How to create modules in Python 3 ?
Modules are simply python code having functions, classes, variables. Any python file with .py extension can be referenced as a module. Although there are some modules available through the python standard library which are installed through python installation, Other modules can be installed using t
4 min read
Python Module Index
Python has a vast ecosystem of modules and packages. These modules enable developers to perform a wide range of tasks without taking the headache of creating a custom module for them to perform a particular task. Whether we have to perform data analysis, set up a web server, or automate tasks, there
4 min read
Python Modules
Python Module is a file that contains built-in functions, classes,its and variables. There are many Python modules, each with its specific work. In this article, we will cover all about Python modules, such as How to create our own simple module, Import Python modules, From statements in Python, we
7 min read
Basics Of Python Modules
A library refers to a collection of modules that together cater to a specific type of needs or application. Module is a file(.py file) containing variables, class definitions statements, and functions related to a particular task. Python modules that come preloaded with Python are called standard li
3 min read
Python Fire Module
Python Fire is a library to create CLI applications. It can automatically generate command line Interfaces from any object in python. It is not limited to this, it is a good tool for debugging and development purposes. With the help of Fire, you can turn existing code into CLI. In this article, we w
3 min read
C API from Extension Module in Python | Set 2
Prerequisite: C API from Extension Module in Python | Set 1 Let's see an example of a new extension module that loads and uses these API functions that we build up in the previous article. Code #1 : #include "pythonsample.h" /* An extension function that uses the exported API */ static PyO
2 min read