Install and run PyRel
PyRel is RelationalAI’s Python package for building semantic models. In this guide you’ll install PyRel, connect a starter project to Snowflake, deploy its semantic model, and query it to answer a business question.
- Estimated time
- 15–30 minutes
- Prerequisites
- A Bash, zsh, or PowerShell terminal.
- Python 3.10–3.14 to run the project. If Python is not installed, the
uvsetup in this guide can download it automatically. - Network access to install Python packages and connect to your Snowflake account.
- An administrator must set up RelationalAI in Snowflake and grant your user the
RAI_DEVELOPERrole and access to a warehouse. - Your administrator must also prepare a deployment schema and a metadata schema for you. The same setup page creates both and grants the permissions you need to deploy models.
Create a project and install PyRel
Section titled “Create a project and install PyRel”Start by downloading the starter project and installing the Python packages it needs. The project includes a simple model, a query, and CSV data that you’ll work through in this guide.
You can install the required Python packages with uv or pip.
If you don’t have a preference, choose uv for fewer setup commands.
Your selection applies to commands throughout this guide:
-
If you haven’t already, download the starter project and save the ZIP file in your Downloads folder.
-
If you don’t have
uvinstalled, follow the installation instructions. -
Open a terminal and run these commands to extract the starter project, enter its folder, and install the required packages:
If you saved the ZIP file outside Downloads, update its path in the first command:
Terminal window unzip ~/Downloads/supplier-disruption.zipcd supplier-disruptionuv syncTerminal window Expand-Archive -Path $HOME\Downloads\supplier-disruption.zip -DestinationPath .Set-Location supplier-disruptionuv sync- Installs PyRel from the
relationalaipackage. - Installs
pandasto read the starter project’s CSV files. - Stores the project’s packages in
.venv, separate from other Python projects.
Run the remaining commands in this guide from the
supplier-disruptionfolder. You’ll configure the Snowflake connection in the next section.What if
uvcan’t find or download a supported Python version?uvnormally downloads a compatible Python version when you runuv sync. If it does not, install Python 3.13 throughuv, then try again:Terminal window uv python install 3.13uv syncIf Python cannot be downloaded, check your network connection. Your organization may also disable Python downloads through
uv. In that case, install Python 3.10 through 3.14 using your organization’s standard method.What if the terminal can’t find
uvafter installation?Close and reopen your terminal, then run:
Terminal window uv --versionIf the terminal still cannot find
uv, repeat theuvinstallation instructions for your operating system. Follow any message from the installer about updating yourPATH, then open another terminal. - Installs PyRel from the
-
Run these commands to check that PyRel and the
raicommand were installed:Terminal window uv run python -c "import relationalai; print('PyRel import OK')"uv run rai --version- The Python command prints
PyRel import OK. - The
raicommand prints the installed CLI version.
These results verify the installation only. You’ll test the Snowflake connection in the next section.
What if one of these commands fails?
Make sure your terminal is in the
supplier-disruptionfolder, runuv sync, and try both commands again. - The Python command prints
-
If you haven’t already, download the starter project and save the ZIP file in your Downloads folder.
-
Open a terminal and run these commands to extract the starter project, enter its folder, create a virtual environment, and install the required packages.
If you saved the ZIP file outside Downloads, update its path in the first command:
Terminal window unzip ~/Downloads/supplier-disruption.zipcd supplier-disruptionpython3 -m venv .venvsource .venv/bin/activatepython -m pip install "pandas>=2.0" "relationalai>=1.37.0,<2.0"Terminal window Expand-Archive -Path $HOME\Downloads\supplier-disruption.zip -DestinationPath .Set-Location supplier-disruptionpy -m venv .venv.venv\Scripts\Activate.ps1python -m pip install "pandas>=2.0" "relationalai>=1.37.0,<2.0"- Installs PyRel from the
relationalaipackage. - Installs
pandasto read the starter project’s CSV files. - Stores the project’s packages in
.venv, separate from other Python projects.
Run the remaining commands in this guide from the
supplier-disruptionfolder. You’ll configure the Snowflake connection in the next section. - Installs PyRel from the
-
Run these commands to check that PyRel and the
raicommand were installed:Terminal window python -c "import relationalai; print('PyRel import OK')"rai --version- The Python command prints
PyRel import OK. - The
raicommand prints the installed CLI version.
These results verify the installation only. You’ll test the Snowflake connection in the next section.
What if one of these commands fails?
Make sure your terminal is in the
supplier-disruptionfolder. Activate the virtual environment again using the command from the previous step, then reinstall the packages:Terminal window python -m pip install "pandas>=2.0" "relationalai>=1.37.0,<2.0"Try both verification commands again.
- The Python command prints
Optional: Set up a coding agent
Section titled “Optional: Set up a coding agent”RelationalAI Agent Skills give coding agents guided workflows for PyRel modeling, reasoning, deployment, and operations. You can complete this guide without a coding agent, but if you want agent assistance in later steps, execute this prompt with your agent to get started:
Read https://docs.relational.ai/agent-setup/prompt.md and follow the instructions to set up RelationalAI Agent Skills.After installation, start a new agent session so the skills are available. For client-specific installation and update instructions, see Install skill files.
Configure your project
Section titled “Configure your project”PyRel reads your connection settings from raiconfig.yaml in your project folder.
If your administrator sent you an invitation link with all required settings, the configuration below is ready to save.
Otherwise, the builder expands the fields you need to complete.
You can always expand Review or edit configuration details to inspect or change settings.
Then save the file, set any required credentials, and verify the connection.
Configure with a coding agent
If you installed RelationalAI Agent Skills, paste this prompt into the new agent session. The prompt updates when you change validated, non-secret settings in the form.
/rai-setup Configure this starter project. Ask me one question at a time for my account, warehouse, username, the authentication method my administrator told me to use, and my deployment schemas. Ask for additional non-secret settings only when that authentication method requires them. If I do not know which authentication method to use, explain the supported methods and tell me what to confirm with my administrator instead of guessing. This guide deploys the starter model, so the configuration must include deployment. Use the deployment schema my administrator prepared for me, as `DATABASE.SCHEMA`, and ask for it if you don't already have it. If you don't already have the metadata schema, suggest the deployment schema name followed by `_META`, and ask me to confirm it matches what my administrator set up. Add a top-level `deployment` block with `schema` and `meta_schema` set to those values, a `schedules.on_deploy` entry with `interval_s: 0` and `run_on_deploy: true`, and `outputs.schedule: on_deploy`.
Do not ask me to paste credentials into chat, and do not print, write, or commit credentials. If authentication requires a credential or browser action, tell me how to complete that step locally. Create or update `raiconfig.yaml` in the project root, but do not change other project files. Run `rai connect` from this project to validate the connection. If it fails, explain the error and help me fix it; do not report success unless the command succeeds.Whether you use the prompt or the form, review the generated configuration and confirm that rai connect succeeds before continuing.
Run the starter project
Section titled “Run the starter project”The starter project models a manufacturer that buys parts from several suppliers. Its completed semantic model connects suppliers to the parts they provide and the products that require those parts. You’ll use the included CSV data to answer a hypothetical question: If Northstar Components can’t deliver, which products depend on parts it supplies?
You’ve installed PyRel and verified that the project can connect to Snowflake. Next, you’ll deploy the semantic model to Snowflake, query it to find which products depend on parts supplied by Northstar Components, and then clean up.
Run and explain with a coding agent
If you installed RelationalAI Agent Skills, paste this prompt into the new agent session. The agent will not edit the starter files. It must ask before creating or removing Snowflake objects.
/rai-pyrel Read these documentation sections before acting:
- https://docs.relational.ai/get-started/install-and-run-pyrel/index.md#run-the-starter-project- https://docs.relational.ai/build/meet-pyrel/index.md#explore-the-starter-model- https://docs.relational.ai/build/meet-pyrel/index.md#understand-the-project-structure
Follow the Install and run PyRel guide’s **Run the starter project** steps for this supplied starter project. Do not edit files, install or upgrade packages, or display configuration or credential values. Use the project’s existing Python environment.
Before deployment, use the guide to explain which Snowflake objects and refresh tasks the command creates, then ask for my explicit confirmation. If I confirm, run the documented deployment command. Continue only if deployment succeeds.
Run the documented query and compare its output with the guide’s expected output. Stop if the command fails or the output does not match. Use the guide’s troubleshooting steps, explain the problem, and help me fix it; do not continue or report success as though the check succeeded.
After a successful query, run the guide’s cleanup preview without `--force` and tell me which deployment and metadata schemas it names. Ask for my explicit confirmation before forced teardown. If I do not confirm, leave the deployment in place and tell me that it remains. Afterward, use the project files and the Meet PyRel model walkthrough to briefly explain how the model, source mappings, relationships, and query produce the result. Preserve the guide’s limits on what the result establishes.Compare the command output with the expected output below before continuing.
Use the same terminal where you ran rai connect in Verify the connection, and make sure you're in the supplier-disruption folder. Then deploy the model, run the query, and clean up the deployment.
Deploy the model
First, deploy the model from your project folder using the
rai models deployCLI command:uvTerminal window uv run rai models deploy --path modelpipTerminal window rai models deploy --path model--path modelloads the model from themodelfolder.- PyRel deploys the model to the schema set by
deployment.schemainraiconfig.yaml. - PyRel creates output objects in Snowflake and fills them with the model's initial results.
- The
on_deployschedule inraiconfig.yamlfills the outputs once, when you deploy. It doesn't refresh them again on a timer. - The command keeps running until the first data load finishes.
What if deployment fails with a schema or permissions error?
Run
uv run rai config explain(pip:rai config explain) to check the names of the deployment and metadata schemas. Ask your administrator to confirm that your role has the required permissions on both schemas.What if authentication fails when I deploy the model?
Follow the troubleshooting guidance in Verify the connection. Once the connection check succeeds, retry the command.
What if deployment fails with an
EXECUTE TASKerror?The deploy fills its tables by running a Snowflake task, and your role needs permission to run it. Ask your administrator to run
GRANT EXECUTE TASK ON ACCOUNT TO ROLE RAI_DEVELOPER;. The script from Set up RelationalAI in Snowflake includes this grant. Then deploy again.Run the query
After deployment succeeds, run the query:
uvTerminal window uv run python find_affected_products.pypipTerminal window python find_affected_products.pyOutput product part0 Cold-chain tracker Control board1 Cold-chain tracker Temperature sensor2 Factory gateway Control board3 Smart thermostat Temperature sensorThe rows may appear in a different order.
If you see this output, PyRel successfully connected to Snowflake, loaded the semantic model, ran the query, and returned results. You can pause here, or read on to learn how the starter project's semantic model works.
What if Python can’t find the model module?
If you see
ModuleNotFoundError: No module named 'model', run the query command from your project folder. This is the folder containingpyproject.tomland themodelfolder.What if authentication fails when I run the query?
Follow the troubleshooting guidance in Verify the connection. Once the connection check succeeds, retry the command.
What if my results don’t match the example output?
If you see different combinations of products and parts, compare your project files with the code in Understand the project structure, or download a fresh starter project.
Clean up the deployment
When you’re done with the example, remove the deployed model from Snowflake. This deletes the objects RelationalAI created in your deployment and metadata schemas, but keeps both schemas. Next, Meet PyRel walks through the model and deploys it again.
Preview the cleanup:
uvTerminal window uv run rai models teardownpipTerminal window rai models teardownReview the preview and confirm that it names the deployment and metadata schemas you used for this example.
Then run the following command to remove the model:
uvTerminal window uv run rai models teardown --forcepipTerminal window rai models teardown --force
Nice work!
You installed PyRel, connected a project to Snowflake, deployed a semantic model, and used it to answer a business question. Next, find out how the model works.
Where to go next
Section titled “Where to go next”Choose a next step based on your goal: