Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion docs/concepts/models/python_models.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,45 @@ Note that arguments must be specified explicitly - variables cannot be accessed

## Python model blueprinting

A Python model can also serve as a template for creating multiple models, or _blueprints_, by specifying a list of key-value dicts in the `blueprints` property. Please refer to the Python-based SQL model [documentation page](./sql_models.md#Python-model-blueprinting)) for more details.
A Python model can also serve as a template for creating multiple models, or _blueprints_, by specifying a list of key-value dicts in the `blueprints` property. In order to achieve this, the model's name must be parameterized with a variable that exists in this mapping.

For instance, the following model will result into two new models, each using the corresponding mapping in the `blueprints` property:

```python linenums="1"
import typing as t
from datetime import datetime

import pandas as pd
from sqlmesh import ExecutionContext, model

@model(
"@{customer}.some_table",
kind="FULL",
blueprints=[
{"customer": "customer1", "field_a": "x", "field_b": "y"},
{"customer": "customer2", "field_a": "z", "field_b": "w"},
],
columns={
"field_a": "text",
"field_b": "text",
"customer": "text",
},
)
def entrypoint(
context: ExecutionContext,
start: datetime,
end: datetime,
execution_time: datetime,
**kwargs: t.Any,
) -> pd.DataFrame:
return pd.DataFrame(
{
"field_a": [context.var("field_a")],
"field_b": [context.var("field_b")],
"customer": [context.var("customer")],
}
)
```

## Examples
### Basic
Expand Down