Packages, modules, libraries,...

Adrian Eyre a.eyre at
Tue Feb 1 08:50:37 EST 2000

> I've seen the words package, module, and library, used in this group 
> frequently. I'm the naive type of programmer, so I thought that these
> were synonyms. Now, some people seem to use these words as such, but
> then there are others who seem to distinguish between them. What is
> true? Are perhaps both views true in some sense? Could someone please
> enlighten me.

I'm not sure about "library", but "package" and "module" are well
defined in Python.

Imagine the following filesystem structure:

/home/fred/python/	<- This is in the PYTHONPATH
                 +- cafe/
                 |      |
                 |      +-
                 |      |
                 |      +-

import spam             # Imports "module" from file[c]
import cafe             # Imports "package" from file cafe/[c]
import cafe.bacon       # Imports "module" from file cafe/[c]

Packages are really useful in that they allow you to easily create
arbitrarily nested namespaces in Python, whilst maintaing a easily
managed directory structure.

The presence of an in a directory constitutes a package,
although technically, a package is just a module:

>>> import spam
>>> spam
<module 'spam' from '/home/fred/python/'>
>>> import cafe
>>> cafe
<module 'cafe' from '/home/fred/python/cafe/'>
>>> import cafe.bacon
>>> cafe.bacon
<module 'cafe.bacon' from '/home/fred/python/cafe/'>

Adrian Eyre <a.eyre at> - 

More information about the Python-list mailing list