> [!warning] Private Preview
> This feature is, as of 2025-04-01, on private preview and **not available for most organizations**.
To deploy [[SQL User Defined Function|UDFs]] written in [[Python]] in [[BigQuery]], by:
- Defining an appropriate `entrypoint` in the script,
- Defining a [[Python]] version (I only tested it with 3.11),
- Defining a `packages=[...]` option that declares all the dependencies to be installed.
- Defining the body as a triple-quoted raw string (prefixed with `r"""`)
```sql
CREATE OR REPLACE FUNCTION
`cartodb-on-gcp-datascience.dvicente.PYTHON_MULTIPLY`
(
x FLOAT64,
y FLOAT64
)
RETURNS FLOAT64
LANGUAGE python
OPTIONS (
entry_point='multiply_handler',
runtime_version='python-3.11'
)
AS r"""
def multiply_handler(x, y):
return x*y
""";
SELECT `cartodb-on-gcp-datascience.dvicente.PYTHON_MULTIPLY`(2, 4) AS test;
```
Defining the function is very fast, while the actual execution takes long the first time and the stays at ~15 sec.