python-configuration

Manage Python application configuration with environment variables and typed pydantic-settings.

Updated Apr 13, 2026
One-click install
npx skills add https://github.com/scoots31/engineering-playbook --skill python-configuration-scoots31
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-configuration
Source: https://github.com/scoots31/engineering-playbook/tree/main/references/python-configuration
Command: npx skills add https://github.com/scoots31/engineering-playbook --skill python-configuration-scoots31

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 impossible to run across environments. This Skill provides patterns for externalizing configuration into environment variables with typed, validated settings objects. ## Core Features & Use Cases - Typed Settings with Pydantic: Define a central BaseSettings class that loads, parses, and validates all environment variables at startup. - Fail-Fast Validation: Crash immediately with clear error messages when required configuration is missing, instead of failing mid-request. - Advanced Patterns: Nested configuration groups, environment-specific behavior, secrets from mounted files, type coercion, and custom validators. - Use Case: You are deploying a FastAPI service to staging and production. Use this Skill to define a Settings class that reads DATABASE__HOST, API_SECRET_KEY, and ENVIRONMENT variables, validates them at boot, and switches logging behavior per environment. ## Quick Start Set up a pydantic-settings configuration class 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 class inheriting from BaseSettings with typed fields and Field aliases matching your environment variable names. Instantiate it once at startup; pydantic-settings loads values from the environment and an optional .env file automatically.

How to validate required configuration at Python app startup?

Declare required fields without defaults in your BaseSettings class and wrap instantiation in a try/except ValidationError block. On failure, print each missing field from e.errors() and exit with sys.exit(1) so the app fails fast with a clear message.

Does pydantic-settings support nested configuration groups?

Yes, nest BaseModel classes inside your BaseSettings class and set env_nested_delimiter to a double underscore in model_config. Variables like DATABASE__HOST then map to the nested database.host field.

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. When an environment variable is not set, pydantic-settings looks for a file with the field name in that directory and reads its contents.

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

Scattered os.getenv calls skip validation, return untyped strings or None, and fail late with cryptic errors. A central typed settings singleton validates everything at boot and gives the rest of the code a single importable source of truth.