Python API

FrePPle embeds an interpreter for the Python programming language.
The full capabilities of this scripting language and its rich library
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 the planning engine.
For complex data integration tasks and for customization of the algorithms
Python is your big friend.

Here’s a simple annotated example of a Python script that is executed
by the planning engine:

# Loads the planning engine as a Python module.importfrepple# Use the standard Python module to read a CSV-formatted text fileimportcsvwithopen('products.csv',newline='')ascsvfile:csvreader=csv.reader(csvfile,delimiter=' ',quotechar='|')forrowincsvreader:# The next line creates an item object in the frePPle core# planning engine.frepple.item(name=row[0],description=row[1])# Call the planning engine solver to create a fully constrained planfrepple.solver_mrp(plantype=1,constraints=15,loglevel=2).solve()# Echo the plan resultsto the screen: load of all resourcesforiinfrepple.resources():forjini.loadplans:print(j.operationplan.id,j.resource.name,j.quantity,j.startdate,j.enddate)# Echo the plan resultsto the screen: inventory profile of all buffersforiinfrepple.buffers():forjini.flowplans:print(j.operationplan.id,j.buffer.name,j.quantity,j.date,j.onhand)

You can execute a Python script either from the planning engine’s
executable frepple(.exe), or you can run it from the standard Python
executable and load the planning engine as an extension module.