API Reference

This section provides detailed API documentation for all modules and classes in the Alt-Ctrl-Proj library. The documentation is automatically generated from docstrings in the code.

Reader

This file starts the process of reading and parsing xer files

This module provides functionality to read and parse Primavera P6 XER files, transforming the tabular data into Python objects.

class xer_parser.reader.Reader(filename: str)[source]

Bases: object

Main parser class for Primavera P6 XER files.

This class reads an XER file and parses its contents into various Python objects representing projects, tasks, resources, and other Primavera P6 entities.

Parameters:

filename (str) – Path to the XER file to be parsed

file

Path to the XER file

Type:

str

projects

Collection of projects in the XER file

Type:

Projects

activities

Collection of activities/tasks in the XER file

Type:

Tasks

wbss

Collection of Work Breakdown Structure elements in the XER file

Type:

WBSs

relations

Collection of relationships between activities in the XER file

Type:

Predecessors

Examples

>>> from xer_parser.reader import Reader
>>> xer = Reader("myproject.xer")
>>> for project in xer.projects:
...     print(project)
__init__(filename: str) None[source]
property accounts: Accounts

Get all accounts in the XER file.

Returns:

Collection of all accounts in the XER file

Return type:

Accounts

property activities: Tasks

Get all tasks/activities in the XER file.

Returns:

Collection of all tasks contained in the XER file

Return type:

Tasks

property activitycodes: ActivityCodes

Get all activity codes in the XER file.

Returns:

Collection of all activity codes in the XER file

Return type:

ActivityCodes

property activityresources: ActivityResources

Get all activity resources in the XER file.

Returns:

Collection of all activity resources in the XER file

Return type:

ActivityResources

property acttypes: ActTypes

Get all activity types in the XER file.

Returns:

Collection of all activity types in the XER file

Return type:

ActTypes

property actvcodes: TaskActvs

Get all activity code values in the XER file.

Returns:

Collection of all activity code values in the XER file

Return type:

TaskActvs

property calendars: Calendars

Get all calendars in the XER file.

Returns:

Collection of all calendars in the XER file

Return type:

Calendars

create_object(object_type: str, params: dict[str, Any]) None[source]

Create appropriate objects based on the record type.

This method creates and adds objects to their respective collections based on the type of record found in the XER file.

Parameters:
  • object_type (str) – The type of record in the XER file

  • params (dict) – The parameters parsed from the record

Return type:

None

property currencies: Currencies

Get all currencies in the XER file.

Returns:

Collection of all currencies in the XER file

Return type:

Currencies

current_headers: ClassVar[list[str]] = []
current_table: str = ''
property fintmpls: list[FinTmpl]

Get all financial templates in the XER file.

Returns:

Collection of all financial templates in the XER file

Return type:

list[FinTmpl]

get_num_lines(file_path: str) int[source]

Get the number of lines in a file.

Parameters:

file_path (str) – Path to the file

Returns:

Number of lines in the file

Return type:

int

property nonworks: list[NonWork]

Get all non-work periods in the XER file.

Returns:

Collection of all non-work periods in the XER file

Return type:

list[NonWork]

property obss: OBSs

Get all OBS elements in the XER file.

Returns:

Collection of all OBS elements in the XER file

Return type:

OBSs

property pcattypes: list[PCatTypes]

Get all project category types in the XER file.

Returns:

Collection of all project category types in the XER file

Return type:

list[PCatTypes]

property pcatvals: list[PCatVals]

Get all project category values in the XER file.

Returns:

Collection of all project category values in the XER file

Return type:

list[PCatVals]

property projects: Projects

Get all projects in the XER file.

Returns:

Collection of all projects contained in the XER file

Return type:

Projects

property projpcats: list[ProjCat]

Get all project categories in the XER file.

Returns:

Collection of all project categories in the XER file

Return type:

list[ProjCat]

property rcattypes: RCatTypes

Get all resource category types in the XER file.

Returns:

