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:
objectMain 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
- relations
Collection of relationships between activities in the XER file
- Type:
Examples
>>> from xer_parser.reader import Reader >>> xer = Reader("myproject.xer") >>> for project in xer.projects: ... print(project)
- 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:
- 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.
- property currencies: Currencies
Get all currencies in the XER file.
- Returns:
Collection of all currencies in the XER file
- Return type:
Currencies
- 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]
- 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:
- 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:
- 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:
- 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
Tasks
- class xer_parser.model.tasks.Tasks[source]
Bases:
objectThis class is a collection of tasks that controls functionalities to search, add, update and delete tasks
- class xer_parser.model.classes.task.Task(params: dict[str, Any], data: Any)[source]
Bases:
objectRepresents 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
- 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
- __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
- 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:
- 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.
- get_tsv() list[Any][source]
Get the task data in TSV format.
- Returns:
Task data formatted for TSV output
- Return type:
List[Any]
- 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]
Projects
Resources
- class xer_parser.model.resources.Resources[source]
Bases:
objectContainer 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.
- __iter__() Resources[source]
Make Resources iterable.
- Returns:
Self reference for iterator
- Return type:
- __next__() Resource[source]
Get the next resource in the iteration.
- Returns:
The next resource in the collection
- Return type:
- 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.
- class xer_parser.model.classes.rsrc.Resource(params: dict[str, Any])[source]
Bases:
objectRepresents 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
- __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[source]
String representation of the resource.
- Returns:
The resource’s name
- Return type:
- get_id() int[source]
Get the resource ID.
- Returns:
The unique identifier for this resource
- Return type:
- get_tsv() list[Any][source]
Get the resource data in TSV format.
- Returns:
Resource data formatted for TSV output
- Return type:
List[Any]
Relationships
- class xer_parser.model.predecessors.Predecessors[source]
Bases:
objectContainer 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]
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.
- __iter__() Predecessors[source]
Make Predecessors iterable.
- Returns:
Self reference for iterator
- Return type:
- __len__() int[source]
Get the number of relationships.
- Returns:
The number of relationships in the container
- Return type:
- __next__() TaskPred[source]
Get the next relationship in the iteration.
- Returns:
The next relationship in the collection
- Return type:
- Raises:
StopIteration – When there are no more relationships to iterate
- count() int[source]
Get the number of relationships.
- Returns:
The number of relationships in the container
- Return type:
- get_predecessors(act_id: int) list[TaskPred][source]
Get all predecessor relationships for a given activity.
- get_successors(act_id: int) list[TaskPred][source]
Get all successor relationships for a given activity.
- class xer_parser.model.classes.taskpred.TaskPred(params: dict[str, Any])[source]
Bases:
objectRepresents 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
- 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:
- lag_hr_cnt
Lag time in hours between the predecessor and successor Positive values represent lag (delay), negative values represent lead (acceleration)
- Type:
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:
- get_id() str[source]
Get the relationship ID.
- Returns:
The unique identifier for this relationship
- Return type:
WBS
- class xer_parser.model.classes.wbs.WBS(params: dict[str, Any], data: Any | None = None)[source]
Bases:
objectRepresents 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
- __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:
- 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_project_id(project_id: int) list[WBS][source]
Find all WBS elements belonging to a project.
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:
- 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")