This chapter introduced Python’s package import model—an optional but useful way to explicitly list part of the directory path leading up to your modules. Package imports are still relative to a directory on your module import search path, but your script gives the rest of the path to the module explicitly.
As we’ve seen, packages not only make imports more meaningful in larger systems, but also simplify import search path settings if all cross-directory imports are relative to a common root directory, and resolve ambiguities when there is more than one module of the same name—including the name of the enclosing directory in a package import helps distinguish between them.
Because it’s relevant only to code in packages, we also explored the newer relative import model here—a way for imports in package files to select modules in the same package explicitly using leading dots in a from, instead of relying on an older and error-prone implicit package search rule. Finally, we surveyed Python 3.3 namespace packages, which allow a logical package to span multiple physical directories as a fallback option of import searches, and remove the initialization file requirements of the prior model.
In the next chapter, we will survey a handful of more advanced module-related topics, such as the __name__ usage mode variable and name-string imports. As usual, though, let’s close out this chapter first with a short quiz to review what you’ve learned here.