Python Package

    What is Python Package? In this tutorial, we will discuss what are Python Packages and how to use them in detail. So let us get started!

    What are Packages?

    On our computer, we have disks in which we can store files and that file could be anything videos, songs, word files, notepad files, pictures, etc. But instead of saving all the files altogether, we make folders for different files, for example, we save all the videos in the videos folder and all the songs inside the songs folder.

    We create folders because with the help of folders we can gather a group of files having the same extension and it also helps us to access them easily. So, in python when we work on a big project, we create such folders or directories in which we store our modules (.py file), and those folders or directories in python are known as packages.

    A package could have modules or sub-folders which are also known as sub-packages. And, every package or sub-package we create for modules should have an file then only the folder or directory will be considered as a python package, and most of the time the _ file is empty.

    Let’s understand it with an example:

    Project1 (Package) (module)
        Project_1_0 (sub-package)

    Importing module from packages and sub-packages

    With the help of the dot (.) operator, we can import different modules from packages.

    Let’s understand it with an example:

    import Project1.Project_1_0.Module1_0_1
    # or you could also write it as
    from Project1.Project_1_0 import Module1_0_1

    Third-Party Packages

    Python is rich with third-party Packages these are the packages that you can download from the internet with the help of the browser or you can just use python-pip install package_name in your command prompt it will install it. Some of the most famous 3 rd party packages are Numpy, orange, Django , Flask , etc.