pydantic-multi-source-settings

Consolidate Python app configuration from env, .env, and remote services.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/dragonkid/dotfiles --skill pydantic-multi-source-settings
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pydantic-multi-source-settings
Source: https://github.com/dragonkid/dotfiles/tree/main/claude/skills/learned/pydantic-multi-source-settings
Command: npx skills add https://github.com/dragonkid/dotfiles --skill pydantic-multi-source-settings

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps applications acquire configuration from multiple sources with a clear precedence order: environment variables, .env files, and a remote configuration service, ensuring consistent, cached settings across the app.

Core Features & Use Cases

  • Multi-source precedence: Environment variables override remote defaults, with .env as a fallback.
  • Singleton settings: Provides a cached, single instance of the Settings model for the app lifecycle.
  • Remote integration: Supports remote config services (e.g., Apollo, Consul) via a model_validator hook to fetch missing values at startup.

Quick Start

Define a Settings class using BaseSettings, configure env_prefix and env_file, implement a loader to fetch missing values from the remote service, and call get_settings() to obtain the singleton.

Frequently Asked Questions about pydantic-multi-source-settings

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I load Pydantic settings from environment variables, .env files, and a remote config service?

To load Pydantic settings from multiple sources, define a BaseSettings class with env_prefix and env_file, then use a model_validator hook to fetch missing values from the remote service. This establishes a clear precedence: environment variables override remote defaults, with .env as a fallback.

What is the best way to maintain a cached Pydantic settings instance across my application lifecycle?

The best way to maintain cached Pydantic settings is to use an lru_cache-wrapped getter function. Calling get_settings() provides a singleton instance of your Settings model, ensuring consistent configuration throughout the app lifecycle without redundant initializations.

Does Pydantic BaseSettings support fetching missing configuration values from remote services like Apollo or Consul?

Yes, Pydantic BaseSettings supports fetching missing values from remote config services like Apollo or Consul. You implement a loader within a model_validator hook to pull remote values during startup, integrating them with local environment variables and .env file settings.

How do I configure case_sensitive settings and env_prefix when consolidating Pydantic configuration?

You configure case_sensitive settings and env_prefix directly within your BaseSettings class definition. This ensures environment variables and .env file keys are matched accurately according to your desired case sensitivity and naming conventions during the multi-source configuration consolidation.

Why does my environment variable not override the remote configuration value in my Python application?

If an environment variable does not override a remote configuration value, the multi-source precedence order may be misconfigured. The correct hierarchy ensures environment variables take priority, overriding remote defaults, while the .env file acts as a fallback for missing values.