Use PyRel With an IDE
This guide walks you through the steps to set up a local Python development environment for using PyRel in an IDE (integrated development environment) such as VS Code, Cursor, or any other IDE of your choice.
Prerequisites
Section titled “Prerequisites”Before you begin, you must have access to:
-
A compatible version of Python installed on your development machine.
How do I install Python?
Click on the tab for your operating system and follow the steps to install Python.
To install Python on Windows, follow these steps:
-
Navigate to the Python 3.12 download page. Scroll down to the Files section. Download the Windows installer (64-bit).
-
Open the installer and follow the prompts to install Python.
-
Open a terminal and verify that Python is installed by running:
Terminal window python --versionThe output should be similar to
Python 3.12.10.
To install Python on macOS, follow these steps:
-
Navigate to the Python 3.12 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. 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 is installed by running:
Terminal window python3.12 --versionThe output should be similar to
Python 3.12.10.
To install Python on Linux, follow these steps:
-
Use your distribution’s package manager to install Python 3.12. Alternatively, navigate to the Python 3.12 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 is installed by running:
Terminal window python3.12 --versionThe output should be similar to
Python 3.12.10.
-
-
A Snowflake account with the RelationalAI (RAI) Native App installed.
How do I know if the RAI Native App is installed?
To check if the RAI Native App is installed in your Snowflake account:- Log in to your Snowflake account.
- Run the following SQL command in a worksheet:
SHOW APPLICATIONS;
- Check the output for an application named
RELATIONALAI.- If you see it listed, the RAI Native App is installed.
- If not, you need to install it.
How do I install the RAI Native App?
See Install the RAI Native App for Snowflake for instructions. -
A Snowflake user with the
RAI_DEVELOPERdatabase role.How do I check my roles?
To check your roles in Snowflake:- Log in to your Snowflake account.
- Run the following SQL command in a worksheet:
SHOW GRANTS TO USER <your_username>;
- Check the output in the
namecolumn for theRAI_DEVELOPERrole.- If you see it listed, you have the required role.
- If not, contact your Snowflake account administrator to have the role assigned to you. See Set Up User Access for the RAI Native App for more information.
Step 1: Install PyRel
Section titled “Step 1: Install PyRel”PyRel is installed via the relationalai Python package.
Click on the tab below that corresponds to your operating system to see the installation instructions.
To install PyRel in your project on a Windows machine, follow the steps below:
-
Create a new project directory and navigate into it:
Terminal window mkdir <my_project> && cd <my_project> -
Create a virtual environment:
Terminal window python -m venv .venv -
Activate the virtual environment:
Terminal window .venv\Scripts\activate -
Upgrade
pipand install therelationalaiPython package:Terminal window python -m pip install --upgrade pippython -m pip install relationalai
To install PyRel in your project on a macOS machine, follow the steps below:
-
Create a new project directory and navigate into it:
Terminal window mkdir <my_project> && cd <my_project> -
Create a virtual environment:
Terminal window python3.12 -m venv .venvReplace
python3.12withpython3.11orpython3.10if you’re using a different version. -
Activate the virtual environment:
Terminal window source .venv/bin/activate -
Upgrade
pipand install therelationalaiPython package:Terminal window python -m pip install --upgrade pippython -m pip install relationalaiNote that you can use
pythoninstead ofpython3.XXhere since the virtual environment is activated.
To install PyRel in your project on a Linux machine, follow the steps below:
-
Create a new project directory and navigate into it:
Terminal window mkdir <my_project> && cd <my_project> -
Create a virtual environment:
Terminal window python3.12 -m venv .venvReplace
python3.12withpython3.11orpython3.10if you’re using a different version. -
Activate the virtual environment:
Terminal window source .venv/bin/activate -
Upgrade
pipand install therelationalaiPython package:Terminal window python -m pip install --upgrade pippython -m pip install relationalaiNote that you can use
pythoninstead ofpython3.XXhere since the virtual environment is activated.
Step 2: Configure PyRel
Section titled “Step 2: Configure PyRel”In order to use PyRel, you need to configure it to connect to your Snowflake account and the RAI Native App.
-
In your terminal, run the
rai initcommand to create araiconfig.yamlfile in your current directory:Terminal window $ rai init -
Fill in the required information in the
raiconfig.ymlto configure access to Snowflake and the RAI Native App.
Step 3: Create Your First Model
Section titled “Step 3: Create Your First Model”PyRel lets you define a semantic model of your business domain using Python syntax. You can then use this model to write and run queries to answer business questions.
-
Open your IDE and create a new Python file named
my_first_model.pyin the same directory where you installed therelationalaipackage. -
Create a file named
my_first_model.pyand add the following code to create a simple semantic model:my_first_model.py from relationalai.semantics import Model# === 1. CREATE A SEMANTIC MODEL ===# Initialize a new model.model = Model("MyFirstModel")# Create concepts and relationships.Person = model.Concept("Person")Person.friend = model.Relationship(f"{Person} is friends with {Person:friend}")# Define some sample data.model.define(alice := Person.new(name="Alice"),bob := Person.new(name="Bob"),alice.friend(bob) # Alice is friends with Bob)# === 2. QUERY YOUR SEMANTIC MODEL ===df = model.select(Person.name, Person.friend.name).to_df()print(df) -
Save the file and execute it.