16

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: abc.seo
  • Library 2 namespace: abc.ajax
  • Library 3 namespace: abc.ecommerce
  • 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.

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

UPDATE

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

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

With the following in setup.py:

setup(
 ...
 namespace_packages = ['rollyourown'],
 ...
asked Feb 21, 2011 at 10:41
3
  • 1
    Have you looked at the various eGenix mx packages on PyPi? Look at those for examples. Then you can ask more specific questions based on that pattern. Commented Feb 21, 2011 at 10:53
  • So you mean to say it's not problematic for a user to install two separate packages with the same parent namespace? This will never cause any issues? The mx packages appear to have a very complicated installation process, I'll try my best to see if they have any special workarounds for namespace issues. Commented Feb 21, 2011 at 11:14
  • 1
    Your "update" is in fact an answer, rather than an update of your question. I'd move it to be an answer, so we can vote on it :) Commented Mar 2, 2013 at 0:04

1 Answer 1

16

In each project base directory, create the following structure:

/setup.py
/abc/__init__.py
/abc/seo/

/abc/__init__.py contains :

__import__('pkg_resources').declare_namespace(__name__)

setup.py contains :

setup(...,
 packages: ['abc', 'abc.seo'],
 namespace_packages = ['abc']
 ...
)

Reference documentation: namespace packages.

TimStaley
5354 silver badges21 bronze badges
answered Feb 21, 2011 at 11:24
Sign up to request clarification or add additional context in comments.

1 Comment

Wonderful! This sounds like it solves the technical problem completely. Thanks!

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.