Nimp: Nested Imports (a la Java)

Tomer Filiba tomerfiliba at gmail.com
Thu Jun 16 10:48:32 CEST 2011


Nimp (Nested Imports) is a little meta-importer hook for Python 2.3-2.7 and 3.0-3.2 that enables the use of *nested packages* (`com.ibm.foo.bar`), as is commonplace in Java and various other languages. It works by collecting all packages that begin with a common prefix on your `sys.path` and "merging" them into logical packages.

Homepage: http://pypi.python.org/pypi/nimp
Install: pip install nimp

Example
-------
Consider the following package layout (say, under site-packages, or anywhere on your python path):

  site-packages/
    com-ibm-storage/
      ... package files ...
    com-ibm-storage-plugins/
      ... package files ...
    com-google-protobuf/
      ... package files ...
    com-google-appengine/
      ... package files ...

Using Nimp is easy:

  import nimp
  nimp.install()

You can place these two lines in your `site.py`; after calling `nimp.install()`, the following imports will "magically" work:

  import com # a namespace package (empty)
  import com.google.protobuf
  import com.ibm.storage
  from com.ibm.storage.plugins import MySQLPlugin


More information about the Python-announce-list mailing list