or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/kedro@1.1.x

docs

api

configuration.mddata-catalog-advanced.mddata-catalog.mdhooks.mdpipeline.mdrunners-advanced.mdrunners.md
index.md
tile.json

tessl/pypi-kedro

tessl install tessl/pypi-kedro@1.1.0

Kedro helps you build production-ready data and analytics pipelines

Agent Success

Agent success rate when using this tile

98%

Improvement

Agent success rate improvement when using this tile compared to baseline

1.32x

Baseline

Agent success rate without this tile

74%

utilities.mddocs/api/framework/

Framework Utilities API Reference

Utility classes and functions for extending KedroContext and framework components.

CatalogCommandsMixin

class CatalogCommandsMixin:
    """
    Mixin providing catalog-related command methods for context.
    Adds catalog inspection and pattern resolution capabilities.
    """

    def describe_datasets(
        self,
        pipelines: dict[str, Pipeline] | None = None,
    ) -> dict[str, dict[str, Any]]:
        """
        Generate detailed descriptions for all datasets in the catalog.

        Parameters:
        - pipelines: Optional dictionary of pipeline names to Pipeline objects.
                    Used to determine which datasets are used in pipelines.
                    Defaults to None

        Returns:
        Dictionary mapping dataset names to their descriptions, including:
        - type: Dataset class name
        - filepath: File path (if applicable)
        - layer: Data layer (if using DataCatalog layers)
        - used_in_pipelines: List of pipeline names using this dataset
        """

    def list_patterns(self) -> list[str]:
        """
        List all dataset factory patterns registered in the catalog.

        Returns:
        List of pattern strings (e.g., '{default}#csv', 'params:{name}')
        """

    def resolve_patterns(
        self,
        pipelines: dict[str, Pipeline] | None = None,
    ) -> dict[str, dict[str, Any]]:
        """
        Resolve dataset factory patterns and return information about resolved datasets.

        Parameters:
        - pipelines: Optional dictionary of pipeline names to Pipeline objects.
                    Used to determine which patterns are used in pipelines.
                    Defaults to None

        Returns:
        Dictionary mapping resolved dataset names to their configuration details
        """

compose_classes

def compose_classes(*classes: type) -> type:
    """
    Compose multiple classes into a single class using multiple inheritance.

    Useful for combining mixins with base context classes.

    Parameters:
    - classes: Variable number of classes to compose

    Returns:
    New composed class type

    Example:
    >>> CustomContext = compose_classes(KedroContext, CatalogCommandsMixin)
    """

Usage Examples

Using CatalogCommandsMixin

from kedro.framework.context import KedroContext
from kedro.framework.context.utilities import CatalogCommandsMixin, compose_classes

# Create custom context with catalog commands
CustomContext = compose_classes(KedroContext, CatalogCommandsMixin)

# Use in session
with KedroSession.create() as session:
    context = session.load_context()
    datasets = context.list_datasets(patterns=["^params:"])
    print(f"Parameters: {datasets}")

Composing Multiple Mixins

class CustomMixin:
    """Custom functionality mixin."""
    def custom_method(self):
        return "custom"

# Compose multiple mixins
EnhancedContext = compose_classes(
    KedroContext,
    CatalogCommandsMixin,
    CustomMixin
)

Advanced: Creating Custom Mixins

from kedro.framework.context import KedroContext
from kedro.framework.context.utilities import compose_classes

class MonitoringMixin:
    """Add monitoring capabilities to context."""

    def track_dataset_load(self, dataset_name: str):
        """Track when datasets are loaded."""
        print(f"Loading dataset: {dataset_name}")
        # Could send metrics to monitoring service

    def track_pipeline_execution(self, pipeline_name: str):
        """Track pipeline executions."""
        print(f"Executing pipeline: {pipeline_name}")
        # Could log to monitoring dashboard


class ValidationMixin:
    """Add data validation capabilities."""

    def validate_catalog(self):
        """Validate all datasets in catalog."""
        datasets = self.catalog.list()
        for ds_name in datasets:
            if not self.catalog.exists(ds_name):
                print(f"Warning: {ds_name} doesn't exist")


# Compose all mixins into custom context
MonitoredContext = compose_classes(
    KedroContext,
    CatalogCommandsMixin,
    MonitoringMixin,
    ValidationMixin
)

# Configure in settings.py
# CONTEXT_CLASS = MonitoredContext

Using CatalogCommandsMixin Methods

from kedro.framework.session import KedroSession

with KedroSession.create() as session:
    context = session.load_context()

    # List all dataset patterns
    patterns = context.list_patterns()
    print(f"Dataset patterns: {patterns}")

    # Describe all datasets
    datasets_info = context.describe_datasets()
    for name, info in datasets_info.items():
        print(f"{name}: {info['type']}")

    # Resolve pattern-based datasets
    resolved = context.resolve_patterns()
    print(f"Resolved datasets: {list(resolved.keys())}")

Method Resolution Order (MRO) with Mixins

When using compose_classes, understand the MRO:

# Order matters - mixins should come after base class
GoodContext = compose_classes(KedroContext, MixinA, MixinB)

# MRO: GoodContext -> KedroContext -> MixinA -> MixinB -> object

# If mixins have conflicting methods, earlier classes take precedence:
class MixinA:
    def method(self): return "A"

class MixinB:
    def method(self): return "B"

Context = compose_classes(KedroContext, MixinA, MixinB)
# Context().method() returns "A" (MixinA comes first)

When to Use Mixins vs Inheritance

Use Mixins when:

  • Adding optional functionality to context
  • Creating reusable components across projects
  • Avoiding deep inheritance hierarchies
  • Need to combine multiple behaviors

Use Direct Inheritance when:

  • Overriding core KedroContext behavior
  • Creating project-specific context with unique structure
  • Single, clear extension of functionality
# Mixin approach (composable, reusable)
Context = compose_classes(KedroContext, FeatureA, FeatureB)

# Inheritance approach (single purpose)
class ProjectContext(KedroContext):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.project_config = self._load_project_config()

See also:

  • KedroContext API - Base context class with mixin examples
  • Project Configuration - Configuring CONTEXT_CLASS setting