VeloX Docs

Python plugins

Python 3 Data Source

Start a migration with data that your own Python 3 code reads from any system or generates.

Overview

The Python 3 Data Source plugin is in the Data Sources group on the left panel of the Designer. Use it at the start of a migration flow. Your Python code reads data from any third-party system, file, or API, or generates it, and the plugin passes the data to the next plugins record by record.

To process data in the middle or at the end of a migration, use Python Script 3 from the Non-SAP Targets group.

Python 3 compared with Python 2

Python 3 Data Source is the successor of the Python 2 Data Source plugin. Both plugins can be used in the same project, but their scripts are not interchangeable.

Python 2 Data Source Python 3 Data Source
Runtime IronPython 2 IronPython 3.4 (Python 3 syntax, for example f-strings)
Entry point Method dowork of class PyClass Function main(kwargs)
Input data and settings Serialized JSON strings Python dictionaries, ready to use
Return value Serialized JSON string Python dictionary with data and metadata keys
Password Manager clr.AddReference('VeloX.Core') and PasswordManager.GetCredentials(...) Built-in kwargs['pm'] helper
Editor Basic editor Code editor with minimap, code folding, autocompletion, search and replace, and a step-by-step debugger
Extra script — After Stop script that runs after the project stops

Setup and prerequisites

You don't need to install Python. The plugin ships with the IronPython 3.4 engine, which runs on .NET Framework 4.8 inside VeloXm.

When a script runs, the plugin searches for imported modules in these folders:

  • IronPython3\pmodules in the VeloXm installation folder (the installer puts the Python standard library here; you can add your own shared modules)
  • IronPython3 in the VeloXm installation folder
  • The template folder, if the plugin was installed from a template

The bundled standard library is the Python 3.4 one, so modules added later, such as typing, dataclasses or secrets, are missing. No third-party packages are bundled for Python 3. See Python Script 3 for details.

Settings

Click Settings on the plugin to open its configuration.

  • Description – a short description that is shown as the plugin's name on the canvas.

General tab

Field Description
Editor Opens the Python script editor. The editor is the same as in Python Script 3.
Notes Opens a notes window for any comments about the plugin.
Group Entries Processes all returned data as one entry instead of one entry per key. See How records are built.
Call script after project stopped Runs the After Stop script once the project stops.
Use Smart Fields Creator Adds settings to the plugin that run the Structure script to build fields. Works the same as in Python Script 3.

Debug tab

Select Use Debugger to open the Python Debugger automatically when a script runs. Then choose which scripts to debug:

  • Main Script – when the migration starts
  • Main Script Analyze – also when you click Analyze (available when Main Script is selected)
  • Structure Creation Script – when a smart field triggers the Structure script
  • Migration Completed Script – the After Stop script

Click Debug Main Script to run the main script in the debugger right away. In Debugger Settings, you can enter Input Data as JSON and select Analyze, Without Data, Simulation, and Stop On First Line. Use Continue (F5) and Step Into (F10) in the Python Debugger window.

Template tab

Click Create Template to save the plugin as a reusable template, or Update Template to update an existing one. The template window is the same as in Python Script 3.

Fields

The plugin has Import and Export fields. To add a field, open Fields, enter its name, and click Add or press Enter.

  • Import fields are parameters for your script, for example a file path or a selection value. The plugin is the first in the flow, so import fields take their values from Default Value. Select Convert To Upper Case to convert a string value to upper case.
  • Export fields describe the data your script returns. Use Table fields (lists of dictionaries) and Structure fields (dictionaries), and add String, Int, or Float fields inside them.

To change the data type of a field, click the field and select a new value in Data Type.

Key fields

Click a field inside an export table and select Key to make it a key field. A K flag appears on the field. The table that has key fields becomes the main table and is marked with an M flag.

Main script

The Main Script must define the function main(kwargs). The plugin calls it when you click Analyze and again when the migration starts.

Input parameters

Key Description
data Dictionary with the import field values.
settings Dictionary of smart field settings and their values.
structure Dictionary with the plugin field structure, with keys input_fields and output_fields.
environment Template folder path.
analyze True when the script is called by the Analyze button. False when the migration runs.
nodata True when Group Entries is selected and the script is called by Analyze. The script only needs to report whether data exists.
id Plugin ID.
description Plugin description.
version Plugin version (.NET Version object).
pm Password Manager helper. Use pm.get(name) to read an entry from the Password Manager, then entry.User, entry.Password, and entry.get_option(name).
ev Environment variables helper with get, set, remove, and remove_env methods.

Return value

Return a dictionary with these keys:

  • data – the export data. Keys are export table and structure names. Tables are lists of dictionaries, and structures are dictionaries.
  • data_exist – True or False. Return it instead of data when nodata is True.
  • metadata – optional status:
    • status – s (successful), e (error), or w (warning). If the status is e, the analysis or migration stops and the messages are shown.
    • messages – a list of messages. Each message has header, details, and an optional number.
def main(kwargs):
    metadata = {
        'status': 's',
        'messages': [{'header': 'Header message', 'details': 'Details message'}]
    }

    if kwargs['analyze'] and kwargs['nodata']:
        return {'data_exist': True, 'metadata': metadata}

    table = [
        {'string_field': 'value1'},
        {'string_field': 'value2'}
    ]
    return {'data': {'table_field': table}, 'metadata': metadata}

Each export table and structure in data must have the right type. Otherwise Analyze shows an error such as "table_field must be Table."

How records are built

Without Group Entries (default):

  1. When you click Analyze, the plugin calls the script and groups the rows of the main table by the key fields. Each unique key combination is one record. If no field is marked as a key, all visible fields of the table are used.
  2. When the migration starts, the plugin calls the script again and passes the records to the next plugins one by one. The multithreading parameter controls how many records run in parallel.

With Group Entries:

  1. When you click Analyze, the plugin calls the script with nodata set to True and uses data_exist to decide whether there is anything to load.
  2. When the migration starts, all returned data is passed to the next plugins as a single record.

If the analysis finds no data, VeloXm shows a "Data empty." notification.

Run-time details

  • Each call (Analyze, start, resume) loads the script into a new interpreter, so module-level variables are not kept between calls. Use the ev helper if you need to keep a value.
  • The script runs once per call, on one thread. Only the records that it returns are processed in parallel by the next plugins.
  • If the script returns an empty data when the migration starts, the run stops with the error "'data' is Empty".
  • The script doesn't receive a simulation flag. In simulation mode it returns its data as usual, and the target plugins receive the flag.
  • When you resume a paused run, the script is called again and records that were already processed are skipped. Records are matched by their row position in the main table, so return the rows in the same order.
  • An unhandled exception in the script stops the analysis or the run and shows the Python traceback in a message box.
  • When the debugger is on for the main script, each call opens a debugger window.

The load log has two extra columns: Data Line (the row number of the record in the main table) and Data Key (the key field values, separated by /). The returned data is written to the technical log only with the Detailed logging mode.

After Stop script

If Call script after project stopped is selected, the plugin runs the After Stop script once after the project stops. The script must define main(kwargs). It receives settings, structure, environment, description, id, version, pm, and ev, and doesn't need to return anything.

Structure script

When Use Smart Fields Creator is selected, the Structure script builds the plugin fields. It receives settings and structure as serialized JSON strings and returns a serialized JSON string. The format is the same as in Python Script 3.

Esc