Requests is a Python library used inside a Snowflake Python UDF to call an external HTTP API and return its response for pipeline enrichment. section 7.2.1
A UDF can use requests to retrieve customer reviews through this sequence:
- Register requests in the UDF packages parameter and import it in the Python handler. section 7.2.1
- Retrieve the API key from the configured Snowflake secret. section 7.2.1
- Construct the Yelp reviews endpoint from the supplied business alias. section 7.2.1
- Call requests.get with the URL and bearer-token authorization, then return response.json(). section 7.2.1
Listing 7.1 The definition of the UDF
create or replace function GET_CUSTOMER_REVIEWS(business_alias varchar)
returns variant
language python
runtime_version = 3.10
handler = 'get_reviews'
external_access_integrations = (YELP_API_INTEGRATION)
secrets = ('yelp_api_token' = YELP_API_TOKEN)
packages = ('requests')
AS #1
The UDF definition registers Python 3.10, the handler, external access integration, secret mapping, and requests package. section 7.2.1
Listing 7.2 The body of the UDF
$$ #1
import _snowflake
import requests
def get_reviews(business_alias):
api_key = _snowflake.get_generic_secret_string('yelp_api_token')
url = f'''https://api.yelp.com/v3/businesses/{business_alias}/reviews'''
response = requests.get(
url=url,
headers = {'Authorization': 'Bearer ' + api_key}
)
return response.json()
$$;
The handler imports requests, retrieves the secret, builds the Yelp URL, sends an authenticated GET request, and returns JSON. section 7.2.1
Querying the UDF
After creation, select the function with a business alias such as boulangerie-julien-paris-3; the result is returned as a VARIANT containing the API response. section 7.2.1





