It is possible to make API calls to external sources from Python functions, but doing so requires additional configuration. This configuration and external source usage are detailed below.
By default, Python functions are not allowed to call external APIs. To enable calling external systems from your Python function, you must configure a source in Data Connection to allow Foundry to connect with an external system.
For Python functions to connect to your source's external system securely, your source must be configured to enable exports and allow the import of your source into Code Repositories. Both of these can be configured by navigating to the source in Data Connection and opening the the Connection settings section. Here you will find the Code import configuration tab, where you can also configure an API name if your source does not yet have one. This API name will be used to reference your source in code.
It is not currently possible to access secrets and credentials stored in a source from a Python function.
To make API calls from a Python function, you must first import your source using the resource imports sidebar in a Python functions repository. Once imported, grant your functions access to the source by adding the source's API name to the sources
parameter of the @function
decorator.
With the source imported and declared in the function decorator, you can make external API calls to the system represented by that source.
An example of this is shown below:
Copied!1 2 3 4
@function(sources=["<SOURCE API NAME>"]) def my_external_function(name: str) -> str: response_string = requests.get('https://<API URL>').text return response_string
After publishing your function, you can use it to make external calls in Pipeline Builder and Workshop.
It is not currently possible to make API calls in function live preview, you will have to publish your function to test it.