Introduction
In programming, a package is a directory or folder containing a collection of modules. These modules can be seen as files or documents contained collectively in a folder called package. Packages are a bundled collection of modules in python serving a specific purpose. An example we can use to explain further is a library and how it works. We can think of this collection of packages like a traditional real world library. Each package is a book or magazine and this library gets bigger everyday. In python, there are currently 10’s of 10,000 of packages to choose from.
Importing Packages
You import packages the same way you import modules, using import statements. However, in the case of packages, you have to use the keywords “import from”. Let’s take a look at this example:
Let’s say you want to import a package “foo”.
import foo
Now the code above wont work unless you make use of the keyword “import from” to specifically mention the module you want to use from the package “foo” . The code below shows how the code should be written:
from foo import a
where “foo” is the package and “a” is the module we want to get from the package.
PIP and PyPI
Exploring the packages directory structure or referring to code blocks online can save time. To work with packages in python, it’s important to know that PIP is it’s default package manager and PyPI(Python Package Index) is the package index where you can find unpublished packages.
Python’s extensive collection of packages
Python has an extensive collection of packages. As a developer starting out, it can be overwhelming but understanding what python is most widely used for today first can help. Therefore, the major application areas of python are:
- Data Science
- AI and Machine Learning
- Web Frameworks
- Application Development
- Automation
- Hardware Interfacing
With this in mind, packages can be grouped into the following categories:
- Built-in Packages
- Data Science
- Machine Learning and AI
- Web and GUI Development
We shall now explore each of these categories in details briefly.
Built-in Packages
These are packages that do not need to be installed separately. They can be used as soon as you have installed python on your system. Almost every project uses one or more of this built-in packages and as a developer, it is of great advantage to you if you know them well. The most popular ones are OS, SYS, CSV, JSON, importlib, remath and intertools.
Data Science
In the world of data science, the most popular python packages are Numpy, Scipy, NLTK and pandas. They are used for data exploration and manipulation. Other packages like openCV and matplotlib are used for image processing and data visualisation.
Machine Learning and Artificial Intelligence
Within the world of ML and AI, the most popular packages are tensorflow, PyTorch and keras. PyTorch and keras are the most popular for deep learning and neuro network implementation. There are also other packages such as Scipy, Scikit-Learn and Theano.
Web and GUI Development
The most popular packages are FLASK(a lightweight microframe work ) and Django(a full stack framework). Other popular web development packages include cherry pie, pyramid, beautiful, soup and selenium.
As a developer, choosing what package to use will depend on the scale and scope of the project and how familiar you become with the package in question. But as a beginner though in using python code, most functions you will need can be met by one package so on the long run, there may be little need for you to learn more than you can handle. In conclusion, python has a wide range of packages which can be used for various fields and also provides a level of diversity for us as developers.