How to Create a Python Package

Python packages are very easy to create, but not so easy to design. A Python package is just a group of files (and possibly subfolders) stored in a directory that includes a file named

To create a package in Python:

  1. Create a new folder.
  2. Add a file to the folder. It does not need to contain any code. For example, the file within Lib/idlelib (the package for the IDLE editor) looks like this:
    # Dummy file to make this a package.
  3. You can include code in the file that will initialize the package.
  4. You can also (but do not have to) set a global __all__ variable, which should contain a list of files to be imported when a file imports your package using
    from package_name import *
    If you do not set the __all__ variable, then that form of import will not be allowed, which may be just fine.

As you see, the steps involved in creating modules and packages for import is relatively straightforward. However, designing useful and easy-to-use modules and packages takes a lot of planning and thought.

Author: Nat Dunn

Nat Dunn is the founder of Webucator (, a company that has provided training for tens of thousands of students from thousands of organizations. Nat started the company in 2003 to combine his passion for technical training with his business expertise, and to help companies benefit from both. His previous experience was in sales, business and technical training, and management. Nat has an MBA from Harvard Business School and a BA in International Relations from Pomona College.

Follow Nat on Twitter at @natdunn and Webucator at @webucator.

About Webucator

Webucator provides instructor-led training to students throughout the US and Canada. We have trained over 90,000 students from over 16,000 organizations on technologies such as Microsoft ASP.NET, Microsoft Office, Azure, Windows, Java, Adobe, Python, SQL, JavaScript, Angular and much more. Check out our complete course catalog.