Defining a provider
Create a Python file underproviders/ in your project. A provider is a class that subclasses Provider from sqlbuild.providers:
Provider extends pydantic-settings BaseSettings, so provider fields are validated and can be populated from environment variables automatically.
Provider name
Each provider has a runtime name used for injection. By default, the name is derived from the class name by converting tolower_snake_case:
WarehouseClientbecomeswarehouse_clientSlackNotifierbecomesslack_notifier
provider_name:
lower_snake_case). They share the global project resource namespace with models, sources, seeds, functions, loaders, tasks, assets, checks, and hooks.
Using providers in Python nodes
Providers are injected into Python node functions by parameter name. Add a parameter whose name matches the provider’s runtime name:warehouse_client to the discovered provider with that name, sets it up if it hasn’t been already, and passes it to the function.
You can also type-annotate the parameter for IDE support and compile-time validation:
- Loaders (
@loader) - Tasks (
@task) - Assets (
@asset) - Checks (
@check)
Using providers in hooks
Python lifecycle hooks also support provider injection by parameter name:HookContext via ctx.providers:
Using providers via context
All Python node contexts (TaskContext, AssetContext, CheckContext, LoaderContext) and HookContext expose a ctx.providers container for name-based access:
ctx.providers) are equivalent. Parameter injection is more explicit and enables type checking; ctx.providers is useful when provider access is conditional or dynamic.
Lifecycle
Providers follow a lazy setup, reverse-teardown lifecycle scoped to the command invocation:- Discovery - on compile, SQLBuild discovers all
Providersubclasses underproviders/and validates their settings (from environment variables or field defaults). - Lazy setup -
setup(ctx)is called the first time a provider is accessed during a build, not at startup. Providers that are never used are never set up. - Teardown - after the command completes,
teardown()is called on all providers that were set up, in reverse setup order. Teardown runs even if the build failed.
setup and teardown are optional. A provider with only field declarations and no lifecycle methods is valid; it acts as a validated configuration object.
Configuration from environment variables
BecauseProvider extends pydantic-settings BaseSettings, fields without defaults are read from environment variables. The environment variable name matches the field name in uppercase:
.env file support, and nested settings.
Discovery rules
- Provider classes are discovered from
.pyfiles underproviders/recursively - Files named
__init__.pyor starting with_are skipped - Each concrete (non-abstract) subclass of
Provideris registered - Provider names must be globally unique across project resources
- Settings are validated at discovery time. Missing required fields (without environment variables set) raise a discovery error immediately, not at runtime
Plan output
When providers are used by Python nodes or hooks,sqb plan shows a Providers section listing each provider and its consumers:
--verbose to see which specific nodes consume each provider.

