1

I would like to create a library, say foolib, but to keep different subpackages separated, so to have barmodule, bazmodule, all under the same foolib main package. In other words, I want the client code to be able to do

import foolib.barmodule
import foolib.bazmodule

but to distribute barmodule and bazmodule as two independent entities. Replace module with package as well... ba[rz]module can be a fukll fledged library with complex content.

The reason behind this choice is manifold:

  • I would like a user to install only barmodule if he needs so.
  • I would like to keep the modules relatively independent and lightweight.
  • but I would like to keep them under a common namespace.

jQuery has a similar structure with the plugins.

Is it feasible in python with the standard setuptools and install procedure ?

Stefano Borini
  • 138,652
  • 96
  • 297
  • 431
  • I asked something similar: http://stackoverflow.com/questions/1443146/how-do-i-protect-my-python-codebase-so-that-guests-cant-see-certain-modules-but – a paid nerd Nov 10 '09 at 04:56

2 Answers2

3

You may be looking for namespace packages. See also PEP 382.

Community
  • 1
  • 1
Ned Deily
  • 83,389
  • 16
  • 128
  • 151
0

Yes, simply create a foolib directory, add an __init__.py to it, and make each sub-module a .py file.

/foolib
    barmodule.py
    bazmodule.py

then you can import them like so:

from foolib import barmodule
barmodule.some_function()
Soviut
  • 88,194
  • 49
  • 192
  • 260
  • Yes, this I know. My problem is not how to create a package containing two modules. My problem is to distribute them as two independent "sublibraries" part of the same library namespace. – Stefano Borini Nov 10 '09 at 05:05
  • Why not simply have a /plugins/ folder that users can drop plugins into and that gets checked when foolib is called? – Soviut Nov 10 '09 at 05:08