python-configuration

Implement typed Python configuration management using environment variables and pydantic-settings.

Updated Apr 23, 2026
One-click install
npx skills add https://github.com/SanketAdlak/PDMProjectDesign --skill python-configuration-sanketadlak
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-configuration
Source: https://github.com/SanketAdlak/PDMProjectDesign/tree/main/.agents/skills/python-configuration
Command: npx skills add https://github.com/SanketAdlak/PDMProjectDesign --skill python-configuration-sanketadlak

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires pydantic, pydantic-settings.

What problem does it solve? Hardcoded configuration values and scattered os.getenv() calls make Python applications fragile, insecure, and hard to deploy across environments. This Skill provides patterns for externalizing configuration into typed, validated settings that fail fast at startup. ## Core Features & Use Cases - Typed Settings with Pydantic: Define a central Settings class using pydantic-settings that loads, coerces, and validates environment variables at application boot. - Secrets and Environment Management: Handle secrets via .env files, Docker secrets directories, and namespaced variables for dev, staging, and production environments. - Advanced Patterns: Nested configuration groups, custom validators, computed environment flags, and comma-separated list parsing. - Use Case: When bootstrapping a new FastAPI or backend service, use this Skill to create a config module that crashes immediately with a clear error if DATABASE_URL or API_SECRET_KEY is missing, instead of failing mid-request. ## Quick Start Set up a pydantic-settings configuration module for my Python app that loads database credentials and API keys from environment variables with startup validation.

Frequently Asked Questions about python-configuration

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

FAQPage Schema
How do I manage environment variables in Python with pydantic-settings?

Define a Settings class inheriting from pydantic-settings BaseSettings, declaring each field with a type and alias matching the environment variable name. Instantiating the class once at startup loads, coerces, and validates all values, and you import that singleton throughout the app.

How to validate required configuration at application startup in Python?

Declare required fields without defaults in your pydantic-settings class, then wrap instantiation in a try/except for ValidationError. On failure, print each missing field with its error message and exit immediately, so misconfiguration crashes at boot rather than mid-request.

Does pydantic-settings support nested configuration from environment variables?

Yes, pydantic-settings supports nested models by setting env_nested_delimiter to a double underscore in model_config. Variables like DATABASE__HOST and DATABASE__PORT then map automatically into a nested DatabaseSettings model.

Can pydantic-settings read secrets from Docker secret files?

Yes, set secrets_dir in model_config to the mounted secrets path such as /run/secrets. If an environment variable is not set, pydantic-settings looks for a file with the field name in that directory and reads its contents as the value.

Why should I avoid calling os.getenv throughout my Python code?

Scattered os.getenv calls return untyped strings or None, fail late with cryptic errors, and make required configuration invisible. A central typed settings module validates everything at startup, provides defaults for local development, and documents all required variables in one place.