Collection of all resource category types in the XER file

Return type:

RCatTypes

property rcatvals: RCatVals

Get all resource category values in the XER file.

Returns:

Collection of all resource category values in the XER file

Return type:

RCatVals

property relations: Predecessors

Get all relationships between activities in the XER file.

Returns:

Collection of all relationships in the XER file

Return type:

Predecessors

property resourcecategories: ResourceCategories

Get all resource categories in the XER file.

Returns:

Collection of all resource categories in the XER file

Return type:

ResourceCategories

property resourcecurves: ResourceCurves

Get all resource curves in the XER file.

Returns:

Collection of all resource curves in the XER file

Return type:

ResourceCurves

property resourcerates: ResourceRates

Get all resource rates in the XER file.

Returns:

Collection of all resource rates in the XER file

Return type:

ResourceRates

property resources: Resources

Get all resources in the XER file.

Returns:

Collection of all resources in the XER file

Return type:

Resources

property rolerates: RoleRates

Get all role rates in the XER file.

Returns:

Collection of all role rates in the XER file

Return type:

RoleRates

property roles: Roles

Get all roles in the XER file.

Returns:

Collection of all roles in the XER file

Return type:

Roles

property scheduleoptions: SchedOptions

Get all schedule options in the XER file.

Returns:

Collection of all schedule options in the XER file

Return type:

SchedOptions

summary() None[source]

Log a summary of the parsed XER file.

Displays the number of activities and relationships in the parsed file.

Return type:

None

property taskprocs: list[TaskProc]

Get all task procedures in the XER file.

Returns:

Collection of all task procedures in the XER file

Return type:

list[TaskProc]

property udftypes: UDFTypes

Get all UDF types in the XER file.

Returns:

Collection of all UDF types in the XER file

Return type:

UDFTypes

property udfvalues: UDFValues

Get all UDF values in the XER file.

Returns:

Collection of all UDF values in the XER file

Return type:

UDFValues

property wbss: WBSs

Get all Work Breakdown Structure elements in the XER file.

Returns:

Collection of all WBS elements in the XER file

Return type:

WBSs

write(filename: str | None = None) None[source]

Write the parsed data back to an XER file.

Parameters:

filename (str, optional) – Path to the output XER file. If None, an exception is raised.

Raises:

Exception – If filename is None

Return type:

None

Tasks

class xer_parser.model.tasks.Tasks[source]

Bases: object

This class is a collection of tasks that controls functionalities to search, add, update and delete tasks

__init__() None[source]
property activities: list[Task]
activities_by_activity_code_id(id)[source]
activities_by_status(status)[source]
activities_by_type(type)[source]
activities_by_wbs_id(id)[source]
activities_with_hard_contratints()[source]
add(params, data) None[source]
property constraints: list
property count: int
duration_greater_than(duration)[source]
find_by_code(code)[source]
find_by_id(id)[source]
float_greater_than(Tfloat)[source]
float_less_than(Tfloat)[source]
float_within_range(float1, float2)[source]
float_within_range_exclusive(float1, float2)[source]
get_by_project(id)[source]
get_tsv()[source]
property has_no_predecessor: list
property has_no_successor: list
no_predecessors()[source]
no_successors()[source]
class xer_parser.model.classes.task.Task(params: dict[str, Any], data: Any)[source]

Bases: object

Represents a Primavera P6 activity/task.

This class encapsulates all the attributes and functionalities of a Primavera P6 activity, including scheduling information, resources, constraints, and relationships.

Parameters:
  • params (Dict[str, Any]) – Dictionary of parameters from the XER file

  • data (Any) – Reference to the main data container

task_id

Unique identifier for the task

Type:

int

proj_id

Project ID to which this task belongs

Type:

int

wbs_id

WBS element ID to which this task is assigned

Type:

int

clndr_id

Calendar ID assigned to this task

Type:

int

task_code

Short ID which uniquely identifies the task within the project

Type:

