Microsoft Fabric

Query Fabric SQL endpoints with an Azure AD service principal and write forecasts back over ODBC.

rb.sources.fabric connects deployed Rebase code to a Microsoft Fabric warehouse or lakehouse SQL endpoint. It shares the uniform data-source surface: read, read_bitemporal, and write.

Install

uv pip install "rebase-toolkit[fabric]"

Ships pyodbc. Declare it on the image you deploy:

image = rb.Image.python("3.12").uv_pip_install("rebase-toolkit[fabric]")

pyodbc additionally requires the ODBC Driver 18 for SQL Server system package (msodbcsql18) in the runtime image. The default Python images do not include it yet — for local runs install it via your OS package manager, and for deployed Fabric workloads contact us about a driver-enabled image.

Authenticate

Fabric authenticates with an Azure AD service principal (client-credentials flow over ODBC):

# 1. Register an app in Microsoft Entra ID, create a client secret, and grant
#    the principal access to the Fabric workspace (Viewer for reads,
#    Contributor for writes).

# 2. Find the SQL connection string on the warehouse/lakehouse
#    "SQL analytics endpoint" settings page.

# 3. Store the credentials as a Rebase secret bundle
rebase secret create acme-fabric \
    FABRIC_SQL_ENDPOINT=xyz.datawarehouse.fabric.microsoft.com \
    FABRIC_DATABASE=energy_wh \
    FABRIC_CLIENT_ID=xxxxxxxx-... \
    FABRIC_TENANT_ID=yyyyyyyy-... \
    FABRIC_CLIENT_SECRET=-  < secret.txt

Settings

SettingEnvironment variableRequired
serverFABRIC_SQL_ENDPOINT / FABRIC_SERVER
databaseFABRIC_DATABASE
client_idFABRIC_CLIENT_ID / AZURE_CLIENT_ID
client_secretFABRIC_CLIENT_SECRET / AZURE_CLIENT_SECRET
tenant_idFABRIC_TENANT_ID / AZURE_TENANT_IDoptional
driverFABRIC_ODBC_DRIVERoptional (default: ODBC Driver 18 for SQL Server)

Any setting can also be passed to the factory directly, or namespaced per connection as REBASE_SOURCE_<CONNECTION>_<FIELD> — see credential precedence.

Read

Parameters bind with ? placeholders (pyodbc):

import rebase as rb

src = rb.sources.fabric(connection="acme")
df = src.read(
    "SELECT ts, issued_at, load_mw FROM dbo.demand WHERE site = ?",
    params=["site-001"],
)

For backtesting, declare knowledge time so emflow can prove there is no leakage:

from rebase.sources import BitemporalSpec

spec = BitemporalSpec(valid_time="ts", knowledge_time="issued_at")
df = src.read_bitemporal(
    "SELECT ts, issued_at, load_mw FROM dbo.demand",
    spec,
)

Write forecasts back

Writes use batched INSERT statements with fast_executemany, committed atomically (rolled back on failure) — suited to forecast-sized results. mode="replace" truncates the table first:

src.write(forecast_df, "dbo.forecasts", mode="append")

For large bulk loads, use Fabric's native ingestion (e.g. COPY INTO from OneLake) instead.

Reference

On this page