Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Dagster io Dagster Config Class

From Leeroopedia


Knowledge Sources
Domains Data_Engineering, Configuration
Last Updated 2026-02-10 00:00 GMT

Overview

Concrete configuration class system for runtime parameterization provided by the Dagster core library.

Description

The Config class is Dagster's base class for defining typed runtime configuration. It extends Pydantic's BaseModel (via MaskedPermissiveConfig), allowing users to define configuration schemas using standard Python type annotations. When an asset or op function declares a parameter of a Config subclass type, Dagster automatically validates user-provided configuration against the schema and injects the validated object at runtime.

The Config system integrates with the Dagster UI to generate configuration form fields, and with the run launcher to validate configuration before execution begins.

Usage

Import Config from the dagster package. Define a subclass with typed fields representing runtime parameters. Declare a parameter of the Config subclass type in your asset or op function. The framework handles validation, UI generation, and injection.

Code Reference

Source Location

  • Repository: dagster
  • File: python_modules/dagster/dagster/_config/pythonic_config/config.py

Signature

class Config(MaskedPermissiveConfig):
    """Base class for Dagster configuration. Subclass this to define typed config schemas."""
    pass

# Usage pattern:
class MyConfig(dg.Config):
    param1: str
    param2: int = 10
    param3: float = 0.5

Import

from dagster import Config

# or

import dagster as dg

class MyConfig(dg.Config):
    ...

I/O Contract

Inputs

Name Type Required Description
(user-defined fields) Any Python type Varies Fields defined on the Config subclass. Types are validated by Pydantic. Fields without defaults are required; fields with defaults are optional.

Outputs

Name Type Description
(injected object) Config subclass instance A validated configuration object injected as a parameter into the asset or op function at runtime.

Usage Examples

Basic Configuration

import dagster as dg

class SampleConfig(dg.Config):
    sample_size: int = 1000
    include_headers: bool = True

@dg.asset
def sampled_data(config: SampleConfig) -> dg.MaterializeResult:
    # config.sample_size and config.include_headers are validated and available
    data = load_data(limit=config.sample_size, headers=config.include_headers)
    return dg.MaterializeResult(metadata={"rows": len(data)})

AI Query Configuration

import dagster as dg

class AskAI(dg.Config):
    question: str

@dg.asset(deps=["embedded_docs"], kinds={"openai"})
def answer(config: AskAI, openai: OpenAIResource) -> dg.MaterializeResult:
    client = openai.get_client()
    response = client.chat.completions.create(
        model="gpt-4-turbo-preview",
        messages=[{"role": "user", "content": config.question}],
    )
    return dg.MaterializeResult(
        metadata={"answer": response.choices[0].message.content}
    )

Configuration with Nested Types

import dagster as dg

class ModelConfig(dg.Config):
    model_name: str = "random_forest"
    learning_rate: float = 0.01
    max_depth: int = 10
    feature_columns: list[str] = ["col_a", "col_b"]

@dg.asset(kinds={"python", "sklearn"})
def trained_model(config: ModelConfig) -> dg.MaterializeResult:
    model = train_model(
        name=config.model_name,
        lr=config.learning_rate,
        depth=config.max_depth,
        features=config.feature_columns,
    )
    return dg.MaterializeResult(
        metadata={"model": config.model_name, "accuracy": model.score}
    )

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment