How to read xer-files using Python?

2.8k Views Asked by At

I have some Primavera .xer files. I can open these files in notepad and I see, that there is some text data (it looks like database data).

Are there any Python parsers for these files?

3

There are 3 best solutions below

0
On

I know it is a bit late. However, I have been looking for a similar answer and I couldn't. So, I have started the development of an opensource package called PyP6XER. You can pip install it or contribute to the development on github https://github.com/HassanEmam/PyP6Xer

Note the package is still in its early stages and not well documented.

0
On

The Primavera P6 XER format is indeed vulnerable to analysis by the CSV module. It's basically a tab-delimited back-up format for a relational database.

The first row is some meta-information about the file. Thereafter, each row begins with a code that tells what the rest of the row contains:

  • %T gives the name of a table.
  • %F gives the name of some fields in that table, all on one line.
  • %R is a record for the most recently-defined table.
  • %E is the end-of-file marker.

The rest depends entirely on how you want to use the data. For my part, I put the data directly into a (fresh, new) SQLITE database first and worry about applications later.

0
On

Not an ideal solution, but you could try using MPXJ. MPXJ itself is a Java library, but assuming you can launch a separate process from your Python code you can get it to convert the XER file to JSON which should be easier to consume (this is the approach used by the MPXJ Ruby gem, it's just wrapping the Java code performing the conversion, then reading the resulting JSON). You should also find the structure of the schedule data in the JSON generated by MPXJ easier to work with than the contents of the XER file, although you won't have access to every attribute in the original XER file.

The ruby version of this process can be found here. To summarise, the command line will look something like this:

java -cp <classpath> net.sf.mpxj.sample.MpxjConvert your-file.xer your-file.json

You'll just need to set supply the <classpath> to tell the JVM where MPXJ JAR and its dependencies are.