YOUSEFUL / FILEMAKER

Youseful Python: FAQ, examples and tutorial

Learning center · Function reference

Use YsflPython.fmx64 with a Windows CPython installation. These examples use a fresh external process for each call and only need Python's standard library.

FAQ

Is Python bundled? No. The plug-in discovers an installed Windows CPython. Set YSFL_PYTHON to your interpreter path before starting FileMaker, or supply python=<path> in the options. Embedded mode additionally needs python3.dll.

What is the difference between modes? inproc executes inside FileMaker, worker reuses one external Python process, and process starts a fresh external process per call. Variables do not survive process-mode calls.

What does Run return? The last expression's value. Lists and dictionaries become JSON; when there is no expression result, printed output is used. Error returns a traceback for a failed call.

Can I use pandas or another package? Install it in the same interpreter that the plug-in uses. Check Mode and Version when diagnosing an import failure. The examples below require no packages beyond the standard library.

Examples

Calculate a sum:

filemaker
YsflPy_Run ( "sum([1, 2, 3])" ; "mode=process timeout=15" )

Result: 6, provided the interpreter is found.

Return a dictionary:

filemaker
YsflPy_Run ( "{'brand': 'Youseful', 'count': 3}" ; "mode=process timeout=15" )

Result: JSON with brand equal to Youseful and numeric count equal to 3.

Tutorial

Standalone sample scripts: Python totals.

Goal: summarize a JSON array with a short Python calculation.

  1. Install/configure your Windows Python interpreter and confirm the first example works. If using an explicit path, put python=<actual path> on its own option line, before param=.
  2. Create Youseful - Python totals:
filemaker
Set Variable [ $rows ; Value: "[{\"qty\":3,\"price\":10},{\"qty\":1,\"price\":7}]" ]
Set Variable [ $code ; Value:
    "import json¶" &
    "rows = json.loads(fm.param)¶" &
    "{'count': len(rows), 'total': sum(row['qty'] * row['price'] for row in rows)}"
]
Set Variable [ $json ; Value: YsflPy_Run ( $code ; "mode=process timeout=15¶param=" & $rows ) ]
Set Variable [ $error ; Value: YsflPy_LastError ]
If [ $error <> 0 ]
    Set Variable [ $detail ; Value: YsflPy_Error ]
    Show Custom Dialog [ "Python failed" ; $detail ]
    Exit Script [ Text Result: $json ]
End If
Show Custom Dialog [ "Summary" ; JSONFormatElements ( $json ) ]
  1. Run it. Expected JSON, ignoring spaces and key order:
json
{"count":2,"total":37}
  1. Change the second price to 9 and rerun. Expected total: 39.

Troubleshooting

An interpreter-not-found result means no usable runtime was discovered. Supply the actual python.exe path rather than assuming the Python used by your shell is the one FileMaker will find. Keep data in fm.param; do not concatenate JSON into Python source. A new process imports modules again on every call.