Modules vs Packages vs Libraries vs Frameworks
Table of Contents
A Python module is just a python file with a .py extension. It can contain variables or functions – elements that can be referred from another python file using an import.
For example, let’s create a simple python file – user.py in a directory.
It just has a variable name and a function nameCapitalize(name). These can be referenced in another file using the standard import process that we already know.
Say, we create another file test.py and then import user.py using
That’s it, the variable name inside the user.py module can be referenced using the familiar dot (.) notation.
You can even reference the functions inside the referenced module.
A python package is just a collection of Python files (or modules). Earlier, we were able to import a specific python file. Now, we have created a folder called customers and inside it created another python file(or module) called customer.py.
You can have any levels of hierarchy inside a package using folders for nesting python modules.
A python library is a collection of python packages. The python standard library for example is a collection of Python Packages. Theoritically, there is no difference between a Python Module and Python Package. Typically python library is a collection of modules or packages. For example, you can view the requests library here
A framework is a collection of python libraries. Some examples of popular python frameworks are
- django – used to build web apps
- flask – used to build APIs
- FastAPI – used to build APIs