[Distutils] Splitting distribute in several distributions

Hanno Schlichting hanno at hannosch.eu
Wed Aug 12 14:31:46 CEST 2009

On Wed, Aug 12, 2009 at 2:18 PM, Barry Warsaw<barry at python.org> wrote:
> On Aug 12, 2009, at 4:35 AM, Tarek Ziadé wrote:
> One feature I would love to see make standard is the ability to import a
> package and check its __version__.  Version information must be available
> from Python, and it seems like __version__ is the standard place to put it.
> Too many times I've had to figure out the version of foo.bar that I'm
> using.  When I can do
>>>> import foo.bar
>>>> foo.bar.__version__
> 3.2.1
> I am a much happier camper.

The easiest way I could find right now seems to be:

>>> import pkg_resources
>>> dist = pkg_resources.get_distribution('foo')
>>> dist.version

Which isn't too bad and could be simplified into an even simpler API call.

If the package author doesn't set a __version__ attribute in his own
code, I'd be hesitant to magically make it available from the
accompanying metadata. If it's part of the metadata, an explicit API
that makes it clear that you are querying the package metadata seems
cleaner to me.


More information about the Distutils-SIG mailing list