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 ?

1

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

Comments

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() 

2 Comments

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.