tags:

views:

69

answers:

2

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 ?

A: 

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
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
Why not simply have a /plugins/ folder that users can drop plugins into and that gets checked when foolib is called?
Soviut
+2  A: 

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

Ned Deily
This is _exactly_ what I was looking for. Thanks!
Stefano Borini