Find ArcMap document version with Python

Posted on

This post shows how to find the version number of an ArcGIS map document (.mxd) programmatically using Python. It seems that arcpy does not provide a method to do this itself.

ArcGIS map documents are actually Microsoft OLE2 files (also called Structured Storage, Compound File Binary Format or Compound Document File Format). There is a Python module called oletools which can read this format, which is available on PyPI.

To install oletools using pip (from a command prompt):

pip install oletools

The following Python function takes a filename and returns the document version number as a string (e.g. '10.3'):

from oletools.thirdparty import olefile

def mxd_version(filename):
    ofile = olefile.OleFileIO(filename)
    stream = ofile.openstream('Version')
    data ='utf-16')
    version = data.split('\x00')[1]
    return version

It is possible to access other information about the map document in this way, although most of the data remains in an undocumented proprietary format and is not readable. The oletools module includes a graphical browser for data in OLE2 files called (documentation).

This post is based on my answer to a question on GIS.SE.