Skip to content

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.

Before you begin, you must have access to:

  1. A compatible version of Python installed on your development machine.

    RelationalAI supports Python 3.10–3.13

    Python versions 3.14+ are currently not supported.

    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:

    1. Navigate to the Python 3.12 download page. Scroll down to the Files section. Download the Windows installer (64-bit).

    2. Open the installer and follow the prompts to install Python.

      Check the box in the installer window to add Python to your PATH.

    3. Open a terminal and verify that Python is installed by running:

      Terminal window
      python --version

      The output should be similar to Python 3.12.10.

  2. 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:

    1. Log in to your Snowflake account.
    2. Run the following SQL command in a worksheet:
      SHOW APPLICATIONS;
    3. 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.

  3. A Snowflake user with the RAI_DEVELOPER database role.

    How do I check my roles? To check your roles in Snowflake:

    1. Log in to your Snowflake account.
    2. Run the following SQL command in a worksheet:
      SHOW GRANTS TO USER <your_username>;
    3. Check the output in the name column for the RAI_DEVELOPER role.
      • 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.

PyRel is installed via the relationalai Python package.

PyRel requires relationalai version 1.0.0 or later!

If you have previously installed the relationalai package, you may need to upgrade it in order to use PyRel.

How do I check my installed version of the relationalai package? You can check your installed version with the following command:

Terminal window
pip show relationalai

If the version displayed is 0.X.X, then you need to upgrade to the latest version.

How do I upgrade the relationalai package? To upgrade to the latest version of the relationalai package, run the following command:

Terminal window
pip install --upgrade relationalai

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:

  1. Create a new project directory and navigate into it:

    Terminal window
    mkdir <my_project> && cd <my_project>
  2. Create a virtual environment:

    Terminal window
    python -m venv .venv
  3. Activate the virtual environment:

    Terminal window
    .venv\Scripts\activate
  4. Upgrade pip and install the relationalai Python package:

    Terminal window
    python -m pip install --upgrade pip
    python -m pip install relationalai

In order to use PyRel, you need to configure it to connect to your Snowflake account and the RAI Native App.

  1. In your terminal, run the rai init command to create a raiconfig.yaml file in your current directory:

    Terminal window
    rai init
  2. Fill in the required information in the raiconfig.yml to configure access to Snowflake and the RAI Native App.

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.

  1. Create a new folder for your project (for example, my-rai-project) and open it in your IDE. Inside that folder, create a new Python file named my_first_model.py. Make sure your IDE is using the Python environment where you installed relationalai. In VS Code, click the Python version in the bottom status bar and select the environment where you ran pip install relationalai.

  2. 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)
  3. Save the file and execute it.

    Your model and its data are not stored on your local machine. PyRel is a local client that interacts with the remote RAI Native App installed in your Snowflake account.

    The first time you query a model, a RAI reasoner is created in the RAI Native App. This reasoner stores your semantic model and its data, and executes your queries.