moduleyou can put code for testing the features of your library inside an if statement as shown and simply run python on your module as the main program to run it that code won' run for users who import your library the module search path when loading modulesthe interpreter searches the list of directories in sys path the first entry in sys path is typically an empty string ''which refers to the current working directory other entries in sys path may consist of directory nameszip archive filesand egg files the order in which entries are listed in sys path determines the search order used when modules are loaded to add new entries to the search pathsimply add them to this list although the path usually contains directory nameszip archive files containing python modules can also be added to the search path this can be convenient way to package collection of modules as single file for examplesuppose you created two modulesfoo py and bar pyand placed them in zip file called mymodules zip the file could be added to the python search path as followsimport sys sys path append("mymodules zip"import foobar specific locations within the directory structure of zip file can also be used in additionzip files can be mixed with regular pathname components here' an examplesys path append("/tmp/modules zip/lib/python"in addition to zip filesyou can also add egg files to the search path egg files are packages created by the setuptools library this is common format encountered when installing third-party python libraries and extensions an egg file is actually just zip file with some extra metadata ( version numberdependenciesetc added to it thusyou can examine and extract data from an egg file using standard tools for working with zip files despite support for zip file importsthere are some restrictions to be aware of firstit is only possible import pypywpycand pyo files from an archive shared libraries and extension modules written in cannot be loaded directly from archivesalthough packaging systems such as setuptools are sometimes able to provide workaround (typically by extracting extensions to temporary directory and loading modules from itmoreoverpython will not create pyc and pyo files when py files are loaded from an archive (described nextthusit is important to make sure these files are created in advance and placed in the archive in order to avoid poor performance when loading modules module loading and compilation so farthis has presented modules as files containing pure python code howevermodules loaded with import really fall into four general categoriesn code written in python py filesn or +extensions that have been compiled into shared libraries or dlls lib fl ff