kelp.meta¶
Reference for the MetaFramework — the reusable metadata loading backend that powers Kelp's runtime context. Frameworks subclass MetaFramework, declare a MetaProjectSpec, and call init() / get_context() to manage lifecycle and catalog access.
kelp.meta.MetaFramework
¶
Framework-specific API for metadata management.
This class provides a clean interface for frameworks to: - Define their metadata specifications - Initialize runtime contexts - Access framework-specific contexts
Each framework should define a subclass that sets spec as a class
attribute and then expose the class methods as their public API.
Example
from kelp.meta import MetaFramework, MetaProjectSpec, MetaObjectSpec from kelp.models.model import Model spec = MetaProjectSpec( ... framework_id="myframework", ... project_header="myframework_project", ... project_settings_model=MyConfig, ... object_specs=( ... MetaObjectSpec( ... root_key="my_models", ... project_config_key="models", ... path_attr="models_path", ... catalog_attr="models", ... model_class=Model, ... model_label="Model", ... ), ... ), ... ) class MyFramework(MetaFramework): ... spec = spec ctx = MyFramework.init() ctx = MyFramework.get_context()
init
classmethod
¶
init(
project_file_path=None,
target=None,
init_vars=None,
manifest_file_path=None,
refresh=False,
store_in_global=True,
)
Initialize and store framework runtime context.
This discovers the project configuration, loads metadata files, resolves variables, and stores the resulting context for later access.
When manifest_file_path is provided, the context is loaded directly
from a pre-built manifest JSON file, skipping all discovery,
rendering, and variable resolution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_file_path
|
str | None
|
Path to project file or directory. If None, auto-discovers from current working directory. |
None
|
target
|
str | None
|
Target environment name (e.g., "dev", "prod") to load target-specific variables from project file. |
None
|
init_vars
|
dict[str, Any] | None
|
Runtime variable overrides (highest priority). |
None
|
manifest_file_path
|
str | None
|
Path to a manifest JSON file. When provided, skips all source file loading and uses the snapshot instead. |
None
|
refresh
|
bool
|
If True, recreate context even if one already exists. |
False
|
store_in_global
|
bool
|
Whether to store context globally. |
True
|
Returns:
| Type | Description |
|---|---|
MetaRuntimeContext
|
The initialized runtime context containing project settings, |
MetaRuntimeContext
|
resolved variables, and metadata catalog. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If project file cannot be discovered. |
ValueError
|
If configuration is invalid or manifest is incompatible. |
Source code in src/kelp/meta/framework.py
get_context
classmethod
¶
Get framework runtime context, optionally auto-initializing.
If the context hasn't been initialized yet, you can either: - Set init=True to auto-initialize from current directory - Call init() explicitly with specific parameters first
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
init
|
bool
|
If True and context doesn't exist, auto-initialize from current working directory with default settings. |
False
|
Returns:
| Type | Description |
|---|---|
MetaRuntimeContext
|
The framework's runtime context. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If context hasn't been initialized and init=False. |
Source code in src/kelp/meta/framework.py
kelp.meta.MetaRuntimeContext
pydantic-model
¶
Bases: BaseModel
Runtime context for one framework namespace.
Attributes:
| Name | Type | Description |
|---|---|---|
framework_id |
str
|
Framework identifier owning this context. |
project_root |
str
|
Project root directory. |
project_file_path |
str
|
Resolved project file path. |
target |
str | None
|
Selected target name, if any. |
runtime_vars |
dict[str, Any]
|
Resolved runtime variables. |
project_settings |
Any
|
Framework-specific settings payload. |
catalog |
dict[str, list[Any]]
|
Loaded catalog payload for framework metadata objects. |
Show JSON schema:
{
"description": "Runtime context for one framework namespace.\n\nAttributes:\n framework_id: Framework identifier owning this context.\n project_root: Project root directory.\n project_file_path: Resolved project file path.\n target: Selected target name, if any.\n runtime_vars: Resolved runtime variables.\n project_settings: Framework-specific settings payload.\n catalog: Loaded catalog payload for framework metadata objects.",
"properties": {
"framework_id": {
"description": "Owning framework identifier",
"title": "Framework Id",
"type": "string"
},
"project_root": {
"description": "Project root path",
"title": "Project Root",
"type": "string"
},
"project_file_path": {
"description": "Project YAML file path",
"title": "Project File Path",
"type": "string"
},
"target": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Selected target",
"title": "Target"
},
"runtime_vars": {
"additionalProperties": true,
"description": "Resolved variables",
"title": "Runtime Vars",
"type": "object"
},
"project_settings": {
"default": null,
"description": "Framework-specific settings Pydantic model",
"title": "Project Settings"
},
"catalog": {
"additionalProperties": {
"items": {},
"type": "array"
},
"description": "Loaded metadata catalog payload",
"title": "Catalog",
"type": "object"
},
"generated_from_manifest": {
"default": false,
"description": "Whether this context was loaded from a manifest file",
"title": "Generated From Manifest",
"type": "boolean"
},
"manifest_file_path": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Path to the manifest file if loaded from one",
"title": "Manifest File Path"
}
},
"required": [
"framework_id",
"project_root",
"project_file_path"
],
"title": "MetaRuntimeContext",
"type": "object"
}
Config:
default:{'arbitrary_types_allowed': True}
Fields:
-
framework_id(str) -
project_root(str) -
project_file_path(str) -
target(str | None) -
runtime_vars(dict[str, Any]) -
project_settings(Any) -
catalog(dict[str, list[Any]]) -
generated_from_manifest(bool) -
manifest_file_path(str | None) -
_catalog_index_cache(MetaCatalog | None)
project_settings
pydantic-field
¶
Framework-specific settings Pydantic model
generated_from_manifest
pydantic-field
¶
Whether this context was loaded from a manifest file
manifest_file_path
pydantic-field
¶
Path to the manifest file if loaded from one
catalog_index
property
¶
Get indexed catalog for efficient name-based lookups.
The MetaCatalog instance is memoized so lazy-built name indices and filter-result caches persist across repeated accesses.
Returns:
| Type | Description |
|---|---|
MetaCatalog
|
MetaCatalog with lazy-built indices for each object type. |
kelp.meta.MetaCatalog
¶
Generic indexed catalog for metadata objects.
Provides name-based lookup and deduplication for any object types stored in a hierarchical dict structure. Maintains lazy-built indices per object type.
Example
catalog = MetaCatalog( ... raw_data={ ... "models": [{"name": "customers", ...}, ...], ... "metric_views": [{"name": "daily_orders", ...}, ...], ... } ... ) table = catalog.get("models", "customers") all_tables = catalog.get_all("models")
Initialize catalog from raw payload.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw_data
|
dict[str, list[Any]]
|
Dict keyed by object type (e.g., "models", "metric_views") with lists of objects as values. |
required |
Source code in src/kelp/meta/catalog_index.py
get
¶
Get object by name from catalog.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catalog_key
|
str
|
Object type key (e.g., "models", "metric_views"). |
required |
name
|
str
|
Object name to lookup. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The first object matching the name. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If object is not found. |
Source code in src/kelp/meta/catalog_index.py
get_all
¶
Get all objects from a catalog.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catalog_key
|
str
|
Object type key (e.g., "models", "metric_views"). |
required |
Returns:
| Type | Description |
|---|---|
list[Any]
|
List of all objects for this catalog key. |
Source code in src/kelp/meta/catalog_index.py
filter_by
¶
Return objects whose attr satisfies value.
When value is a dict the matching uses recursive dict-subset
semantics (see :func:_is_filter_match). Scalar value entries
use exact equality. Results are cached per
(catalog_key, attr, value) tuple.
This method is framework-agnostic — it does not know which attributes a model carries. Any attribute name can be passed.
Examples:
>>> catalog.filter_by("models", "meta", {"group": "abc"})
>>> catalog.filter_by("models", "schema_", "bronze")
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catalog_key
|
str
|
Object type key (e.g., |
required |
attr
|
str
|
Attribute name on the catalog objects to filter by. |
required |
value
|
Any
|
Expected value. A |
required |
Returns:
| Type | Description |
|---|---|
list[Any]
|
List of matching objects (may be empty). |
Source code in src/kelp/meta/catalog_index.py
get_index
¶
Get name -> object index for a catalog key.
Builds index lazily on first access.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catalog_key
|
str
|
Object type key. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict mapping object names to objects. |
Source code in src/kelp/meta/catalog_index.py
refresh_index
¶
Rebuild indices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catalog_key
|
str | None
|
Specific key to rebuild, or None to rebuild all. |
None
|
Source code in src/kelp/meta/catalog_index.py
kelp.meta.MetaProjectSpec
pydantic-model
¶
Bases: BaseModel
Specification describing one framework's project format.
Framework settings are intentionally isolated under project_header
(for example kelp_project or xy_project). Shared sections like
vars and targets remain framework-agnostic and are handled by
the generic loading pipeline.
Attributes:
| Name | Type | Description |
|---|---|---|
framework_id |
str
|
Unique framework identifier for isolated context storage. |
project_header |
str
|
Top-level YAML key containing framework settings. |
project_settings_model |
type[BaseModel]
|
Pydantic model class for framework settings. |
object_specs |
tuple[MetaObjectSpec, ...]
|
Metadata object specs to load and validate. |
project_filename |
str
|
Default project file name used for discovery. |
vars_key |
str
|
Shared vars section key. |
targets_key |
str
|
Shared targets section key. |
vars_overwrite_key |
str
|
Optional path key for overwrite vars file. |
target_var_name |
str
|
Built-in variable name used for selected target. |
Config:
arbitrary_types_allowed:True
Fields:
-
framework_id(str) -
project_header(str) -
project_settings_model(type[BaseModel]) -
object_specs(tuple[MetaObjectSpec, ...]) -
project_filename(str) -
vars_key(str) -
targets_key(str) -
vars_overwrite_key(str) -
target_var_name(str) -
resolve_runtime_settings(bool) -
settings_env_prefix(str) -
settings_spark_prefix(str) -
target_setting_key(str) -
project_file_setting_key(str) -
manifest_file_path_setting_key(str)
model_config
class-attribute
instance-attribute
¶
project_settings_model
pydantic-field
¶
Framework-specific Pydantic settings model
project_filename
pydantic-field
¶
Default project file name used for discovery
vars_overwrite_key
pydantic-field
¶
Shared key containing overwrite vars file path
target_var_name
pydantic-field
¶
Built-in variable name storing selected target
resolve_runtime_settings
pydantic-field
¶
Whether init_runtime should resolve target/project_file via meta settings sources (args/spark/env/defaults).
settings_env_prefix
pydantic-field
¶
Environment variable prefix for runtime settings resolution
settings_spark_prefix
pydantic-field
¶
Spark conf prefix for runtime settings resolution
target_setting_key
pydantic-field
¶
Settings key used to resolve runtime target
project_file_setting_key
pydantic-field
¶
Settings key used to resolve project file path
manifest_file_path_setting_key
pydantic-field
¶
Settings key used to resolve manifest file path
kelp.meta.MetaObjectSpec
pydantic-model
¶
Bases: BaseModel
Specification for one metadata object type.
Attributes:
| Name | Type | Description |
|---|---|---|
root_key |
str
|
YAML root key containing item list (for example |
project_config_key |
str
|
Key in project settings containing hierarchy defaults. |
path_attr |
str
|
Attribute in framework settings with metadata path(s). |
catalog_attr |
str
|
Output catalog key where parsed objects are stored. |
model_class |
type[Any]
|
Pydantic model class used for validation. |
model_label |
str
|
Human-readable label for diagnostics. |
preprocess |
Callable[[dict[str, Any], str | None], dict[str, Any]]
|
Optional hook to transform raw item payload before validation. |
Config:
arbitrary_types_allowed:True
Fields:
-
root_key(str) -
project_config_key(str) -
path_attr(str) -
catalog_attr(str) -
model_class(type[Any]) -
model_label(str) -
preprocess(Callable[[dict[str, Any], str | None], dict[str, Any]])