1

What is the/is there a prefered way to expose a module version number?

  • Python itself use the builtins tuple sys.version_info:

    >>> sys.version_info
    sys.version_info(major=3, minor=3, micro=0, releaselevel='final', serial=0)
    
  • MySQLdb (for example) use an ordinary tuple:

    >>> MySQLdb.version_info
    (1, 2, 3, 'final', 0)
    
  • Some third party library use the string __version__

    >>> requests.__version__
    '1.2.3'
    
  • Some frameworks use the tuple VERSION:

    >>> django.VERSION
    (1, 6, 0, 'alpha', 0)
    

... apparently, there are a lot of different usages in that matter!

Sylvain Leroux
  • 50,096
  • 7
  • 103
  • 125

1 Answers1

5

According to PEP 396, it should be module.__version__. According to that PEP, you should use the Normalized Version style in PEP 386 to decide how it should be written.

It looks like there is a draft version of PEP 440 that will supplant 386.

thegrinner
  • 11,546
  • 5
  • 41
  • 64