> For the complete documentation index, see [llms.txt](https://dev.ubidots.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dev.ubidots.com/ubifunctions/runtimes/python.md).

# Python

Python runtimes include the standard [Python batteries](https://docs.python.org/3/tutorial/stdlib.html), plus additional libraries depending on the selected runtime: `Lite`, `Base`, `Full`, `ML Inference`, or `ML Classical`. Library versions vary by Python version, as shown in the tables below.

{% hint style="info" %}
The heavier the runtime, the longer your UbiFunction takes to execute or update after changes. **We recommend using the `Lite` version unless a heavier runtime is strictly required.**
{% endhint %}

### Lite <a href="#h_5860f0afab" id="h_5860f0afab"></a>

| Library  | Python 3.9 | Python 3.11 | Python 3.13 | Python 3.14 |
| -------- | ---------- | ----------- | ----------- | ----------- |
| requests | 2.32.5     | 2.32.5      | 2.32.5      | 2.32.5      |

### Base <a href="#h_3496c389a7" id="h_3496c389a7"></a>

All libraries included in the `Lite` runtime, plus:

| Library    | Python 3.9 | Python 3.11 | Python 3.13 | Python 3.14 |
| ---------- | ---------- | ----------- | ----------- | ----------- |
| pytz       | 2025.2     | 2025.2      | 2025.2      | 2025.2      |
| msgpack    | 1.1.2      | 1.1.2       | 1.1.2       | 1.1.2       |
| httpx      | 0.28.1     | 0.28.1      | 0.28.1      | 0.28.1      |
| aiohttp    | 3.13.2     | 3.13.2      | 3.13.2      | 3.13.2      |
| lxml       | 6.0.2      | 6.0.2       | 6.0.2       | 6.0.2       |
| numpy      | 2.0.1      | 2.2.6       | 2.2.6       | 2.3.5       |
| pandas     | 2.3.2      | 2.3.2       | 2.3.2       | 2.3.3       |
| protobuf   | 6.33.1     | 6.33.1      | 6.33.1      | 6.33.1      |
| python-aqi | —          | 0.6.1       | 0.6.1       | 0.6.1       |

### Full <a href="#h_a6f43dab0f" id="h_a6f43dab0f"></a>

{% hint style="success" %}
Only available to [Enterprise license](https://ubidots.com/enterprise) holders and above.
{% endhint %}

All libraries included in the `Base` runtime, plus:

| Library      | Python 3.9 | Python 3.11 | Python 3.13 |
| ------------ | ---------- | ----------- | ----------- |
| scrapy       | 2.12.0     | 2.13.2      | 2.12.0      |
| matplotlib   | 3.9.4      | 3.10.3      | 3.10.1      |
| arrow        | 1.3.0      | 1.3.0       | 1.3.0       |
| pymongo      | 4.10.1     | 4.13.2      | 4.11.3      |
| psycopg      | 3.2.3      | 3.2.9       | 3.2.6       |
| pyodbc       | 5.2.0      | 5.2.0       | 5.2.0       |
| stripe       | 10.12.0    | 11.6.0      | 12.0.0      |
| pytesseract  | 0.3.13     | 0.3.13      | 0.3.13      |
| holidays     | 0.57       | 0.59        | 0.69        |
| zeep         | 4.3.1      | 4.3.1       | 4.3.1       |
| scipy        | 1.13.1     | 1.15.3      | 1.15.2      |
| openpyxl     | 3.1.5      | 3.1.5       | 3.1.5       |
| statsmodels  | 0.14.4     | 0.14.4      | 0.14.4      |
| openai       | 1.59.3     | 1.87.0      | 1.70.0      |
| cryptography | 43.0.3     | 44.0.3      | 44.0.2      |

`Full` functions get 1,000 MB of memory by default.

### ML Inference

Use `ML Inference` to run a model you trained elsewhere. It includes [LiteRT](https://ai.google.dev/edge/litert) for TensorFlow Lite models (`.tflite`) and [ONNX Runtime](https://onnxruntime.ai/) for ONNX models (`.onnx`).

{% hint style="info" %}
The ML runtimes are enabled per account. To enable them, [reach out to our support team](https://help.ubidots.com/en/articles/4683984-need-support-find-ubidots-in-app-chat-channel).
{% endhint %}

All libraries included in the `Lite` runtime, plus:

| Library        | Python 3.11 | Python 3.14 |
| -------------- | ----------- | ----------- |
| numpy          | 2.2.0       | 2.4.6       |
| pandas         | 2.3.0       | 3.0.3       |
| ai-edge-litert | 1.4.0       | 2.1.5       |
| onnxruntime    | 1.16.3      | 1.26.0      |
| pillow         | 11.0.0      | 12.2.0      |
| pydantic       | 2.9.0       | 2.13.4      |
| httpx          | 0.28.1      | 0.28.1      |
| protobuf       | 7.35.0      | 7.35.1      |
| joblib         | 1.5.3       | 1.5.3       |
| cryptography   | 48.0.0      | 48.0.1      |

`ai-edge-litert` is Google's successor to `tflite-runtime`, with the same `Interpreter` API. If your code imports `tflite_runtime`, change only the import:

```python
from ai_edge_litert.interpreter import Interpreter  # replaces tflite_runtime.interpreter
```

#### Models trained in other frameworks

If you trained your model in scikit-learn, XGBoost, LightGBM, or PyTorch, export it to ONNX and run it with ONNX Runtime. Those training libraries are not included in the runtime. You don't need them to run an exported model.

| Framework          | Export tool                                                                       |
| ------------------ | --------------------------------------------------------------------------------- |
| scikit-learn       | [skl2onnx](https://onnx.ai/sklearn-onnx/)                                         |
| XGBoost, LightGBM  | [onnxmltools](https://github.com/onnx/onnxmltools)                                |
| PyTorch            | [`torch.onnx.export`](https://pytorch.org/docs/stable/onnx.html)                  |
| TensorFlow / Keras | [tf2onnx](https://github.com/onnx/tensorflow-onnx), or convert to TensorFlow Lite |

#### Example

Upload the model file to your UbiFunction (see [Binary files](/ubifunctions/storage/mutiple-files.md#binary-files)), then load it by its path relative to the function's root directory. Load the model outside `main` so that consecutive executions reuse it:

{% tabs %}
{% tab title="TensorFlow Lite" %}

```python
import numpy as np
from ai_edge_litert.interpreter import Interpreter

interpreter = Interpreter(model_path="model.tflite")
interpreter.allocate_tensors()
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()


def main(args):
    x = np.array(args["values"], dtype=np.float32).reshape(input_details[0]["shape"])
    interpreter.set_tensor(input_details[0]["index"], x)
    interpreter.invoke()
    prediction = interpreter.get_tensor(output_details[0]["index"])
    return {"prediction": prediction.tolist()}
```

{% endtab %}

{% tab title="ONNX" %}

```python
import numpy as np
import onnxruntime as ort

session = ort.InferenceSession("model.onnx")
input_name = session.get_inputs()[0].name


def main(args):
    x = np.array([args["features"]], dtype=np.float32)
    prediction = session.run(None, {input_name: x})[0]
    return {"prediction": prediction.tolist()}
```

{% endtab %}
{% endtabs %}

### ML Classical

Use `ML Classical` to fit and run classical machine learning and statistical models inside the function, for example to cluster or score recent sensor data, detect outliers, or forecast a time series.

{% hint style="info" %}
The ML runtimes are enabled per account. To enable them, [reach out to our support team](https://help.ubidots.com/en/articles/4683984-need-support-find-ubidots-in-app-chat-channel).
{% endhint %}

All libraries included in the `Lite` runtime, plus:

| Library      | Python 3.14 |
| ------------ | ----------- |
| numpy        | 2.4.6       |
| pandas       | 3.0.3       |
| scipy        | 1.17.1      |
| scikit-learn | 1.9.0       |
| statsmodels  | 0.14.6      |
| pydantic     | 2.13.4      |
| joblib       | 1.5.3       |

#### Example

This function forecasts the next values of a series with Holt-Winters exponential smoothing:

```python
import pandas as pd
from statsmodels.tsa.holtwinters import ExponentialSmoothing


def main(args):
    series = pd.Series(args["values"], dtype="float64")
    model = ExponentialSmoothing(series, trend="add").fit()
    forecast = model.forecast(args.get("steps", 12))
    return {"forecast": forecast.tolist()}
```

### Memory for ML runtimes

ML functions start with the default 128 MB of memory, which is often not enough to load a model. We recommend at least 1,024 MB. The CPU available to a function also grows with its memory, so more memory makes inference faster, especially when many executions run at the same time. To increase your function's memory, [reach out to our support team](https://help.ubidots.com/en/articles/4683984-need-support-find-ubidots-in-app-chat-channel).

The ML runtimes do not include full TensorFlow, Keras, PyTorch, or Transformers, and they do not run on GPUs. Train deep learning models outside Ubidots and run them here with `ML Inference`.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://dev.ubidots.com/ubifunctions/runtimes/python.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
