Python: Module vs Package vs Library vs Framework

Module is a file which contains various Python functions and global variables. It is simply just .py extension file which has python executable code.

Package is a collection of modules. It must contains an __init__.py file as a flag so that the python interpreter processes it as such. The __init__.py could be an empty file without causing issues.

Library is a collection of packages.

Framework is a collection of libraries. This is the architecture of the program.

Application is an application. Yah, I’m sure about this one.

10 thoughts on “Python: Module vs Package vs Library vs Framework”

    1. Libraries:
      1. Apache Libcloud: accessing multiple cloud providers through a single, consistent, unified API
      2. Invoke: executing scripts on remote machines

      Frameworks:
      1. Django: open-source full-stack Python web framework.
      2. Bottle: to build lightweight and fast web apps. This is in the grey area between microframeworks and libraries

    2. Use django as an example
      Django is a web framework which has libraries
      Each library has a set of reusable packages
      Each package has modules in them
      Look up the django Web framework Sanchit đź‘Ť

  1. F.W>library>package>Module
    Ok i think i got it now
    Thanks for the help

    Question : can a application contain many frameworks ? Example of app and frameworks!

    1. The quick answer is ‘yes’, you may combine 2 or more frameworks to create an application, especially the frameworks are complimentary. In practice, frameworks often overlap in some properties/functions of their libraries. Thus, combining multiple frameworks can lead to unexpected clobbering.

  2. Great. But aside from a hierarchy, what differentiates these? If I give you a folder with a bunch of folders with some python files is that a library or a package or an application or nothing? Does a setup.py go everywhere? What about using a package or a library in another project? How does an application use a library, a module, a package? Copy the folders?

    Bottom line, can you add to defining the hierarchy:

    What defines an Application and how do you use it?
    What defines a Library and how do you use it?
    What defines a Package and how do you use it?
    What defines a Module and how do you use it?

    It would be extremely helpful for anybody who ends up on this page like me looking for actionable knowledge.

    Thanks!

    1. Hi James,

      Thanks for your comment. Although my day job doesn’t enable me to use Python very much, I’d like to follow your advise and add a few more words to this post:

      1. What defines an Application and how do you use it?
      – An application is a set of codes that performs specific tasks for a user. Depending on the application (app), its UI could be via command line interface (CLI) or graphical user interface (GUI). An example of a CLI app is the Windows Command console. Likewise, GUI apps are Microsoft Word, Excel, Firefox, and Google Chrome.
      2. What defines a Library and how do you use it?
      – “A software library is a suite of data and programming code that is used to develop software programs and applications. It is designed to assist both the programmer and the programming language compiler in building and executing software” ~ techopedia
      3. What defines a Package and how do you use it?
      – A software package is punch of files glued together by ‘include’ statements. Often, we use a package management system (PMS), such as rpm/YUM/Apt (Linux), or MSI (Windows) to automate the installation of software packages. Examples are a MS Office Installation package and an openOffice rpm file.
      4. What defines a Module and how do you use it?
      – A module is a number of distinct but interrelated units of codes from which a program would be built. Coders often perform ‘unit testing’ by analyzing each module at a time to manage complexities.

Leave a Reply

Your email address will not be published. Required fields are marked *