Setting up a custom namespace
Custom namespaces serve as logical environments to package and isolate your data
foundation and analytical data product modules. Running inside a dedicated
custom namespace lets you manage configuration and deployment options
independently, providing isolation for your environment. A key benefit of this
separation is that you can pull future updates and enhancements from the
cortex namespace in Google Cloud Cortex Framework without overriding or corrupting
your custom modules. Create your custom modules within a dedicated namespace.
Custom namespace folder structure
The Cortex Framework namespace folders package and isolate custom module artifacts as Python implicit namespace packages.
The folder structure of a custom namespace is defined in the following table:
| Directory path | Purpose and description |
|---|---|
config/ |
Cortex deployment configuration (Required) Registers custom namespaces and modules in |
src/data_modules/CUSTOM_NAMESPACE/SYSTEM_TYPE/foundations/DATA_FOUNDATION_MODULE_NAME/ |
Data foundation modules Raw-to-foundation dataset transformations. Each data foundation resides in its own leaf directory (no Python files inside content blueprint folders) and consists of:
|
src/data_modules/CUSTOM_NAMESPACE/SYSTEM_TYPE/products/DATA_PRODUCT_MODULE_NAME/ |
Data product definitions Contains business logic and analytical models. Each product resides in its own leaf directory (no Python files inside content blueprint folders) and consists of:
|
src/data_modules/CUSTOM_NAMESPACE/includes/ |
Shared JavaScript helpers Shared Dataform JavaScript helpers live strictly at the namespace root ( |
src/data_modules/CUSTOM_NAMESPACE/assertions/ |
Shared SQL assertion templates Reusable custom SQL assertion templates shared across all modules in the namespace. Cortex Framework enforces a two-boundary layout for |
src/data_modules/CUSTOM_NAMESPACE/{builders,schemas,metadata}/ |
Root-anchored Python SDK plugins (Optional) All Python plugin code for a namespace lives strictly in these three root-anchored directories with zero
Pure-content namespaces (such as |
Replace the following:
CUSTOM_NAMESPACE: the name of your custom namespace directory undersrc/data_modules/, for example:sap_bookingdatamodeloracme_corp.SYSTEM_TYPE: the source system or domain folder name, for example:saporticketing.DATA_FOUNDATION_MODULE_NAME: the leaf directory name of your custom data foundation module, for example:ticketing_system.DATA_PRODUCT_MODULE_NAME: the leaf directory name of your custom data product module, for example:flights_usdorsales_performance.
Custom namespace configuration
You can define a new namespace
(CUSTOM_NAMESPACE) by extending the
corresponding section of the config.yaml file, creating a new directory under
src/data_modules/, and adding the new module code assets.
To make the Cortex Framework compiler aware of your custom
namespace and modules, register them in your global configuration file (for
example, config/config.yaml).
Register the namespace
Under data.namespaces, list each namespace you want active in the workspace.
Omit path for built-in namespaces (cortex, cortex_samples,
cortex_v6_compatibility) and installed third-party cortex.namespaces wheel
packages; specify path only for local custom namespaces or local override
overlays:
data:
namespaces:
- name: cortex
- name: CUSTOM_NAMESPACE # Name of custom namespace
path: ../src/data_modules/CUSTOM_NAMESPACE # Relative to config.yaml directory
Replace the following:
CUSTOM_NAMESPACE: the name of your custom namespace directory undersrc/data_modules/, for example:acme_corporsap_bookingdatamodel.
Cortex Framework applies the following rules when resolving
data.namespaces:
- Built-in and wheel-installed namespaces: Omit
path(- name: cortex,- name: cortex_samples,- name: cortex_v6_compatibility, or an installed third-party extension wheel such as- name: partner_erp). Settingpathto the shipped built-in namespace directory (or a missing legacysrc/data_modules/<builtin>path) emits aDeprecationWarningand isn't portable to wheel installations. Pointingpathto a separate local override directory is supported for multi-root override stacking. - Local custom namespaces: Always specify
path(relative to the configuration file directory) for local custom namespaces—even when the directory sits next to shipped namespaces undersrc/data_modules/in a source checkout—so the sameconfig.yamlworks consistently against wheel installations. - Strict allowlist versus auto-discovery:
- When
data.namespacesis present as a list, it acts as a strict allowlist: only listed namespaces are indexed byModuleCatalogand permitted for<pkg.mod>:<Class>builder imports. Settingnamespaces: []is a valid empty allowlist. - Omitting the
namespaceskey entirely enables auto-discovery of all installed built-in andcortex.namespacespackages. - Setting
namespaces: null(for example, leaving thenamespaces:key with every list item commented out) is rejected at validation time.
- When
Multi-root override stacking: To overlay local changes on top of an installed namespace, list multiple entries for the same
namein priority order (highest precedence first). For example:data: namespaces: - name: cortex path: ../local_overrides/cortex - name: cortexReserved names: Namespace names must be valid Python identifiers and can't use Python keywords, Python standard-library or built-in module names, reserved Cortex Framework internal package names (
common,tools,data_modules,dataform_includes, andtests), or installed third-party top-level Python packages (for example,google,yaml, orpydantic) unless that package registers the namespace through acortex.namespacesentry point.
Configure custom modules
Register your custom modules under data.modules.foundations or
data.modules.products. Use the dot-separated modulePath starting with your
namespace name (by convention, the four-segment format
<namespace>.<system_type>.{foundations|products}.<module_name>). Each
dataSourceId and dataTargetId value must match an id entry defined in the
data.datasets list
in config.yaml. Don't set the deprecated moduleType field in config.yaml:
data:
modules:
foundations:
- moduleId: CUSTOM_NAMESPACE_DATA_FOUNDATION_MODULE_NAME
modulePath: CUSTOM_NAMESPACE.ticketing.foundations.DATA_FOUNDATION_MODULE_NAME
dataSourceId: ticketing_data_raw
dataTargetId: data_foundation_ticketing
# Optional custom table settings file relative to 'config/'
# (replaces table_settings.default.yaml):
# tableSettings: "CUSTOM_NAMESPACE/ticketing/foundations/DATA_FOUNDATION_MODULE_NAME/table_settings.yaml"
products:
- moduleId: CUSTOM_NAMESPACE_DATA_PRODUCT_MODULE_NAME
modulePath: CUSTOM_NAMESPACE.ticketing.products.DATA_PRODUCT_MODULE_NAME
dependencyBindings:
# References an existing foundation moduleId
ticketingModule: CUSTOM_NAMESPACE_DATA_FOUNDATION_MODULE_NAME
dataTargetId: product_target
# Optional sparse custom table settings override relative to 'config/':
# tableSettings: "CUSTOM_NAMESPACE/ticketing/products/DATA_PRODUCT_MODULE_NAME/table_settings.yaml"
Replace the following:
CUSTOM_NAMESPACE: the name of your custom namespace, for example:ticketingoracme_corp.DATA_FOUNDATION_MODULE_NAME: the leaf directory name of your custom data foundation module, for example:ticketing_system.DATA_PRODUCT_MODULE_NAME: the leaf directory name of your custom data product module, for example:ticket_metricsorsales_performance.
Custom foundation modules support source systems without a prebuilt builder
(such as PostgreSQL) and require a custom FoundationBuilder subclass in
<namespace>/builders/. For a walkthrough, see
Data foundation module creation.
Because sap_foundation and sfdc_foundation are scoped to cortex, don't
create a custom foundation module for SAP ERP or Salesforce. Instead, register a
separate instance of the prebuilt foundation module
(cortex.sap.foundations.sap or cortex.sfdc.foundations.sfdc) and bind your
custom data product to its moduleId in dependencyBindings.
Custom namespace shared code
A custom namespace supports sharing code artifacts across its modules while enforcing clean architectural boundaries:
includes/(<custom_namespace>/includes/*.js): JavaScript helpers staged intodist/includes/during compilation (require("includes/<file>.js")) and discovered automatically throughModuleBuilder.get_includes_dirs(). Prefix shared filenames with your namespace (for example,acme_helpers.js) to prevent collisions.assertions/(<custom_namespace>/assertions/*.sql): Reusable SQL assertion templates discovered automatically throughModuleBuilder.get_shared_assertion_dirs(). Module-specific templates can also live inside a leaf blueprint directory (<module_dir>/assertions/).builders/,schemas/, andmetadata/: Root-anchored Python Plugin SDK extensions (<custom_namespace>/{builders,schemas,metadata}/) with zero__init__.pyfiles anywhere in the namespace. Import framework symbols exclusively fromcommon.sdk(nevercommon.registryor internalcommon.builders.*modules), keepschemas/free ofmetadata,builders, and Google Cloud client imports, and import metadata providers andgoogle.cloud.bigquerylazily inside runtime methods to preserve offline workspace resolution.
Understand and reference builders
Builders are Python classes that compile resolved workspace nodes into
Dataform outputs. Cortex Framework uses deterministic
ModuleCatalog and BuilderResolver discovery—without import-side-effect
registries (common.registry was removed in version 7.1)—to resolve the
builder: value in each module's manifest.yaml.
Builder resolution precedence
BuilderResolver resolves manifest.yaml builder: references in the
following order from highest to lowest precedence:
| Precedence | Source or syntax | Description |
|---|---|---|
| 1 | In-memory PluginOverrides |
PluginOverrides(builders=..., catalog_builders=...) supplied programmatically by tests or embedded callers. |
| 2 | Explicit class reference (<pkg.mod>:<Class>) |
Imports a specific class from the current namespace (for example, partner_erp.builders.custom_product:CustomProductBuilder) or a registered cortex.builders entry-point module. Cross-namespace references (<other_ns>.*:<Class>) are rejected. |
| 3 | Same-namespace qualified (<current_ns>.<name>) |
Matches plugin_id or plugin_aliases in <current_ns>/builders/ (for example, partner_erp.custom_product). Cross-namespace references (<other_ns>.<name>) are rejected. |
| 4 | Blueprint-local ./builder.py (Deprecated) |
Legacy co-located <module_dir>/builder.py. Emits a DeprecationWarning and is scheduled for removal in version 8.0. |
| 5 | Namespace-scoped shared builders (<current_ns>/builders/*.py) |
Matches unqualified <name> against plugin_id or plugin_aliases across the current namespace's mounted roots in priority order. |
| 6 | Built-in SDK builders and cortex.builders entry points |
Matches unqualified <name> against the three built-in SDK product builders (flat_product, versioned_product, sap_product) and installed third-party cortex.builders Python entry points. |
Built-in SDK builders and namespace scoping
Only three built-in SDK module builders are available globally to any custom namespace:
builder value (plugin_id) |
SDK class (common.sdk) |
Intended use |
|---|---|---|
flat_product |
FlatProductBuilder |
Flat definitions/*.js data products with flat top-level FlatProductTableSettings (custom-namespace Salesforce products, SAP Business Data Cloud Delta Sharing products, custom-source products, and multi-source composite products). Set materializationType explicitly on each table. |
versioned_product |
VersionedProductBuilder |
Variant-sectioned data products (common: plus <variant>:) that overlay definitions/<active_variant>/ atop definitions/common/ and infer supported variants automatically from table settings, definition subfolders, and manifest dependencies. |
sap_product |
SapProductBuilder |
SAP ECC and SAP S/4HANA versioned data products (SapProductTableSettings) shared across cortex, cortex_samples, cortex_v6_compatibility, and custom namespaces. |
Keep the following scoping and deprecation boundaries in mind when selecting a builder:
sfdc_productis scoped tocortex(not global):SfdcProductBuilderlives incortex/builders/sfdc_product_builder.py. BecauseBuilderResolverrejects cross-namespace builder references, custom namespaces building or extending Salesforce data products must usebuilder: flat_product(with explicitmaterializationTypeon each table). Similarly,sap_foundationandsfdc_foundationare scoped tocortex.- External catalog builders are
CatalogBuilderplugins:lakehouse_delta_shareandanalytics_hubare configured usingtype:underdata.modules.catalogsinconfig.yaml, not asbuilder:values in a module'smanifest.yaml. - Deprecated aliases and legacy paths (removed in version 8.0):
- Legacy product builder aliases
generic_product,composite_product,generic_composite_product, andsap_bdc_productemit aDeprecationWarning. Migrate tobuilder: flat_productand setmaterializationTypeexplicitly on each table (note thatsap_bdc_productis a legacy alias offlat_productand no longer defaults toview). - Blueprint-local
./builder.pyfiles (omittingbuilder:inmanifest.yaml) and nested<namespace>/<segment>/builders/directories (including<namespace>/common/builders/) emit aDeprecationWarning. Move custom builders to<namespace>/builders/and declareplugin_id.
- Legacy product builder aliases
For example, to use the built-in SAP data product builder in your custom
namespace, reference sap_product in manifest.yaml:
# src/data_modules/CUSTOM_NAMESPACE/sap/products/DATA_PRODUCT_MODULE_NAME/manifest.yaml
displayName: Custom SAP Data Product
description: Custom SAP analytical data product.
category: consumption_product
builder: sap_product
dependencies:
sapModule:
modulePath: cortex.sap.foundations.sap
supportedVersions:
- ecc
- s4
tables:
common:
- kna1
Replace the following:
CUSTOM_NAMESPACE: the name of your custom namespace, for example:sap_bookingdatamodelormycompany.DATA_PRODUCT_MODULE_NAME: the leaf directory name of your custom data product module, for example:flights_usd.
Namespace-scoped custom builders
If modules inside your custom namespace require a specialized compiler, declare
a builder plugin using the Tier 3 Python Plugin SDK (common.sdk):
- Create a builder file under
src/data_modules/<custom_namespace>/builders/my_builder.py(keeping zero__init__.pyfiles anywhere undersrc/data_modules/<custom_namespace>/). Subclass
FlatProductBuilder,VersionedProductBuilder, orFoundationBuilderfromcommon.sdkand setplugin_id(with optionalplugin_aliases,legacy_aliases,module_settings_schema_cls, andtable_settings_schema):# src/data_modules/acme_corp/builders/finance_product_builder.py from typing import ClassVar import pydantic from common.sdk import ( CortexBaseModel, FlatProductBuilder, FlatProductTableSettings, ) class FinanceProductSettings(CortexBaseModel): reporting_currency: str = pydantic.Field(alias="reportingCurrency") fiscal_year_start_month: int = pydantic.Field( default=1, alias="fiscalYearStartMonth" ) class AcmeFinanceProductBuilder(FlatProductBuilder): plugin_id: ClassVar[str | None] = "acme_finance_product" module_settings_schema_cls = FinanceProductSettings table_settings_schema = FlatProductTableSettingsReference the builder in your module's
manifest.yamlusingbuilder: acme_finance_product(or same-namespace qualifiedbuilder: acme_corp.acme_finance_product, or explicitbuilder: acme_corp.builders.finance_product_builder:AcmeFinanceProductBuilder).
Package plugins as Python wheels and test with PluginOverrides
To share reusable namespaces or standalone builders across multiple repositories
without copying files under src/data_modules/, publish a standard Python wheel
declaring cortex.namespaces or cortex.builders entry points in
pyproject.toml:
[project.entry-points."cortex.namespaces"]
partner_erp = "partner_erp_pkg:get_namespace_root"
[project.entry-points."cortex.builders"]
acme_product = "acme_cortex.builders:AcmeProductBuilder"
- A
cortex.namespacesentry point can resolve to apathlib.Pathorstrdirectory, a zero-argument callable returning a path, or an imported package with__path__. After installing the wheel, activate the namespace inconfig.yamlwithoutpath(- name: partner_erp), or omitdata.namespacesto auto-discover installed packages. - A
cortex.buildersentry point registers a standaloneModuleBuilderorCatalogBuildersubclass directly under its entry-point name.
For unit tests or embedded invocations, use PluginOverrides from common.sdk
to inject builders at the highest resolution precedence without writing files or
registering entry points:
from common.sdk import PluginOverrides
overrides = PluginOverrides(
builders={"custom_product": MyCustomProductBuilder},
catalog_builders={"custom_catalog": MyCustomCatalogBuilder},
)
In the next steps—Data foundation module creation and Data product module creation—you learn how to add foundation and data product modules to a custom namespace.
What's next
- Next step: Data foundation module creation
- Back to Overview