Skip to content

Create configuration in code

Create a Config in Python when you need configuration to be explicit, self-contained, or overridden programmatically. This is especially useful for tests and in situations where config files are impractical, such as Snowflake notebooks.

  • You have access to a Snowflake account with the RelationalAI Native App installed. If you are unsure, contact your Snowflake administrator.
  • You have working PyRel installation. See Set Up Your Environment for instructions.

To create a Config instance, call create_config() with config sections as keyword arguments. You can provide config sections as plain Python dictionaries or as typed config objects. Dictionaries are the closest match to the shape of raiconfig.yaml.

Use this style when you want the closest match to the shape of raiconfig.yaml:

import os
from relationalai.config import create_config
from relationalai.semantics import Model
cfg = create_config(
connections={
"sf": {
"type": "snowflake",
"authenticator": "username_password",
"account": os.environ["SNOWFLAKE_ACCOUNT"],
"warehouse": os.environ["SNOWFLAKE_WAREHOUSE"],
"user": os.environ["SNOWFLAKE_USER"],
"password": os.environ["SNOWFLAKE_PASSWORD"],
},
},
default_connection="sf",
)
# Use the config
m = Model("MyModel", config=cfg)

Use this style when you want IDE type hints and constructor-style validation:

import os
from relationalai.config import UsernamePasswordAuth, create_config
from relationalai.semantics import Model
cfg = create_config(
connections={
"sf": UsernamePasswordAuth(
account=os.environ["SNOWFLAKE_ACCOUNT"],
warehouse=os.environ["SNOWFLAKE_WAREHOUSE"],
user=os.environ["SNOWFLAKE_USER"],
password=os.environ["SNOWFLAKE_PASSWORD"],
),
},
default_connection="sf",
)
# Use the config
m = Model("MyModel", config=cfg)

Override file-based configuration with programmatic config

Section titled “Override file-based configuration with programmatic config”

You can keep a raiconfig.yaml for shared defaults and override only what changes at runtime. Use this when you want consistent defaults but still need per-run tweaks (tests, CI, notebooks). Programmatic overrides only affect the current Python process.

Call create_config() with the active_profile argument to choose which profile overlay to apply for this process:

from relationalai.config import create_config
from relationalai.semantics import Model
cfg = create_config(active_profile="prod")
# Verify the selected profile
m = Model("MyModel", config=cfg)
print(m.config.active_profile)

Apply one-off runtime overrides without editing files

Section titled “Apply one-off runtime overrides without editing files”

Pass explicit keyword arguments to create_config() to override file-based values for this process:

from relationalai.config import create_config
from relationalai.semantics import Model
cfg = create_config(
execution={
"metrics": True,
}
)
# Verify the override took effect
m = Model("MyModel", config=cfg)
print(m.config.execution.metrics)

For tests, prefer passing connections=... (and any other settings you need) so your test suite does not depend on a developer machine’s config files. This keeps tests hermetic and avoids surprises from a user’s local configuration. If you want to test file discovery behavior, treat that as an integration test and set up the expected files explicitly.