-2

What is the list of main criteria or properties for being a module in Python? Also, what is the list of main criteria or properties for being a package in Python? Additionally, what is the list of main criteria or properties for being a library in Python? Additionally, what is the list of main criteria or properties for being a framework in Python?

How are they interrelated to one another?

Also, a List of similarities and differences would help.

And in the case of TensorFlow what is its list of properties that make it:

  • a module
  • a package
  • a library
  • a framework?

Please answer all these queries with examples

desertnaut
  • 57,590
  • 26
  • 140
  • 166

1 Answers1

0

Similar questions have already been raised and answered in What's the difference between a module and a library in Python? and What's the difference between a module and package in Python?

In short, only Package and Module actually have defined meanings in Python. From the Python Glossary:

Module

An object that serves as an organizational unit of Python code. Modules have a namespace containing arbitrary Python objects. Modules are loaded into Python by the process of importing. See also package.

In other words, anything you import from is a module.

  • import sys - sys is the module
  • from math import floor - math is the module
  • from tensorflow.keras.layers import Dense, Flatten, Conv2D - tensorflow.keras.layers is the module.
  • If I write two scripts foo.py and bar.py and foo.py has the line import bar, then bar is a module.
  • If you invoke a foo.py file with python -m foo.py, then Python will load foo.py as a module, meaning that __name__ == "__main__" will be false when foo.py is loaded.

Package

A Python module which can contain submodules or recursively, subpackages. Technically, a package is a Python module with a __path__ attribute. See also regular package and namespace package.

Regular Package

A traditional package, such as a directory containing an __init__.py file.

Namespace Package -- Added in Python 3.3

A PEP 420 package which serves only as a container for subpackages. Namespace packages may have no physical representation, and specifically are not like a regular package because they have no __init__.py file.

Packages are collections of related modules with a directory hierarchy. Anything you install using pip or conda or any other package manager is a package, although it may be a collection of modules or a single module. You can make your own local packages as well.

Library is not a special term defined in the Python glossary, but in programming a library is a general term for any reusable code. The built-in modules of Python are often referred to as the Standard Library, but its not a reserved term. Library is often used interchangeably with Package. It feels like some Python users tend to use Library more often when referring to packages built in C such as scipy and numpy.

Framework is also not a defined term in the Python glossary, but generally refers to a collection of packages and modules which provide an abstraction layer for developers to create complex applications without having to reinvent the basic elements every time. The distinction between library and framework is a bit nebulous, but we could generally say a library is targeting a specific functionality while a framework tries to provide everything needed for a full application, and may include several libraries. Examples:

nigh_anxiety
  • 1,428
  • 2
  • 4
  • 12
  • 1
    Frameworks aren’t limited to being related to the web. – deceze Jul 07 '23 at 05:30
  • @deceze - Expanded that section. It was admittedly sloppy. Web apps came to mind first as the line between library vs framework isn't always clear, and searching for "python frameworks" seems to default to all the web application frameworks. – nigh_anxiety Jul 07 '23 at 06:43