Python
Since Camel 3.19
Camel allows Python to be used as an Expression or Predicate in Camel routes.
For example, you can use Python in a Predicate with the Content-Based Router EIP.
Python Options
The Python language supports 2 options, which are listed below.
| Name | Default | Java Type | Description |
|---|---|---|---|
| Sets the class of the result type (type from output). | ||
|
| Whether to trim the source code to remove leading and trailing whitespaces and line breaks. For example when using DSLs where the source will span across multiple lines and there may be additional line breaks at both the beginning and end. |
Variables
| Variable | Type | Description |
|---|---|---|
this | Exchange | the Exchange is the root object |
context | CamelContext | the CamelContext |
exchange | Exchange | the Exchange |
exchangeId | String | the exchange id |
message | Message | the message |
body | Message | the message body |
headers | Map | the message headers |
properties | Map | the exchange properties |
Dependencies
To use Python in your Camel routes, you need to add the dependency on camel-python which implements the Python language.
If you use Maven, you could add the following to your pom.xml, substituting the version number for the latest release.
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-python</artifactId>
<version>x.x.x</version>
</dependency> Spring Boot Auto-Configuration
When using python with Spring Boot make sure to use the following Maven dependency to have support for auto configuration:
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-python-starter</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency> The component supports 2 options, which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
Whether to enable auto configuration of the python language. This is enabled by default. | Boolean | ||
Whether to trim the source code to remove leading and trailing whitespaces and line breaks. For example when using DSLs where the source will span across multiple lines and there may be additional line breaks at both the beginning and end. | true | Boolean |