Will Hardy Will Hardy -4 years ago 107
Python Question

packaging common python namespaces

I'm looking to package and upload a library I have to PyPI in the next few days, but I'm a little unsure about my approach to the namespace.

I have a few otherwise unrelated projects with a similar approach and wanted to give them all the same namespace. For example:

  • Library 1 namespace:

  • Library 2 namespace:

  • Library 3 namespace:

  • etc

The problem is that I'm not sure if it's possible for two separate packages (eg eggs) to co-exist with the same parent namespace. Is this approach problematic, or is there a way around it? What's the best approach?

The libraries should not be packaged together, they are too unrelated. I would like to get it right before uploading so as to avoid painful namespace changes after making an "official" release.

is not the real name, I wanted my question to be free from advertising)


I went with the following, to be nice to the people without setuptools installed:

except ImportError:
__path__ = __import__('pkgutil').extend_path(__path__, __name__)

With the following in

namespace_packages = ['rollyourown'],

Answer Source

In each project base directory, create the following structure:


/abc/__init__.py contains :


setup.py contains :

    packages: ['abc', 'abc.seo'],
    namespace_packages = ['abc']

Reference documentation: namespace packages.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download