Skip to main content
Skip table of contents

Python Engine

Users can also run their python scripts within the Requirements and Systems Portal to perform some computations through python coding similar to the octave engine. Additionally, this also allows users to access the rest API and perform modifications to the objects individually or in bulk. The inbuilt python engine currently supports python “Valispace” packages, pint and Scipy (includes NumPy and others). Not all python packages are currently available.

Python Script flow in Scripting Module

The typical workflow in a scripting module involving the python engine is shown in the image below. In case the user doesn't want to perform a calculation and do some bulk changes through the rest API, the user can write the python code directly and run the script.

Packages within python Engine

Since we implemented the python engine within the Requirements and Systems Portal as a beta feature, the python engine doesn’t support all the packages. Currently, very few packages are supported. The packages which are currently supported are listed here.

Example for the python scripting

With the python engine, the user can add the inputs and output and can write a python code to compute the results. This is similar to how it works with the Octave Engine in the Requirements and Systems Portal. In the below example you can see how to write the python script to add a sub-Block to a Block.

CODE
from typing import Any, Dict

import valispace

def main(**kwargs) -> Dict[str, Any]:
    """
    This is the main function to execute your script and it must exists.

    Other functions and files can be also created. You have at your disposal
    to import Valispace API, scipy, numpy and pint.

    :param kwargs: Dictionary with data received from Valispace.
    :type kwargs: Dict[str, Any]

    :return: Dictionary with data to send back to Valispace.
    :rtype: Dict[str, Any]
    """
    # TODO: Write your code here
    
valispace = valispace.API(url="https://.valispace.com/", username = "", password = "") #add your deployment name, username and the password

# The ID of the Parent Component; If it is at the highest level, parent is null, but project need to be specified.
parent_component = 57111

# Object with the new Component Property
component = {
	"name": "NewCompentName2",
	"parent": parent_component
}


# Function to get Vali by the fullname
componentPosted = valispace.post("components/", component)

Currently, to access the the Requirements and Systems Portal’s rest API, the user has to provide the temporary access login token which is stored in the kwargs of the main function or use the User Tokens, see here.

Here are some ideas of what you can do with the scripting module:

  • Creating a vali and adding it to multiple existing components

  • Make bulk edits to the identifiers of requirements

  • Run a simulation using python

  • Convert the units of all power valis to kW

  • Creating and running a script to export the hierarchy of components

  • Creating an export as ReqIF format from the requirements

  • Create a bill of materials extracting components’ material, component number, mass, cost

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.