Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Whenever I do from 'x' import 'y' I was wondering which one is considered the 'module' and which is the 'package', and why it isn't the other way around?

share|improve this question
Regarding why it's the not the other way around, see… – delnan Oct 1 '11 at 23:40
The Python documentation provide formal, precise and complete definitions of both terms. and What part of these was confusing? Please update your question to explain how the standard definitions in the documentation didn't help you. If you don't want to clarify your question, though, that's okay, too. – S.Lott Oct 2 '11 at 0:28
up vote 108 down vote accepted

A Python module is simply a Python source file, which can expose classes, functions and global variables.

When imported from another Python source file, the file name is treated as a namespace.

A Python package is simply a directory of Python module(s).

For example, imagine the following directory tree in /usr/lib/python/site-packages:

mypackage/ <-- this is what tells Python to treat this directory as a package

So then you would do:

import mypackage.mymodule


from mypackage.mymodule import myclass
share|improve this answer
Aha, so when you say that the file name is treated as a namespace, you would so something like this? "mymodule.var1" for the first case, or "myclass.var1" for the second? – Dark Templar Oct 2 '11 at 4:08
Not exactly. The package still counts as part of the namespace. If you want to do what you said then you need to do from mypackage import mymodule. – Yam Marcovic Oct 2 '11 at 10:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.