Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Pydantic · Class

SettingsConfigDict

SettingsConfigDict configures Pydantic settings models through named options such as environment-variable prefixes and dotenv-file loading. It is used as model_config data on a settings class.

How it works

SettingsConfigDict is the settings-specific configuration dictionary used with Pydantic Settings models. It supplies options such as environment-variable naming and dotenv-file loading while retaining the typed configuration model used by Pydantic.

Syntax

model_config = SettingsConfigDict(**options)

Key points

  • Use SettingsConfigDict to declare model configuration for a Pydantic settings class.
  • The configuration is dictionary-shaped and provides named options rather than requiring a custom configuration class.
  • Configuration can control how extra input is handled during model initialization.
  • Strict validation can be enabled across a model through its configuration.

Common mistakes

  • Use it as configuration data rather than as a runtime model or validation schema.

Example: Configure a settings model

from pydantic_settings import BaseSettings, SettingsConfigDict

class AppSettings(BaseSettings):
    model_config = SettingsConfigDict(env_prefix="APP_", env_file=".env")
    debug: bool = False

settings = AppSettings()

The settings model reads configuration using the declared environment prefix and optional dotenv file.

When to use it

Map environment variables into typed settings

Environment-based application configuration

Load values from a dotenv file

Local development configuration

Declare validation and input-handling policy

Consistent model behavior

Interview questions

QWhat is SettingsConfigDict used for?

SettingsConfigDict is a typed configuration dictionary for settings models. It is assigned to model_config to control how configuration values are sourced and interpreted.

Follow-up: How would you make environment variables use a common prefix? Set env_prefix in SettingsConfigDict and name variables with that prefix.

QGive two examples of settings configuration options.

It lets a settings model declare options such as an environment-variable prefix and a dotenv file. The settings model then applies those options when it is instantiated.

Follow-up: What is the practical effect of env_file=".env"? Values from that dotenv file become one of the configured sources for settings loading.

QWhat kind of object underlies Pydantic configuration dictionaries?

The configuration is expressed as a dictionary-shaped object because the underlying configuration type is ConfigDict, documented as a TypedDict. This provides a structured set of named configuration fields rather than an untyped mapping.

Follow-up: Why prefer the documented configuration type over arbitrary keys? The typed fields communicate supported behavior and help catch misspelled or unsupported options.

  • ConfigDict
  • with_config
  • BaseSettings

Source: Configuration - Pydantic. Checked 2026-10-15.