frePPLeOpen source Production Planning
  • Home
  • Documentation
  • C++ API

Python interpreter

FrePPle embeds an interpreter for the Python language.

The full capabilities of this scripting language are accessible from frePPLe, and Python also has access to the frePPLe objects in memory.
Python is thus a very powerful way to interact with frePPLe.

Python code can be executed in two ways:

  • A XML processing instruction in XML data files.
         <?xml version="1.0" encoding="UTF-8" ?>
         <plan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot;>
         ...
         <?python
         Your python code goes here.
         ?>
         ...
         </plan>
  • Python code in a file init.py, located in one of the frePPLe directories, is executed automatically when frePPLe starts. This provides a clean mechanism to define global Python functions and classes you application needs.

The interpreter is multi-threaded. Multiple python scripts can run in parallel. However, Python internally executes only one thread at a time and the interpreter switches between the active threads.
A single, global interpreter instance is used. A global Python variable or function is thus visible across multiple invocations of the Python interpreter.

The following Python functions are defined:

  • loadmodule dynamically loads an extension module.
  • readXMLfile processes a XML-file from the local file system.
  • readXMLdata processes a XML-formatted string.
  • erase removes part of the model or plan from memory.
  • saveXMLfile saves the model to an XML-formatted file.
  • saveplan saves the most important plan information to a file.
  • printsize prints information about the memory size of the model and other system parameters.

loadmodule

This command dynamically loads an extension module.

Field Type Description
filename normalizedString Name of the shared library file to be loaded.
The operating system should allow frePPLe to locate the file. The directories listed in the following environment variable should include the module shared library.

  • LD_LIBRARY_PATH variable for Linux, Solaris
  • LIBPATH for AIX
  • SHLIB_PATH for HPUX
  • PATH for windows and cygwin
parameter parameter Initialization and configuration values that are passed to the module’s initialization routine.
A parameter consists of a PARAMETER and VALUE pair, as shown in the example below.

Example code:

  <?python
  frepple.loadmodule("your_module.so", 
    parameter1="string value",
    parameter2=100,
    parameter3=True)
  ?>

readXMLfile

This command reads and processes a XML-file from the local file system.

Field Type Description
filename normalizedString Name of the data file to be loaded.
validate boolean When set to true, the XML data are validated against the XML-schema.
The default value is true, for security reasons.
When parsing large files with a trusted structure setting this field to false will speed up the import.
validate_only boolean If this optional argument is equal to true the input data are only validated against the XML-schema. The data are not processed in the core application.
callback Python function An optional callback function that is called when an object has been read from the input data.\\ The object is passed as argument.

Example code:

  <?python
  frepple.readXMLfile("input.xml",True,True) 
  ?>

readXMLdata

This command processes a XML-formatted data string.

Field Type Description
data string XML-formatted data to be processed.
validate boolean When set to true, the XML data are validated against the XML-schema.
The default value is true, for security reasons.
When processing large data strings with a trusted structure setting this field to false will speed up the execution.
validate_only boolean If this optional argument is equal to true the input data are only validated against the XML-schema. The data are not processed in the core application.
callback Python function An optional callback function that is called when an object has been read from the input data.\\ The object is passed as argument.

Example code:

  <?python
  frepple.readXMLdata('''
    <plan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <locations>
    <location name="Location 1" action="R"/>
    </locations>
    </plan>''',True,True) 
  ?>

erase

Use this command to erase the plan or the entire model from memory.

Field Type Description
mode boolean When set to true the complete model is erased. You will again have a completely empty model.
When set to false only the plan information is erased, ie only the operationplans with their load- and flowplans are removed (except the ones that are locked).

Example code:

  <?python
  frepple.erase(False)
  ?>

saveXMLfile

This commands saves the model into an XML file.

Field Type Description
filename normalizedString Name of the output file.
content STANDARD
PLAN
PLANDETAIL
Controls the level of detail in the output:

  • STANDARD plan information is sufficient for restoring the model from the output file.
    This is the default mode.
  • PLAN adds more detail about its plan with each entity.
    A buffer will report on its flowplans, a resource reports on its loadplans, and a demand on its delivery operationplans.
  • PLANDETAIL goes even further and includes full pegging information the output.
    A buffer will report how the material is supplied and which demands it satisfies, a resource will report on how the capacity used links to the demands, and a demand shows the complete supply path used to meet it.
headerstart string The first line of the XML output.
The default value is:

  <?xml version="1.0" encoding="UTF-8"?>