str

task_name

Name of the task

Type:

str

task_type

Type of task (Task Dependent, Resource Dependent, Level of Effort, etc.)

Type:

str

duration_type

Duration type (Fixed Units, Fixed Duration, Fixed Units per Time)

Type:

str

status_code

Current status (Not Started, In Progress, Completed)

Type:

str

target_drtn_hr_cnt

Original duration in hours

Type:

float

act_start_date

Actual start date of the task

Type:

datetime

act_end_date

Actual end date of the task

Type:

datetime

target_start_date

Planned/target start date of the task

Type:

datetime

target_end_date

Planned/target end date of the task

Type:

datetime

cstr_type

Constraint type applied to the task

Type:

str

total_float_hr_cnt

Total float in hours

Type:

float

__init__(params: dict[str, Any], data: Any) None[source]

Initialize a Task object from XER file parameters.

Parameters:
  • params (Dict[str, Any]) – Dictionary of parameters from the XER file

  • data (Any) – Reference to the main data container

__repr__() str[source]

String representation of the task.

Returns:

The task’s code

Return type:

str

property activitycodes: list[Any]

Get all activity codes assigned to this task.

Returns:

List of TaskActv objects assigned to this task

Return type:

List[Any]

property constraints: dict[str, Any] | None

Get the constraints applied to this task.

Returns:

Dictionary with constraint type and date, or None if no constraints

Return type:

Dict[str, Any] or None

property duration: float

Get the duration of the task in days.

Returns:

Duration in days (calculated from hours based on calendar working hours)

Return type:

float

property end_date: datetime | None

Get the effective end date of the task.

Returns the actual end date if the task has finished, otherwise the target end date.

Returns:

The effective end date of the task

Return type:

datetime or None

classmethod find_by_wbs_id(wbs_id: int) list[Task][source]

Find all tasks belonging to a WBS element.

Parameters:

wbs_id (int) – The ID of the WBS element

Returns:

List of tasks belonging to the specified WBS element

Return type:

List[Task]

get_tsv() list[Any][source]

Get the task data in TSV format.

Returns:

Task data formatted for TSV output

Return type:

List[Any]

property id: int

Get the task ID.

Returns:

The unique identifier for this task

Return type:

int

obj_list: ClassVar[list[Task]] = []
property predecessors: list[Any]

Get all predecessor tasks to this task.

Returns:

List of tasks that are predecessors to this task

Return type:

List[Any]

property resources: list[Any]

Get all resources assigned to this task.

Returns:

List of TaskRsrc objects assigned to this task

Return type:

List[Any]

property start_date: datetime | None

Get the effective start date of the task.

Returns the actual start date if the task has started, otherwise the target start date.

Returns:

The effective start date of the task

Return type:

datetime or None

property steps: list[Any]

Get all steps (work products) for this task.

Returns:

List of TaskProc objects belonging to this task

Return type:

List[Any]

property successors: list[Any]

Get all successor tasks to this task.

Returns:

List of tasks that are successors to this task

Return type:

List[Any]

property totalint: float | None

Get the total float in days.

Returns:

Total float in days (8 hours per day), or None if not available

Return type:

float or None

Projects

class xer_parser.model.projects.Projects[source]

Bases: object

__init__() None[source]
add(params, data)[source]
find_by_id(id) Project[source]
get_tsv()[source]

Resources

class xer_parser.model.resources.Resources[source]

Bases: object

Container class for managing Primavera P6 resources.

This class provides functionality to store, retrieve, and manipulate Resource objects, supporting both individual resource operations and hierarchical resource structures.

_rsrcs

Internal list of Resource objects

Type:

List[Resource]

index

Current index for iterator functionality

Type:

int

__init__() None[source]

Initialize an empty Resources container.

__iter__() Resources[source]

Make Resources iterable.

Returns:

Self reference for iterator

Return type:

Resources

__next__() Resource[source]

Get the next resource in the iteration.

Returns:

