Python on the web: How to get a list of all available Python modules

If you want to get a complete list of Python modules available on your web host, you can do so with the following code:


import os

print "Content-type: text/html\n\n";
print "<html><head></head>"
print "<body bgcolor='#ffffff'>"

print "\n<BR><b>Available Modules:</b><BR>"

# List all installed packages
print '<ul>'
dist_list = []
for dist in __import__('pkg_resources').working_set:
    dist_list.append(dist.project_name.replace('Python', '').strip())
dist_list = list(filter(None, dist_list))
for dist in dist_list:
    print "\n<li>", dist, '</li>'   
print '</ul>'

print "</body></html>"

I saved the above code as a CGI script called “” and uploaded it to my website cgi-bin. Here is what the code produces, shown below in an iframe:

For more information about pkg_resources, see:

Leave a Reply