Skip to main content

Read and parse a Primavera P6 xer file.

Project description

Xer-Reader

Read the contents of a Primavera P6 XER file using Python.

Xer-Reader makes it easy to read, parse, and convert the data in a XER file to other formats.

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 xer-reader

Linux/Mac:

pip3 install xer-reader

Usage

Import the XerReader class from xer_reader.

from xer_reader import XerReader

Create a new instance of a XerReader passing in the XER file as an argument. XerReader can accept the file path represented as a str or pathlib Path object, or a Binary file received as a response from requests, Flask, FastAPI, etc...

file = r"/path/to/file.xer"
reader = XerReader(file)

Attributes

  • data [str] - The contents of the XER file as a string.
  • export_date [datetime] - The date the XER file was exported.
  • export_user [str] - The P6 user who export the XER file.
  • export_version [str] - The P6 verison used to export the XER file.
  • file_name [str] - The name of the file without the '.xer' extension.

Methods

check_errors() -> list[str]
Checks the XER file for missing tables and orphan data, and returns the results as a list of errors.

  • Missing tables can occur when an entry in Table 1 points to an entry in Table 2 but Table 2 does not exist at all.
  • Orphan data occurs when an entry in Table 1 points to an entry Table 2 but the entry in Table 2 does not exist.

delete_tables(*table_names: str) -> str
Delete a variable number of tables (table_names) from the XER file data and returns a new string (Does not modify XerReader.data attribute).

In the following example the tables associated with User Defined Fields are removed from the XER file contents and stored in a new variable new_xer_data, which can then be written to a new XER file:

new_xer_data = reader.delete_tables("UDFTYPE", "UDFVALUE")

with open("New_XER.xer", "w", encoding=XerReader.CODEC) as new_xer_file:
    new_xer_file.write(new_xer_data)
new_file.close()

get_table_names() -> list[str]
Returns a list of table names included in the XER file.

get_table_str(table_name: str) -> str
Returns a string for a specific table in the XER file.

has_table(table_name: str) -> bool
Return True if table (table_name) if found in the XER file.

parse_tables() -> dict[str, Table]
Returns a dictionary with the table name as the key and a Table object as the value.

to_csv(file_directory: str | Path) -> None
Generate a CSV file for each table in the XER file using 'tab' as the delimiter. CSV files will be created in the current working directory.
Optional: Pass a string or Path object (file_directory) to speficy a folder to store the CSV files in.

to_json(*tables: str) -> str
Generate a json compliant string representation of the tables in the XER file.
Optional: Pass in specific table names to include in the json string.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xer_reader-0.1.2.tar.gz (18.7 kB view details)

Uploaded Source

Built Distribution

xer_reader-0.1.2-py3-none-any.whl (20.1 kB view details)

Uploaded Python 3

File details

Details for the file xer_reader-0.1.2.tar.gz.

File metadata

  • Download URL: xer_reader-0.1.2.tar.gz
  • Upload date:
  • Size: 18.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.10.6 Linux/5.15.90.1-microsoft-standard-WSL2

File hashes

Hashes for xer_reader-0.1.2.tar.gz
Algorithm Hash digest
SHA256 cced203c8f5fe391388b3d9da50a452b93f10fcc1ce246593c4b0aedec2d82ce
MD5 fe9d032196c1140db3c1d6409a4bec50
BLAKE2b-256 a0a8054e70a05664a1386f7ca91e3b7dd02df0228d9ada4ddd59e27f493f731d

See more details on using hashes here.

File details

Details for the file xer_reader-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: xer_reader-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 20.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.10.6 Linux/5.15.90.1-microsoft-standard-WSL2

File hashes

Hashes for xer_reader-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 cfed602c38c538e371e1ef74f3f58e48134f9bca9b50a9aaa2fa6d871d586b1d
MD5 f60882047f4c3e3a7e3e41045366287e
BLAKE2b-256 ea92586b00d0475b308e3d37ea481e4702ea04381d6e0cc48d13c7076b0c1270

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page