University of Sunderland
MSc Digital & Technology Solutions CESTM65 Software Engineering Principles
How to Create a Python Package
A python package is a collection of modules that are grouped together that work with one another for a
specific purpose. An example of a Package is PyGame which involves a series of modules that deal with
graphics and games design, or mys-math 0.7.0 which deals with mathematical equations.
Packages help structure the different modules use through the use of ‘dotted module names’. I.e.
[Link] where NameA is the name of the package and NameB is the name of the sub-module. For
example, in a package named PyCars we have a module named [Link]. The full path of the module is
now [Link]. A major advantage of using the approach to naming modules and packages is that
such a method enable multiple authors to work on a package without them needing to worry about the
specific module names they each use.
([Link] 23/10/2020)
Packages also allow you to go to deeper levels. For example, we could have a package named Vehicles, with
modules dedicated for Cars, and another set of modules dedicated for Boats. In effect, Cars and Boats are sub-
packages of Vehicles. To use the Emissions as an example: [Link] is the full name for the
Emissions module.
The following steps are designed to assist you with creating a Python Package:
1) You should have a top level directory for your package. To use the above example: Vehicles
2) Inside this, on older versions of Python, a __init__.py module was required. However, with newer
versions of Python (3.0 and up), this is no longer needed.
3) The next directory level should be groupings of modules with a common link. Using our example: Cars
and Boats
4) Inside each of these sub-directories should be the modules required for each. i.e. [Link] or
[Link]
Submitted by: Paul Jones
Student Number: bh83dq 23/10/2020