Comprehensive List of Python Modules and Packages
1. Introduction to Modules and Packages
Python modules are individual files containing functions and variables.
Packages are directories containing multiple modules, making it easier to organize large projects.
2. Built-in Modules (Standard Library)
These modules are included in Python by default and do not require installation.
- os: Interact with the operating system.
- sys: System-specific parameters and functions.
- math: Mathematical functions like sqrt, sin, cos.
- datetime: Date and time manipulation.
- random: Generate random numbers.
- json: Encode and decode JSON data.
- re: Regular expressions for pattern matching.
- collections: Specialized data structures like deque, defaultdict.
- itertools: Advanced iteration tools.
- functools: Functional programming tools.
3. External Modules (Third-Party Libraries)
These libraries are widely used but must be installed using pip.
- numpy: Numerical computations and arrays.
- pandas: Data analysis and manipulation.
- matplotlib: Data visualization with charts and graphs.
- seaborn: Statistical data visualization.
- requests: HTTP requests handling.
- flask: Lightweight web framework.
- django: Full-stack web framework.
- tensorflow: Machine learning and AI.
- scikit-learn: Data science and ML.
- opencv: Computer vision tasks.
4. Creating and Importing Custom Modules
You can create your own module by saving Python functions in a .py file.
Example:
# mymodule.py
def greet(name):
return f"Hello, {name}!"
Importing:
import mymodule
print(mymodule.greet("Alice"))
5. Package Management with pip and virtual environments
Use pip to install and manage packages:
pip install package_name
Virtual environments help manage dependencies for different projects:
python -m venv myenv
source myenv/bin/activate (Linux/Mac)
myenv\Scripts\activate (Windows)