> ## Documentation Index
> Fetch the complete documentation index at: https://docs.omni.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Running Python with AI

> Use the Omni Agent to run Python for statistics, forecasting, and machine learning on your query results and uploaded files.

The Omni Agent can write and run Python code for analysis that is limited in SQL, such as statistics, forecasting, machine learning, and data reshaping. The code works on your query results and any CSV or Excel files you upload.

> [!NOTE]
>
> Python is available for Omni instances hosted on AWS in the United States, the EU, Canada, and Australia.

## Requirements

To use Python in the Omni Agent, you need:

* The [**Use Python**](https://docs.omni.co/administration/users/custom-roles.md#permissions-reference) permission. It is on by default for Queriers and above.
* The **Use Omni Agent** [AI setting](https://docs.omni.co/ai/settings/features.md) enabled
* To upload files, the **Omni Agent > File uploads** [AI setting](https://docs.omni.co/ai/settings/features.md#file-uploads) enabled

Organization Admins can restrict individual users or groups from using Python through a granular permission on a [custom role](https://docs.omni.co/administration/users/custom-roles.md).

## How it works

The agent decides when to use Python, and you can also ask for it directly. When a question needs Python:

**Step 1**

The Omni Agent gets the data. It runs new queries or uses the results already in the chat, together with any CSV or Excel files you uploaded.

**Step 2**

It writes Python code for the analysis.

**Step 3**

It runs the code in an isolated sandbox with no internet access. See [AI data security](https://docs.omni.co/ai/security.md#python) for how Omni isolates the code and what it shares with the LLM.

**Step 4**

It reads the output and answers your question in the chat. Any chart or table from the run appears with the answer, and you can open the code and logs of each Python step to check the work.

Charts appear as tiles in the browser chat. [Slack](https://docs.omni.co/integrations/omni-slack-agent.md) and the [API](https://docs.omni.co/api.md) return Python results as text only. A chart stays available for 30 days. After that, ask the agent to run the analysis again.

## Use cases

| Use case | Example prompt |
| - | - |
| Forecasting | "Forecast monthly recurring revenue for the next 6 months and show the confidence interval" |
| Statistical testing | "Did the new checkout flow change conversion? Test if the difference is significant" |
| Cohort analysis | "Build a retention curve for each signup month and estimate lifetime value" |
| Outlier detection | "Find the claims with amounts that are unusual for their category" |
| Segmentation | "Group customers into segments by order frequency and spend" |
| Driver analysis | "Which account attributes best predict churn?" |
| Fuzzy matching | "Find duplicate company names that are spelled differently" |
| File reconciliation | "Compare this budget spreadsheet with actual spend and list the gaps" |
| Combining results | "Join the support ticket results with the revenue results and correlate them" |

If you have the **Use Python** permission, the agent forecasts with Python's `statsmodels` library instead of the [built-in forecasting tool](https://docs.omni.co/ai/forecasting.md).

## Using uploaded files

If you have the **Use Python** permission, the agent uses Python to read every CSV and Excel file you [upload to the chat](https://docs.omni.co/ai/chat.md#uploading-files). The agent can combine a file with your query results, for example to compare a spreadsheet with warehouse data.

The agent runs Python each time it needs a file's contents. Each file can be up to 250 MB. Omni stores each file and keeps it available to the chat for 30 days.

## Available packages

Python code runs on Python 3.13 with these packages installed:

| Purpose | Packages |
| - | - |
| Data handling | pandas, polars, numpy, pyarrow |
| Statistics and forecasting | scipy, statsmodels |
| Machine learning | scikit-learn |
| Charts | Altair, matplotlib, seaborn |
| Excel files | openpyxl |

> [!NOTE]
>
> Need a package that isn't on this list? Let Omni support know, and we'll look into adding it.

## Next steps

* [Omni Agent](https://docs.omni.co/ai/chat.md): Learn more about the Omni Agent's chat capabilities
* [Generating visualizations with AI](https://docs.omni.co/ai/visualizations.md): Learn about AI-generated visualizations
* [Defining custom model roles](https://docs.omni.co/administration/users/custom-roles.md): Manage the permission that controls Python access
