public
Description: Create composite Python namespace packages
Homepage: http://github.com/davisp/namespace
Clone URL: git://github.com/davisp/namespace.git
Paul J. Davis (author)
Sat Jul 04 19:43:22 -0700 2009
name age message
file .gitignore Sat Jul 04 19:19:47 -0700 2009 Initial commit. Basic idea works. [Paul J. Davis]
file MANIFEST Sat Jul 04 19:19:47 -0700 2009 Initial commit. Basic idea works. [Paul J. Davis]
file README.md Sat Jul 04 19:26:54 -0700 2009 Copy docs to README.md [Paul J. Davis]
file namespace.py Sat Jul 04 19:43:22 -0700 2009 Minor nits. [Paul J. Davis]
file setup.py Sat Jul 04 19:42:25 -0700 2009 Docs and setup.py tweaking. [Paul J. Davis]
README.md

namespace.py

In a nutshell, namespace.py allows you to create composite namespace packages without altering any submodule.

>>> import namespace
>>> ns = namespace.Namespace()
>>> ns.proxy("ns.path", "os.path")
>>> import ns.path
>>> import sys
>>> ns.path == sys.modules["os.path"]
True

The general idea here is that you'd create a PyPI package for the namespace and then attach the individual subpackages to the namespace. Something like:

# mynamespace.py
import namespace
ns = namespace.Namespace()
ns.proxy("mynamespace.web", "django")

And then client packages could use this namespace package as:

import mynamespace.web.forms as forms

That's perhaps not the best example, but hopefully it gets the idea across.

Other caveats is that this doesn't allow for magical addition to the namespace if a package elects to be in it. I'm not feeling creative enough to think of a good solution to this. I'm pretty sure it could be done with a hook in setuptools though.