SQLMesh Renderer¶
Renders SQLMesh models into clean SQL via subprocess, then parses with SqlParser.
SqlMeshRenderer
¶
SqlMeshRenderer(sql_parser=None)
Renders sqlmesh models into ParseResult objects via subprocess.
Runs an inline Python script inside the sqlmesh project's own virtualenv
to load the project, render every model to SQL, and output JSON to stdout.
The rendered SQL is then parsed by SqlParser. This avoids requiring
sqlmesh as a direct dependency of the indexer.
Initialise the renderer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sql_parser
|
SqlParser | None
|
|
None
|
Source code in src/sqlprism/languages/sqlmesh.py
176 177 178 179 180 181 182 183 | |
render_project_raw
¶
render_project_raw(
project_path,
env_file=None,
variables=None,
gateway="local",
dialect="athena",
sqlmesh_command="uv run python",
venv_dir=None,
)
Render all models and return raw SQL + column schemas (no parsing).
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Tuple of (models_dict, column_schemas_dict) where models maps |
dict[str, dict[str, str]]
|
model_name -> rendered_sql and column_schemas maps |
tuple[dict[str, str], dict[str, dict[str, str]]]
|
model_name -> {col_name: data_type}. |
Source code in src/sqlprism/languages/sqlmesh.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | |
render_project
¶
render_project(
project_path,
env_file=None,
variables=None,
gateway="local",
dialect="athena",
sqlmesh_command="uv run python",
venv_dir=None,
schema_catalog=None,
)
Render all models in a sqlmesh project.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_path
|
str | Path
|
Path to the sqlmesh project directory (containing config.yaml) |
required |
env_file
|
str | Path | None
|
Path to .env file to source before loading context |
None
|
variables
|
dict[str, str | int] | None
|
Extra sqlmesh variables (e.g. {"GRACE_PERIOD": 7}) |
None
|
gateway
|
str
|
Gateway name to use (default "local" — uses duckdb, no remote deps) |
'local'
|
dialect
|
str
|
SQL dialect for rendering output |
'athena'
|
sqlmesh_command
|
str
|
Command to run python in the sqlmesh venv (default: "uv run python") |
'uv run python'
|
venv_dir
|
str | Path | None
|
Directory to run from (where .venv lives). Auto-detects if not set. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, ParseResult]
|
Dict mapping model name -> ParseResult |
Source code in src/sqlprism/languages/sqlmesh.py
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
render_models
¶
render_models(
project_path,
model_names,
env_file=None,
variables=None,
gateway="local",
dialect="athena",
sqlmesh_command="uv run python",
venv_dir=None,
schema_catalog=None,
)
Render specific models in a sqlmesh project.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_path
|
str | Path
|
Path to the sqlmesh project directory |
required |
model_names
|
list[str]
|
List of model names to render (passed as filter to render script) |
required |
env_file
|
str | Path | None
|
Path to .env file to source before loading context |
None
|
variables
|
dict[str, str | int] | None
|
Extra sqlmesh variables |
None
|
gateway
|
str
|
Gateway name to use (default "local") |
'local'
|
dialect
|
str
|
SQL dialect for rendering output |
'athena'
|
sqlmesh_command
|
str
|
Command to run python in the sqlmesh venv |
'uv run python'
|
venv_dir
|
str | Path | None
|
Directory to run from (where .venv lives) |
None
|
schema_catalog
|
dict | None
|
Optional schema catalog for column resolution |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, ParseResult]
|
Dict mapping model name -> ParseResult |
Source code in src/sqlprism/languages/sqlmesh.py
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | |