Python package name conventions Python package name conventions python python

Python package name conventions


Python has two "mantras" that cover this topic:

Explicit is better than implicit.

and

Namespaces are one honking great idea -- let's do more of those!

There is a convention for naming of and importing of modules that can be found in The Python Style Guide (PEP 8).

The biggest reason that there is no such convention to consistently prefix your modules names in a Java style, is because over time you end up with a lot of repetition in your code that doesn't really need to be there.

One of the problems with Java is it forces you to repeat yourself, constantly. There's a lot of boilerplate that goes into Java code that just isn't necessary in Python. (Getters/setters being a prime example of that.)

Namespaces aren't so much of a problem in Python because you are able to give modules an alias upon import. Such as:

import com.company.actualpackage as shortername

So you're not only able to create or manipulate the namespace within your programs, but are able to create your own keystroke-saving aliases as well.


The Java's conventions also has its own drawbacks. Not every opensource package has a stable website behind it. What should a maintainer do if his website changes? Also, using this scheme package names become long and hard to remember. Finally, the name of the package should represent the purpose of the package, not its owner


An update for anyone else who comes looking for this:

As of 2012, PEP 423 addresses this. PEP 8 touches on the topic briefly, but only to say: all lowercase or underscores.

The gist of it: pick memorable, meaningful names that aren't already used on PyPI.