[Python-ideas] Python package files

Adam Atlas adam at atlas.st
Thu Apr 26 21:59:46 CEST 2007


I think it would be useful for Python to accept imports of standalone  
files representing entire packages, maybe with the extension .pyp. A  
package file would basically be a ZIP file, so it would follow fairly  
easily from the current zipimport mechanism... its top-level  
directory would be the contents of a package named by the outer ZIP  
file. In other words, suppose we have a ZIP file called  
"package.pyp", and at its top level, it contains "__init__.py" and  
"blah.py". Anywhere this can be located, it would be equivalent to a  
physical directory called "package" containing those two files. So  
you can simply do "import package" as usual, regardless of whether  
it's a directory or a .pyp.

A while ago I wrote a program called Squisher that does this (it  
takes a ZIP file and turns it into an importable .pyc file), but it's  
a huge hack. The hackishness mainly comes from my desire to not  
require users of Squished packages to install Squisher itself; so  
each module basically has to bootstrap itself, adding its own import  
hook and then adding its own path to sys.path and shuffling around a  
couple of things in sys.modules. All that could be avoided if this  
were a core feature; I expect a straightforward import hook would  
suffice.

As PEP 302 says, "Distributing lots of source or pyc files around is  
not always appropriate, so there is a frequent desire to package all  
needed modules in a single file." It's very useful to be able to  
download a single file, plop it into a directory, and immediately be  
able to import it like any .py or .pyc file. Eggs are nice, but  
having to manually add them to sys.path or install them system-wide  
with setuptools is not always ideal.



More information about the Python-ideas mailing list