Export for Python

Tuesday January 01, 2008
I've started playing around with minor projects in my personal launchpad space, partially to try out bzr.

Most recently I wrote a hack, temporarily named "pyexport", which allows you to control the names which your library module namespaces export to application code.

So far, I've implemented a few features.
  1. export.alias(), which registers an alias for a method in another module that will not be imported until that module is imported,
  2. export.explicitly(), a convenience function which makes cooperating with __all__ easy
  3. export.internal(), which marks a module as "internal", and warns any application code (code outside the package which defines the module) which tries to import it
  4. export.restrict(), a method which prevents "leakage" of extraneous imported or private names - for example, if you have a module 'foo' which imports 'sys', you can normally do 'from foo import sys' in Python and get a result.
  5. export.singleton(), which replaces the calling module with a proxy that shares a namespace between the given singleton and the module itself.
It'll be some work to turn this rough prototype into something really usable for a large system like Twisted; at the very least it will need to be rebuilt test-first and integrated with the pydoctor and pydoc documentation tools.  Let me know what you think, and if I should pursue it!