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.

    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.

    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.

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. Open your IDE and create a new Python file named my_first_model.py in the same directory where you installed the relationalai package.

  2. Create a file named my_first_model.py and 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.