Skip to content

Conversation

Seunghan-Jung
Copy link
Contributor

Description

It would be great if YamlConfigSettingsSource could support loading settings from a specific nested key within a YAML file.

Use Case

Often, YAML files contain configuration for multiple environments or sections, such as:

A_service:
  key: "A_key"
 
B_service:
  key: "B_key"

In this case, it would be useful to load settings from a specific key, for example, development, rather than requiring separate YAML files for each environment.

Suggested Feature

Allow an optional argument (e.g., nested_key) to be passed to YamlConfigSettingsSource like this:

YamlConfigSettingsSource(settings_cls, yaml_file="config.yaml", yaml_nested_key="A_service")

This would tell the source to load settings from config["development"] instead of the root.

Benefits
• Reduces the need for multiple YAML files
• Simplifies environment-specific configuration management
• Aligns with how many existing tools and frameworks organize config

@hramezani
Copy link
Member

Thanks @Seunghan-Jung for the PR.

I left some comments. please update

@hramezani
Copy link
Member

Thanks @Seunghan-Jung

@hramezani hramezani merged commit dff3f02 into pydantic:main Apr 21, 2025
18 checks passed
@Seunghan-Jung
Copy link
Contributor Author

Thanks @hramezani

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants