Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags


What are Python packages?

Educative Answers Team

A python package is a collection of modules. Modules that are related to each other are mainly put in the same package. When a module from an external package is required in a program, that package can be imported and its modules can be put to use.

Any Python file, whose name is the module’s name property without the .py extension, is a module.

A package is a directory of Python modules that contains an additional file, which distinguishes a package from a directory that is supposed to contain multiple Python scripts. Packages can be nested to multiple depths if each corresponding directory contains its own file.

svg viewer

When you import a module or a package, the object created by Python is always of type module.

When you import a package, only the methods and the classes in the file of that package are directly visible.


For example, let’s take the datetime module, which has a submodule called date. When datetime is imported, it’ll result in an error, as shown below:

import datetime

The correct way to use the date module is shown below:

from datetime import date


Copyright ©2022 Educative, Inc. All rights reserved

View all Courses

Keep Exploring