Python – Packages

What is Package: Python modules may contain several classes, functions, variables, etc. whereas Python packages contain several modules. In simpler terms, Package in Python is a folder that contains various modules as files.

Python has a vast ecosystem of third-party packages and libraries that extend its functionality for various purposes.

Here are some commonly used Python packages across different domains:

We organize a large number of files in different folders and subfolders based on some criteria, so that we can
find and manage them easily. In the same way, a package in Python takes the concept of the modular approach to
next logical level. As you know, a module can contain multiple objects, such as classes, functions, etc.

A package can contain one or more relevant modules. Physically, a package is actually a folder containing one or more module files.

Let’s create a package named mypackage, using the following steps:

Create a new folder named D:\MyApp.
Inside MyApp, create a subfolder with the name ‘mypackage’.
Create an empty file in the mypackage folder.
Using a Python-aware editor like IDLE, create modules and with the following code:

def SayHello(name):
print(“Hello “, name)
def sum(x,y):
return x+y

def average(x,y):
return (x+y)/2

def power(x,y):
return x**y

That’s it. We have created our package called mypackage. The following is a folder structure:

Install a Package Globally:

Once a package is created, it can be installed for system-wide use by running the setup script. The script calls setup() function from the setuptools module.

Let’s install mypackage for system-wide use by running a setup script.

Save the following code as in the parent folder MyApp. The script calls the setup() function from the setuptools module. The setup() function takes various arguments such as name, version, author, list of dependencies, etc. The zip_safe argument defines whether the package is installed in compressed mode or regular mode.


from setuptools import setup
description=’Testing installation of Package’,

Python training in hyderabad


Enquiry Now
close slider
Scroll to Top
Call Now Button