Python.Run
----------

Runs a Python script.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [Python](component_Python.md) | [14.3](newinversion143.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "Python.Run"; PythonRef; ScriptText ) 

**MBS**( **"Python.Run";** /\* Runs a Python script. \*/  
**$PythonRef**; /\* The Python reference number.e.g. $python \*/   
**$ScriptText**) /\* The script text.e.g. "print('hello')" \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| PythonRef | The Python reference number. | $python |
| ScriptText | The script text. | "print('hello')" |

### Result

Returns result or error.

### Description

Runs a Python script.  
Pass the script text to run. Returns the result of the script.  
Before running a specific script, you may run a prefix script to setup sys.argv with the arguments you like to have. [Python.SetValue](PythonSetValue.md) can help to set a few global variables.  
  
The script runs within the FileMaker process. If you cause an endless loop, FileMaker freezes and needs to be force quit, so please always include an exit condition for your loops. Also if you get Python to crash, FileMaker will crash with it. Use [Shell](component_Shell.md) functions to run Python in a separate process.  
  
You may want to use [Process.SetCurrentDirectory](ProcessSetCurrentDirectory.md) function to set the current directory, so local files are found.  
### Examples

Try it:

 Set Variable \[ $r ; Value: MBS ("Python.Run"; $p ; "x = 1¶if x == 1:¶ # indented four spaces¶ print('x is 1.')") \]  
Set Variable \[ $o ; Value: MBS ("[Python.PrintOutput](PythonPrintOutput.md)"; $p ) \]  
If \[ MBS ("[IsError](IsError.md)") or $o ≠ "x is 1.¶" \]  
 Show Custom Dialog \[ "Failed to evaluate" ; $r \]  
 Exit Script \[ Text Result: \]  
End If  
### See also

- [IsError](IsError.md)
- [Process.SetCurrentDirectory](ProcessSetCurrentDirectory.md)
- [Python.PrintOutput](PythonPrintOutput.md)
- [Python.RunFile](PythonRunFile.md)
- [Python.SetValue](PythonSetValue.md)

### Release notes

- **Version 14.4**
    - Added [Python.RunFile](https://www.mbsplugins.eu/PythonRunFile.shtml) function.

### Example Databases

- [Python](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Python.shtml#2ScriptAnchor_)

### Blog Entries

- [Using Python in FileMaker](https://www.mbsplugins.de/archive/2024-06-24/Using_Python_in_FileMaker/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

Created 31st May 2024 , last changed 27th March 2026

  
[Python.ReleaseAll](PythonReleaseAll.md) - [Python.RunFile](PythonRunFile.md)

[HTML Version](PythonRun.shtml)