Skip to content

Create configuration in code

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.

Both approaches call create_config() and return the same validated Config object. Pass the result to Model using config=cfg. The examples set MY_DATABASE.MODEL_DEV as a development target; replace it with your dedicated database and schema.

Choose the style that best matches how you are building the settings:

ApproachChoose it when
Typed config objectsYou want IDE type hints, constructor arguments, and a more Python-native style.
Plain dictionariesYou want code that closely mirrors raiconfig.yaml, or you need to build sections and keys dynamically.

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",
deployment={
"public_schema": "MY_DATABASE.MODEL_DEV",
"identity": {"internal_schema": "MY_DATABASE.MODEL_DEV_META"},
},
)
m = Model("MyModel", config=cfg)
print(m.config.deployment.public_schema)

The printed value should be MY_DATABASE.MODEL_DEV, or the target you substituted. If a required environment variable is missing, Python raises KeyError; make it available to the Python process and rerun the example.

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

import os
from relationalai.config import (
DeploymentConfig,
IdentityConfig,
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",
deployment=DeploymentConfig(
public_schema="MY_DATABASE.MODEL_DEV",
identity=IdentityConfig(internal_schema="MY_DATABASE.MODEL_DEV_META"),
),
)
m = Model("MyModel", config=cfg)
print(m.config.deployment.public_schema)

The printed value should again match your development target. Use the same public_schema name when constructing DeploymentConfig and when reading the value in Python.

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 in tests, CI, or notebooks. Overrides apply to the returned configuration and models that receive it, not to unrelated models or later CLI commands. They do not edit the configuration file. If you deploy a model using that configuration, its settings determine the deployment target and behavior.

Call create_config() with the active_profile argument to select a named profile from the configuration file. The profile name must already exist in that profile section:

from relationalai.config import create_config
from relationalai.semantics import Model
cfg = create_config(active_profile="dev")
m = Model("MyModel", config=cfg)
print(m.config.active_profile)
print(m.config.deployment.public_schema)

With the linked file example, the printed values should be dev and MY_DATABASE.MODEL_DEV. If the profile is missing or the target differs, check the file’s profile.dev settings. This example selects a file-backed profile; do not assume that passing profile and connections dictionaries to create_config() applies the same profile overlay.

Apply one-off runtime overrides without editing files

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

Pass a development target to create_config() to override the file’s public and internal schemas while retaining other file-based deployment settings:

from relationalai.config import create_config
from relationalai.semantics import Model
cfg = create_config(
deployment={
"public_schema": "MY_DATABASE.MODEL_DEV",
"identity": {"internal_schema": "MY_DATABASE.MODEL_DEV_META"},
},
)
m = Model("MyModel", config=cfg)
print(m.config.deployment.public_schema)

The printed value should be MY_DATABASE.MODEL_DEV. If it differs, check that the model receives cfg rather than loading another configuration. This confirms the selected target, not that the schemas exist or your role can deploy to them.

Pass connection and deployment settings explicitly to make a test’s intended configuration clear. However, connections=... alone does not isolate a test: YAML files and environment settings can still supply values you omit. Control the working directory, configuration files, RAI_CONFIG_FILE_PATH, and relevant environment variables in your test setup. If you are testing file discovery itself, create the expected files explicitly rather than relying on a developer’s local configuration.