Blog Layout

Python Start • March 4, 2017

The list of Python Packages is Massive

Python's geometric rise is due, at least in part, to a tremendous list of packages

Python has experienced tremendous recent adoption for at least 5 reasons. One of those reasons is the vast set of available Python packages.

What is a Python Module?

In order to understand Python packages, it's helpful to first understand Python modules. Modules are individual Python files that can be imported and interpreted at run-time. For example, you could create a file named log_search.py in the current directory and then import the module using the import command. You can then access the log_search functions from your main application module. We'll dive into modules and functions in more detail, but for now think of a module as a collection of definitions and statements that comprise a set of related capabilities. Each function within a module is accessed using the module name, followed by a period (.) like this:

import log_search
log_search.find("pythonstart.com")

What is a Python Package?

A package is a collection of Python modules. This lets you organize even larger sets of capabilities into a single package. For example, perhaps you want to create an log_analysis package that includes many different sets of capabilities, and perhaps it will grow over time. Within this package, you want to include a set of functions that let users search log files (log_search) and a set of functions to append, split, and save log files, which you'll call (log_file_ops). Each module is a file that sits within a log_analysis folder. You can even nest packages, so that you can include multiple packages in a single web_ops package. To do this, you simply create a top-level folder named web_ops, add the log_analysis folder and create sibling folders such as web_server. Below is a view of the folder structure:

web_ops/                              Top-level package
__init__.py                    Initialize the web_ops package
web_server/                 Subpackage for web server functionality      
__init__.py           Initialize the web_server package
deploy.py             Functions to deploy your web server
start.py                Functions to start your web server
log_analysis/               Subpackage for log analysis functionality
__init__.py         Initialize the log_analysis package
log_search.py    Functions to search your logs
log_file_ops.py   Functions to modify your log files

Popular Python Packages

Regular expressions
By Python Start June 28, 2020
Learn how to use regular expressions in Python to help sift through large amounts of text input. In this blog post, we will show you the process step-by-step by extracting story passages from an HTML file.
Linear programming has been effectively used in hospitals to solve nursing staff scheduling problems
By Python Start June 22, 2020
See how to solve a staffing problem with PuLP, a linear programming toolkit for Python. In this post, we consider a hospital nursing staff scheduling problem.
Python
By Python Start February 25, 2017
Python is becoming a popular programming language, and here are 7 examples to prove it
Share by: