Get Started with RAI in a Local Python Environment
This guide walks you through the steps to set up a local Python development environment with the relationalai
package.
This setup is ideal for developing, testing, and deploying applications built with RAI.
Install Python
Section titled “Install Python”Select your operating system and follow the steps to install Python on your machine:
-
Navigate to the Python 3.11 download page, scroll down to the Files section, and download the Windows installer (64-bit).
-
Open the installer and follow the prompts to install Python 3.11. Check the box to add Python to your
PATH
. -
Open a terminal and verify that Python 3.11 is installed by running:
Terminal window python --versionThe output should be similar to
Python 3.11.9
.
-
Navigate to the Python 3.11 download page, scroll down to the Files section, and download the macOS 64-bit universal2 installer.
-
Open the installer and follow the prompts to install Python 3.11. Use the default installation options. When the installation is complete, double click the Install Certificates command in the Finder window.
-
Open a terminal and verify that Python 3.11 is installed by running:
Terminal window python3.11 --versionThe output should be similar to
Python 3.11.9
.
-
Use your distribution’s package manager to install Python 3.11. Alternatively, navigate to the Python 3.11 download page, scroll down to the Files section, download the Gzipped source tarball and compile it yourself. See the Python documentation for details.
-
Open a terminal and verify that Python 3.11 is installed by running:
Terminal window python3.11 --versionThe output should be similar to
Python 3.11.9
.
Install the relationalai
Package
Section titled “Install the relationalai Package”Create a new project directory and virtual environment
and use pip
to install the relationalai
package:
mkdir rai-getting-started && cd rai-getting-started
# Create a virtual environment.python -m venv .venv
# Activate the virtual environment..venv\Scripts\activate
# Install the relationalai package.python -m pip install relationalai
mkdir rai-getting-started && cd rai-getting-started
# Create a virtual environment.# NOTE: Replace `python3.11` with `python3.9` or `python3.10`# if you're using a different version.python3.11 -m venv .venv
# Activate the virtual environment.source .venv/bin/activate
# Install the relationalai package.# NOTE: The python command is now the one in your virtual environment, so# you can use it as `python` instead of `python3.11`.python -m pip install relationalai
Set Up Your Snowflake Connection
Section titled “Set Up Your Snowflake Connection”Run rai init
to connect to your Snowflake account and configure your project:
rai init
Follow the interactive prompts to enter your Snowflake credentials and choose the:
- Snowflake role:
Must have
SELECT
privileges on the Snowflake tables you’ll be accessing as well as theeng_admin
andall_schema_all
RAI application roles. - Snowflake warehouse: May be any warehouse.
- RAI native app: The default is
relationalai
, but yours may differ.
Run a Test Query
Section titled “Run a Test Query”Verify that the relationalai
package is installed and working correctly by running the following code:
import relationalai as rai
# Create a model named "MyFirstModel".model = rai.Model("MyFirstModel")
# Send a test query.with model.query() as select: response = select(1 + 1)
# The results are stored as a pandas DataFrame in the response.results attribute.print(response.results)# v# 0 2