Introduction to Python scripting
You can interact with parts of the simulation object model, policies and events and manipulate them through Python®. Review the Generic event hierarchy to gain a high-level overview of the potential interaction points within Supply Chain Guru X simulation. You will find additional detail about the actual script types, their outputs and expected return values in the Script types section. The Model object tree provides a high-level look at some of the main relationships between objects. More detail including the individual attributes, attribute data types and whether attributes are settable is available in the Model object dictionary. This document describes the parts available to Python and how to interact with simulation but does not cover Python documentation.
You can use one of a number of publicly available Python script editors to develop your scripts.
Python script import
You can set up a Python file as a script for use with Simulation using the Simulation Scripts tool.

- Select Model > Simulation Scripts. You see the Simulation Scripts form.
- Click Add. If you have not already set the Python Script Folder on the General tab in Simulation Options, you are asked if you want to set the path.
- Click Yes, then navigate to the folder where your Python script files (*.py) are located and click OK.
- Select the Python script filename and click Open. The script is added to the list of available scripts.
- Enter the script Method Name. This is the method you have defined within the script that should be called when the script is triggered.
- Select the Script Type from the dropdown list.
- If the script is a scheduled script, select/enter values for:
- First Time – If you want the script to start on a specific date, enter this date in the First Time option.
- First Time Formula – If you want the script to start on a 'day of model', enter this value in the First Time Formula parameter. For example, if you want the script to start on the 20th day of the model horizon, enter 20. First Time Formula overrides First Time if both are present.
- Run Time Interval – If Occurrences is greater than 1, then use the Run Time Interval option to specify the time between each trigger.
- Occurrences – Use the Occurrences value to determine the number of times you want the script to trigger.
For example, if you want a script to trigger on every 5th day of the model at 6 a.m. starting on the 20th day of the model and continuing for approximately one month, then the inputs would be:
- First Time Formula: 20.25 DAY (0.25 of a day is 6 a.m.)
- Run Time Interval: 5 DAY
- Occurrences: 6
- Click Update. The script will now be available for use in table columns based on the Script Type. For example, if you defined a script with a Script Type of “Mode Selection Rule”, this script will now be available as a selection in the Transportation Policies Mode Rule column.
Python script editors
There are a number of python editors available for use in editing your Simulation scripts. Coupa recommends the following editors:
PyCharm Community Edition:
https://www.jetbrains.com/pycharm/download/#section=windows
PyDev:
This editor is a plug-in for Eclipse (https://eclipse.org).
Python scripts and SupplyChainGuru.com
At this time, Python scripts are not supported when uploading to or solving on the Cloud.
Notation
Data types are in italics.
Objects are enclosed in brackets <...>.
Custom attributes
Each object in the object model accepts custom attributes. Custom attributes can be of any Python data type. This functionality allows you to add integer, string, float, and other data type attributes to any object. Because any Python data type is allowed, you can also add lists, tuples or arrays to any object. For example, you can attach a transportation cost grid with weight bands in columns and distance bands in rows to the Model object, Lane object or TransportationMode object. This grid will be available to calculate a rate based on a shipment's weight and lane distance.
Methods
<object>.setcustomattribute(attributename as string, attributedata as Python type)
Sets the custom attribute named 'attributename'
<object>.getcustomattribute(attributename as string)
Returns the value of the custom attribute named 'attributename'
Last modified: Wednesday May 15, 2024