The next resource in the collection

Return type:

Resource

Raises:

StopIteration – When there are no more resources to iterate

add(params: dict[str, Any]) None[source]

Add a new resource to the container.

Parameters:

params (Dict[str, Any]) – Dictionary of parameters from the XER file to create a new Resource

build_tree() list[dict[int, Any]][source]

Build a hierarchical tree structure of resources.

This method organizes resources into their hierarchical structure based on parent-child relationships. Resources without parents form the roots of separate trees in the resulting forest.

Returns:

A forest of resource trees, where each tree represents a hierarchical structure of resources

Return type:

list[dict[int, Any]]

get_parent(id: int) Resource | None[source]

Find the parent resource of a given resource.

Parameters:

id (int) – The resource ID for which to find the parent

Returns:

The parent resource, or None if the resource has no parent or is not found

Return type:

Resource or None

get_resource_by_id(id: int) Resource | None[source]

Find a resource by its ID.

Parameters:

id (int) – The resource ID to search for

Returns:

The resource with the specified ID, or None if not found

Return type:

Resource or None

get_tsv() list[list[Any]][source]

Get all resources in TSV format.

Returns:

Resources data formatted for TSV output

Return type:

list[list[Any]]

class xer_parser.model.classes.rsrc.Resource(params: dict[str, Any])[source]

Bases: object

Represents a Primavera P6 resource.

This class encapsulates all the attributes and functionalities of a resource in Primavera P6, including labor and non-labor resources that can be assigned to activities.

Parameters:

params (Dict[str, Any]) – Dictionary of parameters from the XER file

rsrc_id

Unique identifier for the resource

Type:

int

rsrc_name

Name of the resource

Type:

str

rsrc_short_name

Short name of the resource

Type:

str

rsrc_type

Type of resource (Labor, Non-Labor, etc.)

Type:

str

parent_rsrc_id

ID of the parent resource in a hierarchical structure

Type:

int

clndr_id

ID of the calendar assigned to this resource

Type:

int

role_id

ID of the role assigned to this resource

Type:

int

active_flag

Flag indicating whether the resource is active

Type:

str

email_addr

Email address of the resource (for labor resources)

Type:

str

__init__(params: dict[str, Any]) None[source]

Initialize a Resource object from XER file parameters.

Parameters:

params (Dict[str, Any]) – Dictionary of parameters from the XER file

__repr__() str[source]

String representation of the resource.

Returns:

The resource’s name

Return type:

str

__str__() str[source]

String representation of the resource.

Returns:

The resource’s name

Return type:

str

classmethod find_by_id(id: int) Resource | None[source]

Find a resource by its ID.

Parameters:

id (int) – The resource ID to search for

Returns:

The resource with the specified ID, or None if not found

Return type:

Resource or None

get_id() int[source]

Get the resource ID.

Returns:

The unique identifier for this resource

Return type:

int

get_tsv() list[Any][source]

Get the resource data in TSV format.

Returns:

Resource data formatted for TSV output

Return type:

List[Any]

obj_list: ClassVar[list[Resource]] = []
property parent: int | None

Get the parent resource ID.

Returns:

The ID of the parent resource, or None if this is a top-level resource

Return type:

int or None

toJson() str[source]

Convert the resource to a JSON string.

Returns:

JSON representation of the resource

Return type:

str

Relationships

class xer_parser.model.predecessors.Predecessors[source]

Bases: object

Container class for managing relationships between activities in Primavera P6.

This class provides functionality to store, retrieve, and manipulate relationship objects (TaskPred), which represent logical connections between activities in a project schedule.

task_pred

Internal list of TaskPred objects representing activity relationships

Type:

List[TaskPred]

index

Current index for iterator functionality

Type:

int

Notes

In Primavera P6, relationships can be of four types: - Finish-to-Start (FS): The successor activity cannot start until the predecessor finishes - Start-to-Start (SS): The successor activity cannot start until the predecessor starts - Finish-to-Finish (FF): The successor activity cannot finish until the predecessor finishes - Start-to-Finish (SF): The successor activity cannot finish until the predecessor starts

