Contact Us 1-800-596-4880

Python Component Reference

python component 48x32

Overview

The Python component can be used to enhance web-based transaction systems and further extend the capabilities of web-based applications. As an example, you can write a custom script in Python for an application, save it in a separate file and then configure the Python component to reference the file. Or, after placing the Python component on the Studio canvas you can type in the script through the Python Pattern Properties pane. The Python script is generally executed at runtime (client-side request) and the custom logic embedded in the script could trigger an application to execute a database transaction, or modify your web-page interface. The Python component is very similar to Java, Groovy and Ruby components.
Python also allows the developer to configure interceptors and alter the values or references of particular properties in a script. Interceptors are configured to provide additional services to a message as it flows through a component. For example, a developer can configure an interceptor to execute scheduling or logging of a particular event while a message is being processed. The Python component also includes a custom interceptor which allows you to configure settings for Spring elements. Use the Advanced tab to access Script Properties, then define the value and reference for a particular property in the script.
When using Python, typing-in or appending a script to the component is the only configuration required.

Configuration

If the application referencing Python expects a response, use a request-response endpoint to enable the Python component to communicate in a two-way fashion (See: below).

PythonHTTP2way

If Python is used to simply pass data to the client, the transaction is referred to as one-way. No response is required from the client (See: below).

PythonFile1way

General Tab

To configure the Python component, from the Message Flow canvas double-click the Python icon to open the Pattern Properties pane. Use the General tab to specify the file location of the script or simply type in the script on the script text window. The scripting engine is Python.

+ image::pythonpropgen.png[PythonPropGen]

+

Panel Description

Display

Defaults to the generic component name. Change the Display Name, which must be alpha-numeric, to reflect the component’s specific role, i.e., Welcome Page Python Script.

Script

Select one of the following ways to reference the script.
Script Text: Type the script the component will load directly into this space.
Script File: Enter the location of the script to be loaded by the component. The file can reside on the classpath or the local file system.

Advanced Tab

Use the Advanced tab to optionally configure interceptors and (depending on the interceptor) enter Spring values. You also have the option to specify script properties, which are key/value pairs used to alter or change properties in the script. See the [MULETEMP:Script Component Reference] page for information on using the advanced tab.

PythonPropAdv2
Panel Description

Interceptors Management

Interceptors enable the developer to provide additional services to the component such as the ability to log transactions and the ability to log the time for each transaction. Use the Add Custom Interceptor to create a custom interceptor that can reference Spring objects. The Interceptor Stack enables you to bundle multiple interceptors. Use the Interceptor Stack to apply multiple interceptors on a Python component. The interceptors will be applied in the order defined in the stack.

Script Properties

Configure these parameters to define your attribute keys and their associated values. This enables the Python component to quickly look up a value associated with a key.

Documentation tab

The Documentation tab lets you add optional descriptive documentation for the Python component. Each component has a Documentation tab and optional Description field.

PythonPropDoc
Property Description

Documentation

Enter all relevant information regarding this Python component. This information is displayed in Studio when you hover over the component icon on the Message Flow canvas.

Mule ESB Reference

Refer to the generic [MULETEMP:Script Component Reference] to see how a script works with one-way and request-response endpoints.

For more information see the Mule ESB page Scripting Module.