Skip to main content

Nested Imports (Nimp)

Allows nested imports, a la Java. Nimp installs a harmless meta import-hook that adds support for nested packages, i.e., multiple packages that “live” under a common namespace. This is the idiom in Java, where you have packages like com.foo.bar.spam and com.foo.bar.eggs, as well as in Haskell and several other languages. Nimp basically allows packages to “inject” themselves into shared namespaces.

Compatible with Python 2.3-2.7 and 3.0 and up.

You can read more about nimp and __lazy__ on my blog.

Usage

import nimp
nimp.install()

You can add these two lines to your site.py script, so you’ll get Nimp out of the box.

Benefits

  • Allows for distributing “plug-in” packages independently: consider a project like twisted, made of several add-on packages (but without hacking distutils too much).

  • A project may depend on package X.Y without having to depend on X.

  • These nested-packages can be found anywhere on your python path (they don’t have to be located in the same directory)

  • A small (less than 100 LoC) standalone module that does all the magic for you – no third-party cooperation required.

Example Layout

Consider the following directory structure, somewhere on your python path (say, site-packages):

site-packages/

  com-ibm-storage/
    files...

  com-ibm-storage-plugins/
    files...

  com-ibm-pythontools/
    files...

After calling nimp.install(), the following imports will work as expected:

import com                              # a namespace package (empty)
import com.ibm                          # a namespace package (empty)
import com.ibm.pythontools              # a real package
com.ibm.pythontools.myfunc(1,2,3)

# and of course `from x import y` works too
from com.ibm.storage import ScsiDisk

# note how the `plugins` package is "injected" into `storage`
from com.ibm.storage.plugins import MySQLPlugin

Metadata

Release files for nimp 0.9.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nimp 0.9.2
File Size Uploaded
nimp-0.9.2.tar.gz 3.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nimp 0.9.2
File Interpreter ABI Platform
nimp-0.9.2.win32.exe Details

Total release size: 206.1 kB

Release files / nimp-0.9.2.tar.gz

Download URL nimp-0.9.2.tar.gz
Size 3.9 kB
Tags Source
SHA-256 checksum
How to use checksums
a512f3691aa4d4af1ff448f220deaacb5b6402061476856833392a2c76b9f6bc
BLAKE2b-256 checksum
How to use checksums
40dfccc932ce29f90d4efb52f401e434bb945697c9d8eac8d2da3aa469cde97b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / nimp-0.9.2.win32.exe

Download URL nimp-0.9.2.win32.exe
Size 202.2 kB
Tags Source
SHA-256 checksum
How to use checksums
a5dc47774afc528b661ca8af5ab0b6f854309c5ad4222f88568bac13016eb46f
BLAKE2b-256 checksum
How to use checksums
502e1fb95e52564df24165ed632e93976fcba87140469e78a959a245d37c5a20
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.9.2 This release

2 release files

0.9.1

2 release files

0.9

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page