Relationships can also have lag (positive value) or lead (negative value) time.

__init__() None[source]

Initialize an empty Predecessors container.

__iter__() Predecessors[source]

Make Predecessors iterable.

Returns:

Self reference for iterator

Return type:

Predecessors

__len__() int[source]

Get the number of relationships.

Returns:

The number of relationships in the container

Return type:

int

__next__() TaskPred[source]

Get the next relationship in the iteration.

Returns:

The next relationship in the collection

Return type:

TaskPred

Raises:

StopIteration – When there are no more relationships to iterate

add(params: dict[str, Any]) None[source]

Add a new relationship to the container.

Parameters:

params (dict[str, Any]) – Dictionary of parameters from the XER file to create a new TaskPred

count() int[source]

Get the number of relationships.

Returns:

The number of relationships in the container

Return type:

int

find_by_id(code_id: int) TaskPred | None[source]

Find a relationship by its ID.

Parameters:

code_id (int) – The relationship ID to search for

Returns:

The relationship with the specified ID, or None if not found

Return type:

TaskPred or None

property finish_to_start: list[TaskPred]

Get all Finish-to-Start relationships.

Returns:

List of Finish-to-Start relationships

Return type:

list[TaskPred]

get_predecessors(act_id: int) list[TaskPred][source]

Get all predecessor relationships for a given activity.

Parameters:

act_id (int) – The activity ID for which to find predecessors

Returns:

List of relationships where the specified activity is a successor

Return type:

list[TaskPred]

get_successors(act_id: int) list[TaskPred][source]

Get all successor relationships for a given activity.

Parameters:

act_id (int) – The activity ID for which to find successors

Returns:

List of relationships where the specified activity is a predecessor

Return type:

list[TaskPred]

get_tsv() list[list[Any]][source]

Get all relationships in TSV format.

Returns:

Relationship data formatted for TSV output

Return type:

list[list[Any]]

property leads: list[TaskPred]

Get all relationships with lead time (negative lag).

Returns:

List of relationships with negative lag values

Return type:

list[TaskPred]

property relations: list[TaskPred]

Get all relationships.

Returns:

List of all relationships in the container

Return type:

list[TaskPred]

class xer_parser.model.classes.taskpred.TaskPred(params: dict[str, Any])[source]

Bases: object

Represents a relationship between two activities in Primavera P6.

This class encapsulates a logical connection between two activities, defining how they are related in time. Relationships are directional, having a predecessor and a successor activity, a relationship type, and an optional lag or lead time.

Parameters:

params (Dict[str, Any]) – Dictionary of parameters from the XER file

task_pred_id

Unique identifier for the relationship

Type:

str

task_id

ID of the successor task

Type:

int

pred_task_id

ID of the predecessor task

Type:

int

pred_type

Type of relationship: ‘PR_FS’ (Finish-to-Start), ‘PR_SS’ (Start-to-Start), ‘PR_FF’ (Finish-to-Finish), or ‘PR_SF’ (Start-to-Finish)

Type:

str

lag_hr_cnt

Lag time in hours between the predecessor and successor Positive values represent lag (delay), negative values represent lead (acceleration)

Type:

float

proj_id

Project ID to which the successor task belongs

Type:

int

pred_proj_id

Project ID to which the predecessor task belongs

Type:

int

float_path

Float path indicator

Type:

str

comments

Comments associated with the relationship

Type:

str

Notes

Relationship types in Primavera P6 are defined as: - Finish-to-Start (PR_FS): The successor cannot start until the predecessor finishes - Start-to-Start (PR_SS): The successor cannot start until the predecessor starts - Finish-to-Finish (PR_FF): The successor cannot finish until the predecessor finishes - Start-to-Finish (PR_SF): The successor cannot finish until the predecessor starts

