Create MS Project in Python | MS Project API Python

Project management is essential for any organization that wants to thrive in a competitive world. Microsoft Project is popular project management software that manages projects easily and flexibly. In certain cases, we may need to create and manage MS Projects programmatically without using MS Project. In this blog post, we will explore how to create an MS Project programmatically using Python, unlocking new levels of automation and productivity.

This article covers the following topics:

  1. Python API to Create and Manage MS Projects
  2. Create MS Project from Scratch using Python
  3. Add Tasks to the Project
  4. Add Resources to the Project
  5. Assign Tasks to Project Resources
  6. Set MS Project’s Calculation Mode
  7. Convert MPP to XML

Python API to Create and Manage MS Projects

We will use Apose.Tasks for Python in order to create our MS Project. It is a powerful API that allows developers to work with Microsoft Project files (MPP) programmatically. It provides features and functionalities to read, write, manipulate, and manage Microsoft Project files without Microsoft Project software itself.

Please download the package or install the API from PyPI using the following pip command in the console:

pip install aspose-tasks

Create MS Project File in Python

MS Project uses MPP as the proprietary file format. We can create the first MS Project from scratch by following the steps below:

  • Create an instance of the Project class.
  • Call the save() method with the output MPP file path and SaveFileFormat as arguments.

The following code samples show how to create MS Project files using Python.

Create MS Project File in Python

Add Tasks to MS Project in Python

We can add simple tasks, summary tasks, or subtasks to the MS project programmatically by following the steps below:

  1. Create an instance of the Project class.
  2. Add a new summary task to the project’s Tasks collection using the root_task.children.add(string) method.
  3. Add a subtask to the summary task using the task.children.add(string) method.
  4. Call the save() method to save the project.

The following code sample shows how to create and add tasks to MS Project files using Python.

Add Tasks to MS Project File in Python

Add Resources to MS Project using Python

Resources are the entities that perform tasks in a project. We can add resources to MS Project programmatically by following the steps below:

  • Create or load an existing project using the Project class.
  • Add a new resource to the project’s Resources collection using the project.resources.add(string) method.
  • Call the save() method to save the project.

The following code sample shows how to add resources to an MS Project file using Python.

Assign Tasks to Resources in a Project using Python

After adding tasks and resources, we can assign tasks to resources by following these steps:

  • Create an instance of the Project class.
  • Add a task to the project’s Tasks collection.
  • Add a resource to the project’s Resources collection.
  • After that, assign the task to the respective resource using the project.resource_assignments.add(task, resource) method.
  • Call the save() method with the output MPP file path and SaveFileFormat as arguments.

The following code sample shows how to create and assign tasks to resources in an MS Project using Python.

Assign Tasks to Resource in a Project using Python

Set MS Project Calculation Mode using Python

The project’s calculation mode defines when to calculate changes. We can set the calculation mode by following the steps below:

  • Create or load a project using the Project class.
  • Specify the project’s calculation_mode property using the CalculationMode enumeration value.
  • Save the project.

The following code sample shows how to set MS Project’s calculation mode using Python.

Convert MPP to XML

We can save MS Project in formats other than MPP such as XML as shown below:

Please check out the detailed tutorial on how to convert MPP to XML in Python.

Try Aspose.Tasks for Free

You can get a free temporary license to try Aspose.Tasks for Python without evaluation limitations.

MS Project API Python

Check out the following resources to learn more about creating and managing MS Projects using Aspose.Tasks for Python:

Conclusion

In this blog post, we learned how to create an MS Project file in Python. The step-by-step guide and code samples show how easy it is to create MS Projects, add tasks and resources, and assign tasks to resources using the Aspose.Tasks for Python library. Whether you’re a beginner or an experienced programmer, Aspose.Tasks for Python simplifies the creation and manipulation of MS Projects without Microsoft Project. Take advantage of this library and improve your project management and automation. In case of any ambiguity, please contact us on our free support forum.

See Also