An Introduction to Python Packages

Profile picture for user devanshi.srivastava
Submitted by devanshi.srivastava on

In Python, we have modules for files and packages for directories. It is a hierarchical file directory structure that defines a single Python application environment that consists of modules and sub-packages and sub-sub-packages, and so on.

Packages are a way of structuring many packages and modules which helps in a well-organized hierarchy of data set, making the directories and modules easy to access.

A package can contain one or more relevant modules. It is actually a folder containing one or more module files. It is basically a directory with Python files and a file with the name This means that every directory inside of the Python path, which contains a file named, will be treated as a package by Python. It's possible to put several modules into a Package.

Importing module from a package:

In Python, We can import packages using import keyword .


import math

Another way of importing just the required function (or class or variable) from a module within a package would be as follows:


from math import pi

While importing packages, Python looks in the list of directories defined in sys.path, similar as for module search path.