headeratts string Predefined attributes of the XML root-element.
The default value is:

  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

Example code:

  <?python
  frepple.saveXMLfile("output.xml")
  frepple.saveXMLfile("detailedoutput.xml","PLANDETAIL")
  ?>

saveplan

This command saves the most important plan information to a file.
It is used for the unit tests, but its’ usefulness in a real-life implementation is probably limited.

Field Type Description
filename normalizedString Name of the output file.

Example code:

  <?python
  frepple.saveplan("output.xml")
  ?>

printsize

This command prints information about the memory size of the model and other sytem parameters.

Example code:

  <?python
  frepple.printsize()
  ?>
    • Getting started
      • 1 – Introduction
      • 2 – Installation
      • 3 – Entering data
      • 4 – Modelling concepts
      • 5 – Your first model
      • 6 – Your first plan
    • Modeling guide
      • Simplified domain model
      • Detailed domain model
      • Environment variables
      • Python interpreter
      • Global parameters
      • Buffer
      • Calendar
      • Customer
      • Demand
      • Flow
      • Item
      • Load
      • Location
      • Operation
      • Suboperation
      • Operationplan
      • Problem
      • Resource
      • SetupMatrix
      • Skill
      • Resource skill
      • Solver
    • User guide
      • Supported browsers
      • Getting around
        • Logging in
        • Logging out
        • Changing password
        • Navigation
          • Menu bar
          • Jump search
          • Context menus
        • Filtering data
        • Sorting data
        • Selecting time buckets
        • Exporting data
        • Importing data
        • Customizing a screen
        • User preferences
        • User permissions and roles
        • Comments
        • History – Audit trail
      • Data maintenance screens
      • Supply Path / Where Used
      • Plan analysis screens
        • Problem report
        • Constraint report
        • Inventory report
        • Inventory detail report
        • Resource report
        • Resource Gantt report
        • Resource detail report
        • Operation report
        • Operation detail report
        • Demand report
        • Demand detail report
        • Demand Gantt report
        • Forecast report
        • Performance indicator report
      • Execution screen
      • Batch commands
        • frepplectl
        • frepple
        • freppleservice.exe (Windows only)
    • Installation guide
      • Windows installer
      • Compiling on Windows
      • Linux binary packages
      • Compiling on Linux
      • Compiling from the source code repository
      • Running the VMWare virtual machine
      • Other platforms
      • Configuring multiple models in the user interface
      • Configuring as a Python extension module
    • Extension modules
      • Forecast module
      • Order quoting module
      • REST web service module
      • OpenERP connector module
      • Linear programming solver module
    • Technical guide
      • Architecture
      • Source code repository
      • User interface
        • Creating an extension app
        • Translating the user interface
        • Adding or customizing a report
        • Style guide
      • Solver engine
        • Code structure
        • Class diagram
        • Planning algorithm
          • Top level loop
          • Demand solver
          • Buffer solver
          • Flow solver
          • Load solver
          • Operation solver
          • Resource solver
        • Cluster and level algorithm
        • Extension modules
        • Style guide
        • Portability
      • Security
      • Unit tests
        • buffer_procure_1
        • calendar
        • callback
        • cluster
        • constraints_combined_1
        • constraints_combined_2
        • constraints_leadtime_1
        • constraints_material_1
        • constraints_material_2
        • constraints_material_3
        • constraints_material_4
        • constraints_resource_1
        • constraints_resource_2
        • constraints_resource_3
        • constraints_resource_4
        • constraints_resource_5
        • datetime
        • deletion
        • demand_policy
        • flow_alternate_1
        • flow_alternate_2
        • flow_effective
        • forecast_1
        • forecast_2
        • forecast_3
        • forecast_4
        • forecast_5
        • forecast_6
        • jobshop
        • load_alternate
        • load_effective
        • lpsolver_1
        • multithreading
        • name
        • operation_alternate
        • operation_available
        • operation_effective
        • operation_pre_post
        • operation_routing
        • pegging
        • problems
        • python_1
        • python_2
        • python_3
        • safety_stock
        • sample_module
        • scalability_1
        • scalability_2
        • scalability_3
        • setup_1
        • setup_2
        • skill
        • xml
        • xml_remote
    • FAQ
    • License
      • GNU Affero General Public License
      • GNU Free Documentation License
    • Third party add-ons
  • Copyright © 2010-2013 frePPLe bvba