xerparser
Read the contents of a P6 .xer file and convert it into a Python object.
Disclaimers:
It's helpfull if you are already familiar with the mapping and schemas used by P6 during the export process.
Refer to the Oracle Documentation for more information regarding how data is mapped to the XER format.
Tested on .xer files exported as versions 15.2 through 19.12.
Install
Windows:
pip install xerparser
Linux/Mac:
pip3 install xerparser
Usage
Import the Xer
class from xerparser
and pass the contents of a .xer file as an argument. Use the Xer
class variable CODEC
to set the proper encoding to decode the file.
from xerparser import Xer
file = r"/path/to/file.xer"
with open(file, encoding=Xer.CODEC, errors="ignore") as f:
file_contents = f.read()
xer = Xer(file_contents)
Do not pass the the .xer file directly as an argument to the Xer
class. The file must be decoded and read into a string, which can then be passed as an argument. Or, pass the .xer file into the Xer.reader
classmethod, which accepts:
- str or pathlib.Path objects for files stored locally or on a server.
- Binary files from requests, Flask, FastAPI, etc...
from xerparser import Xer
file = r"/path/to/file.xer"
xer = Xer.reader(file)
Attributes
The tables stored in the .xer file are accessable as either Global, Project specific, Task specific, or Resource specific:
Global
xer.export_info
xer.activity_code_types
xer.activity_code_values
xer.calendars
xer.financial_periods
xer.notebook_topics
xer.projects
xer.project_code_types
xer.project_code_values
xer.tasks
xer.relationships
xer.resources
xer.resource_rates
xer.udf_types
xer.wbs_nodes
Project Specific
project = list(xer.projects.values())[0]
project.activity_codes
project.calendars
project.project_codes
project.tasks
project.relationships
project.resources
project.user_defined_fields
project.wbs_nodes
WBS Specific
wbs_node = project.wbs_root
wbs_node.children
wbs_node.project
wbs_node.tasks
wbs_node.all_tasks
wbs_node.user_defined_fields
Task Specific
task = project.tasks[0]
task.activity_codes
task.memos
task.periods
task.resources
task.user_defined_fields
Resource Specific
resource = list(task.resources.values())[0]
resource.periods
resource.user_defined_fields
Error Checking
Sometimes the xer file is corrupted during the export process. If this is the case, a CorruptXerFile
Exception will be raised during initialization. A list of the errors can be accessed from the CorruptXerFile
Exception, or by using the find_xer_errors
function.
Option 1 - errors
attribute of CorruptXerFile
exception (preferred)
from xerparser import Xer, CorruptXerFile
file = r"/path/to/file.xer"
try:
xer = Xer.reader(file)
except CorruptXerFile as e:
for error in e.errors:
print(error)
Option 2 - find_xer_errors
function
from xerparser import parser, file_reader, find_xer_errors
file = r"/path/to/file.xer"
xer_data = parser(file_reader(file))
file_errors = find_xer_errors(xer_data)
for error in file_errors:
print(error)
Errors
-
Minimum required tables - an error is recorded if one of the following tables is missing:
- CALENDAR
- PROJECT
- PROJWBS
- TASK
- TASKPRED
-
Required table pairs - an error is recorded if Table 1 is included but not Table 2:
Table 1 | Table 2 | Notes |
---|
TASKFIN | FINDATES | Financial Period Data for Task |
TRSRCFIN | FINDATES | Financial Period Data for Task Resource |
TASKRSRC | RSRC | Resource Data |
TASKMEMO | MEMOTYPE | Notebook Data |
ACTVCODE | ACTVTYPE | Activity Code Data |
TASKACTV | ACTVCODE | Activity Code Data |
PCATVAL | PCATTYPE | Project Code Data |
PROJPCAT | PCATVAL | Project Code Data |
UDFVALUE | UDFTYPE | User Defined Field Data |
-
Non-existent calendars assigned to tasks.
-
Non-existent resources assigned to task resources.