Home > Software > How to read PKG-INFO metadata off a Python .egg distribution

How to read PKG-INFO metadata off a Python .egg distribution

It’s obvious when you see it but somehow I’ve just spent an hour on figuring out how to read a PKG-INFO metadata file off a Python .egg distribution, so here it is in case someone needs it some day :-)

# stdlib
import zipimport
 
# Distribute
import pkg_resources
 
egg_file = "/path/to/a/distribution-1.0-py2.6.egg"
dist = pkg_resources.Distribution.from_filename(egg_file,
             metadata=pkg_resources.EggMetadata(zipimport.zipimporter(egg_file)))
 
# pkg_info will now be equal to the contents of a PKG-INFO metadata file
pkg_info = dist.get_metadata("PKG-INFO")
Share
Categories: Software Tags:
  1. No comments yet.
  1. No trackbacks yet.