dastrobu dastrobu - 1 year ago 67
Python Question

How to access python package metadata from within the python console?

If I have built a python package employing

, e.g. via

description="foo package",

where does all the metadata go (what is it intended for?) and how can I access it from within python. Specifically, how can I access the author information from the python console after doing something like

>>> import foo

Answer Source

One way to access the metadata is to use :

import pip

package = [pckg for pckg in pip.get_installed_distributions() 
            if pckg.project_name == 'package_name'][0]
#  package var will contain some metadata: version, project_name and others.

or pkg_resources

from pkg_resources import get_distribution

pkg = get_distribution('package_name')  # also contains a metadata
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download