Was this helpful?

Apigee provides a range of out-of-the-box policy capabilities that address common API management requirements. However, there are some cases where your API requires custom behavior that is not covered by Apigee's standard policy palette. In these cases, Apigee exposes scripting interfaces to ease the task of implementing custom behaviors in the proxied API message flow. One approach is to attach your own Python script to an API flow, which the API Platform then executes at runtime.

A Python policy contains no actual code. Instead, a Python policy references a Python 'resource' and defines the Step in the API flow where the Python script executes. You can upload your JavaScript through the Management UI proxy editor, or you can include it in the /resources/py directory in API proxies that you develop locally.

System calls, for example network I/O, filesystem read/writes, current user info, process list, and CPU/memory utilization are not permitted by the security model. Although some such calls may be functional, they are unsupported and liable to be actively disabled at any time. For forward compatibility, you should avoid making such calls in your Python scripts.

For working sample Python scripts, see Samples reference.

Configuring a Python Script policy

Configure the Python Script policy using the following elements.

Field Name Description
ResourceURL Specifies the name of the Python script stored in the API proxy under /resources/py. Note: the filename must match exactly or an


error will be thrown at runtime.
IncludeURL (Optional) Scripts are evaluated strictly in the order of the IncludeURL list.

Policy schema

Each policy must conform to a policy schema. All policy constructs such as elements and attributes mentioned above are defined in a schema. To download the schema, click here.

Add new comment

Provide your email address if you wish to be contacted offline about your comment.
We will not display your email address as part of your comment.

We'd love your feedback and perspective! Please be as specific as possible.
Type the characters you see in this picture. (verify using audio)

Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.