__init__(params: dict[str, Any]) None[source]

Initialize a TaskPred object from XER file parameters.

Parameters:

params (Dict[str, Any]) – Dictionary of parameters from the XER file

__repr__() str[source]

String representation of the relationship.

Returns:

A string representing the relationship in the format: “predecessor_id - relationship_type -> successor_id lag: lag_value”

Return type:

str

get_id() str[source]

Get the relationship ID.

Returns:

The unique identifier for this relationship

Return type:

str

get_tsv() list[Any][source]

Get the relationship data in TSV format.

Returns:

Relationship data formatted for TSV output

Return type:

List[Any]

obj_list: ClassVar[list[TaskPred]] = []

WBS

class xer_parser.model.wbss.WBSs(data: Any | None = None)[source]

Bases: object

__init__(data: Any | None = None) None[source]
add(params: dict[str, Any], data: Any) None[source]
get_by_project(id: int) list[WBS][source]
get_tsv() list[list[str]][source]
class xer_parser.model.classes.wbs.WBS(params: dict[str, Any], data: Any | None = None)[source]

Bases: object

Represents a Work Breakdown Structure (WBS) element in Primavera P6.

This class encapsulates the WBS elements that organize activities hierarchically within a project structure. WBS provides a framework for organizing and defining the total scope of the project.

Parameters:
  • params (Dict[str, Any]) – Dictionary of parameters from the XER file

  • data (Any, optional) – Reference to the main data container

wbs_id

Unique identifier for the WBS element

Type:

int

proj_id

Project ID to which this WBS belongs

Type:

int

wbs_name

Name of the WBS element

Type:

str

wbs_short_name

Short name of the WBS element

Type:

str

parent_wbs_id

ID of the parent WBS element in the hierarchy

Type:

int

status_code

Status code of the WBS element

Type:

str

__init__(params: dict[str, Any], data: Any | None = None) None[source]

Initialize a WBS object from XER file parameters.

Parameters:
  • params (Dict[str, Any]) – Dictionary of parameters from the XER file

  • data (Any, optional) – Reference to the main data container

__repr__() str[source]

String representation of the WBS element.

Returns:

The WBS element’s name

Return type:

str

property activities: list[Task]

Get all activities associated with this WBS element.

Returns:

List of tasks belonging to this WBS element

Return type:

List[Task]

classmethod find_by_id(id_: int | None) WBS | None[source]
classmethod find_by_project_id(project_id: int) list[WBS][source]

Find all WBS elements belonging to a project.

Parameters:

project_id (int) – The project ID to search for

Returns:

List of WBS elements belonging to the specified project

Return type:

List[WBS]

classmethod get_childs(node: WBS, level: int) dict[str, Any][source]
get_id() int[source]

Get the WBS ID.

Returns:

The unique identifier for this WBS element

Return type:

int

classmethod get_json() dict[str, Any][source]
get_tsv() list[Any][source]
obj_list: ClassVar[list[WBS]] = []

DCMA14 Analysis

XER Writer

Module for writing parsed XER data back to files.

This module provides functionality to write data from the Reader object back to an XER file in the Primavera P6 format.

xer_parser.write.writeXER(r: Any, filename: str) None[source]

Write parsed data back to an XER file.

This function writes all the data contained in the Reader object back to a new XER file in the Primavera P6 format. It creates a TSV (tab-separated values) file with all the tables and records from the original XER file, potentially with modifications if made to the data structures.

Parameters:
  • r (Reader) – The Reader object containing the parsed XER data

  • filename (str) – Path to the output XER file

Return type:

None

Notes

The order of tables written to the XER file is important and follows Primavera P6’s requirements for dependencies between tables. The function adds appropriate headers and format indicators for the XER file format.

Examples

>>> from xer_parser.reader import Reader
>>> from xer_parser.write import writeXER
>>> xer = Reader("input.xer")
>>> # Make modifications to the data
>>> writeXER(xer, "output.xer")