Python

Note: These scripts are not sandboxed like V8js so care must be taken to prevent unwanted access to system resources, e.g. the file system of the host server that is running DreamFactory. Please see example scripts for Python for more information. Python needs to installed on the host server to run your Python scripts.

Contents

Requirements

DreamFactory Python scripting requires 'bunch' package to be installed on server. Your server might not include pip by default but it should be available via your Linux version's package manager, for instance on Debian/Ubuntu:

$ sudo apt install python-pip

Once installed you can install bunch like so:

$ sudo pip install bunch

Accessing Resources

DreamFactory passes in two additional objects for use in the scripts.
In Python, these resources are represented as native dictionaries and can be accessed as normal. See the examples below.

Debugging

Python's httplib module is used to perform the network calls, meaning you have access to all of the debugging capabilities of this module within your Python scripts. For instance if you are calling another API endpoint within your script and something isn't going right, you can return the HTTP status code and reason like so:

Including Other Scripts

In your Python script you can use other Python libraries/modules by including them using the import statement. For example import json. Note: if you are going to use a third party module, you will need to make sure that the module is installed on the server where your DreamFactory instance is running.