/
Run Python Scripts
Run Python Scripts
Thanks to the Python engine, you can execute Python code interacting with the partition from inside a Model Class logic.
To achieve this goal, follow these steps:
Decide which image flavour of the Python engine to run.
For your partition, request a new Calculation Engine of the type Python via PlatformManager. (The engine is then executed through a Job Trigger Calculation.)
Write your logic, script and test it.
Script Sample
Here is a small example of running a script in the Python engine from a Groovy logic
// These parameters will be available to the python job using `pyfx.get_context().parameters()`
def params = [
foo: 1234,
bar: 'baz',
]
// The python script you want to run
def script = '''
import pyfx
foo = pyfx.get_context().parameters()["foo"]
print(f'Hello {foo}')
''')
model.startJobTriggerCalculation(
'cregistry.pricefx.eu/engineering/pricefx-python-engine/datascience',
'latest', // NOTE for production you *should* change this to a specific version to avoid unexpected breakage
api.jsonEncode([script: script, parameters: params]),
'py'
)
Example Logic
You can find a complete sample logic using the Python engine at https://gitlab.pricefx.eu/logic/python-engine-samples-logic.
This logic can be used as a starting point for your own projects.
, multiple selections available,
Related content
Python Engine
Python Engine
More like this
Job Trigger Calculations
Job Trigger Calculations
More like this
Model Classes and Models Overview
Model Classes and Models Overview
Read with this
Logging and Debugging
Logging and Debugging
More like this
Customize Optimization
Customize Optimization
Read with this
Images Flavour
Images Flavour
Read with this
Found an issue in documentation? Write to us.