Search code examples
pythonpackaging

What are the caveats of namespace packages


Here in Packaging namespace packages, it is mentioned that

namespace packages can be useful for a large collection of loosely-related packages (such as a large corpus of client libraries for multiple products from a single company). However, namespace packages come with several caveats and are not appropriate in all cases. A simple alternative is to use a prefix on all of your distributions such as import mynamespace_subpackage_a (you could even use import mynamespace_subpackage_a as subpackage_a to keep the import object short).

But there are no examples. It is better to use the alternative?


Solution

  • there are no examples.

    The documentation refers to this example:

    https://github.com/pypa/sample-namespace-packages/tree/master/native

    The documentation was written prior to the sunsetting of python2. Designing a solution that supports both {2,3} would involve several caveats.

    tl;dr: Given that you now should be targeting python3, and 3.3+ at that, then using namespace packages makes perfect sense. (Current released interpreter is 3.11.)